Loading Common/Libraries/IRALibrary/include/FastQueue.h +12 −5 Original line number Diff line number Diff line Loading @@ -54,11 +54,11 @@ public: } /** * puts an element in the head of the queue. * puts an element in the tail of the queue. * @param element new element to be added * @return false if the container is full and no other elements could be added */ bool pushFront(const T& element) { bool pushBack(const T& element) { if (isFull()) return false; m_array[m_head] = element; m_head = (m_head+ 1)%m_positions; // if full an element is overwritten Loading @@ -66,20 +66,27 @@ public: } /** * pop back an element from the tail of the queue * pop an element from the front of the queue * @element the next element is the queue * @return false if the queue is empty and the element could not be pop */ bool popBack(T& element) { bool popFront(T& element) { if (isEmpty()) return false; element=m_array[m_end]; m_end=(m_end+1)%m_positions; // if it is not empty return true; } /** * @return the reference to the element that is going to come out of the queue */ const T& front() const { return m_array[m_end]; } protected: unsigned m_positions; /** beggining of the array */ /** beginning of the array */ unsigned m_head; /** end of the array */ unsigned m_end; Loading Common/Libraries/IRALibrary/tests/FastQueue_test.i +6 −6 Original line number Diff line number Diff line Loading @@ -12,14 +12,14 @@ public: IRA::CFastQueue<unsigned> queue(FASTQUEUE_SIZE); if (!queue.isEmpty()) ::testing::AssertionFailure() << " the container should be empty"; for (unsigned i=0;i<FASTQUEUE_SIZE;i++) { if (!queue.pushFront(i)) { if (!queue.pushBack(i)) { return ::testing::AssertionFailure() << " element " << i << " cannot be inserted"; } if (queue.size()!=i+1) { return ::testing::AssertionFailure() << " the size of the container is not expected"; } } if (queue.pushFront(1)) return ::testing::AssertionFailure() << " insertion should have failed because of container limits"; if (queue.pushBack(1)) return ::testing::AssertionFailure() << " insertion should have failed because of container limits"; if (!queue.isFull()) return ::testing::AssertionFailure() << " ithe container should be full"; return ::testing::AssertionSuccess(); } Loading @@ -30,12 +30,12 @@ public: unsigned elem; // assign some elements for (unsigned i=0;i<1000;i++) { if (!queue.pushFront(i)) { if (!queue.pushBack(i)) { return ::testing::AssertionFailure() << " element " << i << " cannot be inserted"; } } for (unsigned i=0;i<500;i++) { if (!queue.popBack(elem)) { if (!queue.popFront(elem)) { return ::testing::AssertionFailure() << " element " << i << " cannot be extracted"; } if (elem!=i) { Loading @@ -43,12 +43,12 @@ public: } } for (unsigned i=1000;i<2000;i++) { if (!queue.pushFront(i)) { if (!queue.pushBack(i)) { return ::testing::AssertionFailure() << " element " << i << " cannot be inserted"; } } for (unsigned i=500;i<2000;i++) { if (!queue.popBack(elem)) { if (!queue.popFront(elem)) { return ::testing::AssertionFailure() << " element " << i << " cannot be extracted"; } if (elem!=i) { Loading Loading
Common/Libraries/IRALibrary/include/FastQueue.h +12 −5 Original line number Diff line number Diff line Loading @@ -54,11 +54,11 @@ public: } /** * puts an element in the head of the queue. * puts an element in the tail of the queue. * @param element new element to be added * @return false if the container is full and no other elements could be added */ bool pushFront(const T& element) { bool pushBack(const T& element) { if (isFull()) return false; m_array[m_head] = element; m_head = (m_head+ 1)%m_positions; // if full an element is overwritten Loading @@ -66,20 +66,27 @@ public: } /** * pop back an element from the tail of the queue * pop an element from the front of the queue * @element the next element is the queue * @return false if the queue is empty and the element could not be pop */ bool popBack(T& element) { bool popFront(T& element) { if (isEmpty()) return false; element=m_array[m_end]; m_end=(m_end+1)%m_positions; // if it is not empty return true; } /** * @return the reference to the element that is going to come out of the queue */ const T& front() const { return m_array[m_end]; } protected: unsigned m_positions; /** beggining of the array */ /** beginning of the array */ unsigned m_head; /** end of the array */ unsigned m_end; Loading
Common/Libraries/IRALibrary/tests/FastQueue_test.i +6 −6 Original line number Diff line number Diff line Loading @@ -12,14 +12,14 @@ public: IRA::CFastQueue<unsigned> queue(FASTQUEUE_SIZE); if (!queue.isEmpty()) ::testing::AssertionFailure() << " the container should be empty"; for (unsigned i=0;i<FASTQUEUE_SIZE;i++) { if (!queue.pushFront(i)) { if (!queue.pushBack(i)) { return ::testing::AssertionFailure() << " element " << i << " cannot be inserted"; } if (queue.size()!=i+1) { return ::testing::AssertionFailure() << " the size of the container is not expected"; } } if (queue.pushFront(1)) return ::testing::AssertionFailure() << " insertion should have failed because of container limits"; if (queue.pushBack(1)) return ::testing::AssertionFailure() << " insertion should have failed because of container limits"; if (!queue.isFull()) return ::testing::AssertionFailure() << " ithe container should be full"; return ::testing::AssertionSuccess(); } Loading @@ -30,12 +30,12 @@ public: unsigned elem; // assign some elements for (unsigned i=0;i<1000;i++) { if (!queue.pushFront(i)) { if (!queue.pushBack(i)) { return ::testing::AssertionFailure() << " element " << i << " cannot be inserted"; } } for (unsigned i=0;i<500;i++) { if (!queue.popBack(elem)) { if (!queue.popFront(elem)) { return ::testing::AssertionFailure() << " element " << i << " cannot be extracted"; } if (elem!=i) { Loading @@ -43,12 +43,12 @@ public: } } for (unsigned i=1000;i<2000;i++) { if (!queue.pushFront(i)) { if (!queue.pushBack(i)) { return ::testing::AssertionFailure() << " element " << i << " cannot be inserted"; } } for (unsigned i=500;i<2000;i++) { if (!queue.popBack(elem)) { if (!queue.popFront(elem)) { return ::testing::AssertionFailure() << " element " << i << " cannot be extracted"; } if (elem!=i) { Loading