summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-04-29 11:39:28 -0700
committerGitHub <noreply@github.com>2021-04-29 11:39:28 -0700
commita4c7866f5e133c58ebbf09715a705d514209dac1 (patch)
tree7ca2ead470ee9ac15b02ecc7589700052443bb8a /src
parent2785d936639c62d08eb836a775838a37033127b4 (diff)
downloadbinaryen-a4c7866f5e133c58ebbf09715a705d514209dac1.tar.gz
binaryen-a4c7866f5e133c58ebbf09715a705d514209dac1.tar.bz2
binaryen-a4c7866f5e133c58ebbf09715a705d514209dac1.zip
UniqueDeferredQueue improvements (#3847)
Add clear(). Add UniqueNonrepeatingDeferredQueue which also has the property that it never repeats values in the output. Also add unit tests.
Diffstat (limited to 'src')
-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