diff --git a/src/fake.rs b/src/fake.rs index 203fdb3423a..c0b432ac56a 100644 --- a/src/fake.rs +++ b/src/fake.rs @@ -6,6 +6,7 @@ use std::hash::{BuildHasher, Hash}; use std::collections::HashMap as StdMap; +use std::collections::HashSet as StdSet; use std::ops::{Deref, DerefMut}; pub use std::collections::hash_map::{Entry, RandomState}; @@ -81,3 +82,65 @@ impl HashMap Ok(self.insert(k, v)) } } + +pub struct HashSet(StdSet); + + +impl Deref for HashSet { + type Target = StdSet; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for HashSet { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl HashSet { + + #[inline] + pub fn new() -> HashSet { + HashSet(StdSet::new()) + } + + #[inline] + pub fn with_capacity(capacity: usize) -> HashSet { + HashSet(StdSet::with_capacity(capacity)) + } +} + + +impl HashSet + where T: Eq + Hash, + S: BuildHasher +{ + + #[inline] + pub fn with_hasher(hasher: S) -> HashSet { + HashSet(StdSet::with_hasher(hasher)) + } + + + #[inline] + pub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> HashSet { + HashSet(StdSet::with_capacity_and_hasher(capacity, hasher)) + } + + #[inline] + pub fn reserve_fallible(&mut self, additional: usize) -> Result<(), ()> { + Ok(self.reserve(additional)) + } + + #[inline] + pub fn shrink_to_fit_fallible(&mut self) -> Result<(), ()> { + Ok(self.shrink_to_fit()) + } + + #[inline] + pub fn insert_fallible(&mut self, value: T) -> Result { + Ok(self.insert(value)) + } +}