summaryrefslogtreecommitdiff
path: root/src/support/unique_deferring_queue.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/support/unique_deferring_queue.h')
-rw-r--r--src/support/unique_deferring_queue.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/support/unique_deferring_queue.h b/src/support/unique_deferring_queue.h
index ad8f3967d..ba59ffd8f 100644
--- a/src/support/unique_deferring_queue.h
+++ b/src/support/unique_deferring_queue.h
@@ -25,6 +25,7 @@
#include <queue>
#include <unordered_map>
+#include <unordered_set>
namespace wasm {
@@ -57,6 +58,31 @@ template<typename T> struct UniqueDeferredQueue {
// skip this one, keep going
}
}
+
+ void clear() {
+ std::queue<T> empty;
+ std::swap(data, empty);
+ count.clear();
+ }
+};
+
+// As UniqueDeferredQueue, but once an item has been processed through the queue
+// (that is, popped) it will be ignored from then on in later pushes.
+template<typename T>
+struct UniqueNonrepeatingDeferredQueue : UniqueDeferredQueue<T> {
+ std::unordered_set<T> processed;
+
+ void push(T item) {
+ if (!processed.count(item)) {
+ UniqueDeferredQueue<T>::push(item);
+ }
+ }
+
+ T pop() {
+ T ret = UniqueDeferredQueue<T>::pop();
+ processed.insert(ret);
+ return ret;
+ }
};
} // namespace wasm