diff --git a/src/collections/sets.rs b/src/collections/sets.rs new file mode 100644 index 0000000000000000000000000000000000000000..b4510b48778b1812e4e26b6e2caa0dc87885904f --- /dev/null +++ b/src/collections/sets.rs @@ -0,0 +1,50 @@ +use std::collections::VecDeque; + +/// Simple double ended queue that ensures that all elements are unique. Queue +/// is not ordered. +pub struct DequeSet { + inner: VecDeque, +} + +impl DequeSet { + pub fn new() -> Self { + Self{ inner: VecDeque::new() } + } + + #[inline] + pub fn pop_front(&mut self) -> Option { + self.inner.pop_front() + } + + #[inline] + pub fn pop_back(&mut self) -> Option { + self.inner.pop_back() + } + + #[inline] + pub fn push_back(&mut self, to_push: T) { + for element in self.inner.iter() { + if *element == to_push { + return; + } + } + + self.inner.push_back(to_push); + } + + #[inline] + pub fn push_front(&mut self, to_push: T) { + for element in self.inner.iter() { + if *element == to_push { + return; + } + } + + self.inner.push_front(to_push); + } + + #[inline] + pub fn is_empty(&self) -> bool { + self.inner.is_empty() + } +} \ No newline at end of file