diff --git a/src/collections/sets.rs b/src/collections/sets.rs index 669a5b65f1f60091ca9a0c97b767e559b49bb584..96f7df9fbdfeb228cc51882a6cc6d2dcf58604ce 100644 --- a/src/collections/sets.rs +++ b/src/collections/sets.rs @@ -1,8 +1,7 @@ use std::collections::VecDeque; /// Simple double ended queue that ensures that all elements are unique. Queue -/// elements are not ordered (use case is that the queue should be rather -/// small). +/// elements are not ordered (we expect the queue to be rather small). pub struct DequeSet { inner: VecDeque, } @@ -49,6 +48,44 @@ impl DequeSet { self.inner.clear(); } + #[inline] + pub fn is_empty(&self) -> bool { + self.inner.is_empty() + } +} + +/// Simple vector set that ensures that all elements are unique. Elements are +/// not ordered (we expect the vector to be small). +pub struct VecSet { + inner: Vec, +} + +impl VecSet { + pub fn new() -> Self { + Self{ inner: Vec::new() } + } + + #[inline] + pub fn pop(&mut self) -> Option { + self.inner.pop() + } + + #[inline] + pub fn push(&mut self, to_push: T) { + for element in self.inner.iter() { + if *element == to_push { + return; + } + } + + self.inner.push(to_push); + } + + #[inline] + pub fn clear(&mut self) { + self.inner.clear(); + } + #[inline] pub fn is_empty(&self) -> bool { self.inner.is_empty()