예제 #1
0
 void update(int64_t packet_raw, int packet_size, const Int64TimeField &packet_at,
             const string &filename) {
     LintelLogDebug("IPRolling::packet", format("UPD %d %d") % packet_raw % packet_size);
     if (!packets_in_flight.empty()) {
         int64_t cur_back_ts_raw = packets_in_flight.back().timestamp_raw;
         INVARIANT(packet_raw >= cur_back_ts_raw,
                   format("out of order by %.4fs in %s; %d < %d") 
                   % packet_at.rawToDoubleSeconds(cur_back_ts_raw - packet_raw) % filename
                   % packet_raw % cur_back_ts_raw);
     }
     while ((packet_raw - cur_time_raw) > interval_width_raw) {
         // update statistics for the interval from cur_time to cur_time + interval_width
         // all packets in p_i_f must have been received in that interval
         double bw = cur_bytes_in_queue * MiB_per_second_convert;
         MiB_per_second.add(bw);
         double pps = packets_in_flight.size() * kpackets_per_second_convert;
         kpackets_per_second.add(pps);
         LintelLogDebug("IPRolling::detail", format("[%d..%d[: %.0f, %d -> %.6g %.6g")
                        % cur_time_raw % (cur_time_raw + update_step_raw)
                        % cur_bytes_in_queue % packets_in_flight.size() % bw % pps);
         cur_time_raw += update_step_raw;
         while (! packets_in_flight.empty() &&
               packets_in_flight.front().timestamp_raw < cur_time_raw) {
             cur_bytes_in_queue -= packets_in_flight.front().packetsize;
             packets_in_flight.pop_front();
         }
     }
     packets_in_flight.push_back(packetTimeSize(packet_raw, packet_size));
     cur_bytes_in_queue += packet_size;
 }
