SyntaxTutor
Educational app designed to help compiler students understand LL(1) and SLR(1) parsing algorithms.
 
Loading...
Searching...
No Matches
UniqueQueue.h
Go to the documentation of this file.
1#ifndef UNIQUEQUEUE_H
2#define UNIQUEQUEUE_H
3#include <queue>
4#include <unordered_set>
5
16template<typename T>
18public:
23 void push(const T& value) {
24 if (seen_.insert(value).second) {
25 queue_.push(value);
26 }
27 }
28
32 void pop() {
33 if (!queue_.empty()) {
34 queue_.pop();
35 }
36 }
37
42 const T& front() const {
43 return queue_.front();
44 }
45
50 bool empty() const {
51 return queue_.empty();
52 }
53
57 void clear() {
58 while(!queue_.empty()) queue_.pop();
59 seen_.clear();
60 }
61
62private:
63 std::queue<T> queue_;
64 std::unordered_set<T> seen_;
65};
66#endif // UNIQUEQUEUE_H
A queue that ensures each element is inserted only once.
Definition UniqueQueue.h:17
void clear()
Clears the queue and the set of seen elements.
Definition UniqueQueue.h:57
const T & front() const
Accesses the front element of the queue.
Definition UniqueQueue.h:42
void pop()
Removes the front element from the queue.
Definition UniqueQueue.h:32
void push(const T &value)
Pushes an element to the queue if it hasn't been inserted before.
Definition UniqueQueue.h:23
bool empty() const
Checks whether the queue is empty.
Definition UniqueQueue.h:50