int main()
{
    Deque <string> D;

    D.insertFront("Alice");
    D.insertRear("Bob");

    cout << D.front() << endl;
    cout << D.rear() << endl;

    cout << D.size() << endl;

    D.insertRear("Charlie");

    cout << D.front() << endl;
    cout << D.rear() << endl;

    D.removeFront();

    cout << D.front() << endl;
    cout << D.rear() << endl;

    cout << D.size() << endl;

    D.removeFront();

    cout << D.size() << endl;
}
예제 #3
0
파일: deque.cpp 프로젝트: ziqifan16/Lintel
void testNoDefaultConstructor() {
    Deque<NoDefaultConstructor> deque;

    deque.reserve(8);

    for(int i = 0; i < 5; ++i) {
        deque.push_back(NoDefaultConstructor(i));
        SINVARIANT(deque.back().v == i);
        SINVARIANT(deque.size() == static_cast<size_t>(i + 1));
        INVARIANT(NoDefaultConstructor::ndc_count == i + 1, format("%d != %d + 1")
                  % NoDefaultConstructor::ndc_count % i);
    }

    for(int i = 0; i < 5; ++i) {
        SINVARIANT(deque.front().v == i);
        deque.pop_front();
        deque.push_back(NoDefaultConstructor(i));
        SINVARIANT(deque.back().v == i);
        SINVARIANT(deque.size() == 5);
        SINVARIANT(NoDefaultConstructor::ndc_count == 5);
    }

    for(int i = 0; i < 5; ++i) {
        SINVARIANT(deque.front().v == i);
        deque.pop_front();
        SINVARIANT(deque.size() == static_cast<size_t>(4 - i));
        SINVARIANT(NoDefaultConstructor::ndc_count == 4 - i);
    }
    SINVARIANT(NoDefaultConstructor::ndc_count == 0);
}
예제 #4
0
파일: deque.cpp 프로젝트: ziqifan16/Lintel
void testPushBack() {
    Deque<int> deque;

    SINVARIANT(deque.empty());
    deque.reserve(8);
    SINVARIANT(deque.empty() && deque.capacity() == 8);
    for(int i = 0; i < 5; ++i) {
        deque.push_back(i);
        SINVARIANT(deque.back() == i);
        SINVARIANT(deque.size() == static_cast<size_t>(i + 1));
    }

    for(int i = 0; i < 5; ++i) {
        SINVARIANT(deque.at(i) == i);
    }

    for(int i = 0; i < 5; ++i) {
        SINVARIANT(deque.front() == i);
        deque.pop_front();
        deque.push_back(i);
        SINVARIANT(deque.back() == i);
        SINVARIANT(deque.size() == 5);
    }

    for(int i = 0; i < 5; ++i) {
        SINVARIANT(deque.at(i) == i);
    }

    {
        Deque<int>::iterator i = deque.begin();
        int j = 0;
        while(i != deque.end()) {
            INVARIANT(*i == j, format("%d != %d") % *i % j);
            ++i;
            ++j;
        }
    }

    vector<int> avec;
    for(int i = 5; i < 10; ++i) {
        avec.push_back(i);
    }
    deque.push_back(avec);

    for(int i = 0; i < 10; ++i) {
        SINVARIANT(deque.front() == i);
        deque.pop_front();
    }
    SINVARIANT(deque.empty());
}
예제 #5
0
파일: Ch8_Ex23.cpp 프로젝트: EDA-TADs/EDA
//--------------------Linear solution----------------------
void minimumValues(int v[], int k) {
	Deque<int> d = Deque<int>(); // In the queue I store positions, no elements

	for (int i = 0; i < N; i++)
	{
		if (i >= k) // Until we have not consider a subarray, we can not print the minimums.
			cout << v[d.front()] << " ";

		while (!d.empty() && v[d.back()] >= v[i]) { // While the queue is not empty and the element I want to insert is
												   // greater or equal than the last one I extract the last element
			d.pop_back();
		}
		d.push_back(i); // I insert the new element

		if (d.front() <= i - k) //This remove the minimum once is out of the subarray
			d.pop_front();
	}
	cout << v[d.front()] << endl;
}
예제 #6
0
void HyperDijkstra::visitAdjacencyMap(AdjacencyMap& amap, TreeAction* action, bool useDistance)
{

    typedef std::deque<HyperGraph::Vertex*> Deque;
    Deque q;
    // scans for the vertices without the parent (whcih are the roots of the trees) and applies the action to them.
    for (AdjacencyMap::iterator it=amap.begin(); it!=amap.end(); ++it) {
        AdjacencyMapEntry& entry(it->second);
        if (! entry.parent()) {
            action->perform(it->first,0,0);
            q.push_back(it->first);
        }
    }

    //std::cerr << "q.size()" << q.size() << endl;
    int count=0;
    while (! q.empty()) {
        HyperGraph::Vertex* parent=q.front();
        q.pop_front();
        ++count;
        AdjacencyMap::iterator parentIt=amap.find(parent);
        if (parentIt==amap.end()) {
            continue;
        }
        //cerr << "parent= " << parent << " parent id= " << parent->id() << "\t children id =";
        HyperGraph::VertexSet& childs(parentIt->second.children());
        for (HyperGraph::VertexSet::iterator childsIt=childs.begin(); childsIt!=childs.end(); ++childsIt) {
            HyperGraph::Vertex* child=*childsIt;
            //cerr << child->id();
            AdjacencyMap::iterator adjacencyIt=amap.find(child);
            assert (adjacencyIt!=amap.end());
            HyperGraph::Edge* edge=adjacencyIt->second.edge();

            assert(adjacencyIt->first==child);
            assert(adjacencyIt->second.child()==child);
            assert(adjacencyIt->second.parent()==parent);
            if (! useDistance) {
                action->perform(child, parent, edge);
            } else {
                action->perform(child, parent, edge, adjacencyIt->second.distance());
            }
            q.push_back(child);
        }
        //cerr << endl;
    }

}
예제 #7
0
파일: Deque.cpp 프로젝트: dataseries/Lintel
void
DequeTest()
{
    Deque<int> testq;

    Deque<int> testBad(256);
    for(int i=0;i<512;i++) {
	testBad.push_back(i);
    }
    for(int i=0;i<512;i++) {
	INVARIANT(testBad.empty() == false && testBad.front() == i,
		  "simple test failed?!");
	testBad.pop_front();
    }

    // test empty->size1->empty
    for(int size1=1;size1<2000;size1++) {
	INVARIANT(testq.empty()==true,"internal");
	for(int j=0;j<size1;j++) {
	    testq.push_back(j);
	    INVARIANT(testq.empty()==false,"internal");
	}
	for(int j=0;j<size1;j++) {
	    INVARIANT(testq.empty()==false,"internal");
	    INVARIANT(testq.front() == j,
		      boost::format("Internal Error: %d/%d")
		      % size1 % j);
	    testq.pop_front();
	}
	INVARIANT(testq.empty()==true,"internal");
    }
    printf("pass empty->full->empty tests\n");
    // test empty->size1, size2 add/remove, ->empty
    for(int size1=1;size1<150;size1++) {
	for(int size2=1;size2<400;size2++) {
	    INVARIANT(testq.empty()==true,"internal");
	    for(int j=0;j<size1;j++) {
		testq.push_back(j);
		INVARIANT(testq.empty()==false,"internal");
	    }
	    for(int j=0;j<size2;j++) {
		INVARIANT(testq.empty()==false,"internal");
		INVARIANT(testq.front() == j,
			  boost::format("Internal Error: %d/%d/%d")
			  % size1 % size2 %j);
		testq.pop_front();
		testq.push_back((j+size1));
	    }
	    for(int j=size2;j<size1+size2;j++) {
		INVARIANT(testq.empty()==false,"internal");
		int t = testq.front();
		testq.pop_front();
		INVARIANT(t == j,
			  boost::format("Internal Error: %d/%d/%d/%d")
			  % t % size1 % size2 % j);
	    }
	    INVARIANT(testq.empty()==true,"internal");
	}
    }
    printf("pass partial fill tests\n");
}