diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-10-09 09:55:00 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-04-04 13:23:07 -0700 |
| commit | 8057faa2d320db0abdfb385ad1827f8902931cef (patch) | |
| tree | f17a3fb3384bf7de95a8b9d1fd5598c8f165a64e | |
| parent | 7c48e53c1e8c1427cbb2e827a9d43bfa36847d65 (diff) | |
| download | rust-8057faa2d320db0abdfb385ad1827f8902931cef.tar.gz rust-8057faa2d320db0abdfb385ad1827f8902931cef.zip | |
std: TrieSet should implement container::{,Mutable}Set
| -rw-r--r-- | src/libcollections/trie.rs | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/src/libcollections/trie.rs b/src/libcollections/trie.rs index 740a3637700..8b83e658386 100644 --- a/src/libcollections/trie.rs +++ b/src/libcollections/trie.rs @@ -293,32 +293,46 @@ impl Mutable for TrieSet { fn clear(&mut self) { self.map.clear() } } -impl TrieSet { - /// Create an empty TrieSet +impl Set<uint> for TrieSet { #[inline] - pub fn new() -> TrieSet { - TrieSet{map: TrieMap::new()} + fn contains(&self, value: &uint) -> bool { + self.map.contains_key(value) } - /// Return true if the set contains a value #[inline] - pub fn contains(&self, value: &uint) -> bool { - self.map.contains_key(value) + fn is_disjoint(&self, other: &TrieSet) -> bool { + self.iter().all(|v| !other.contains(&v)) } - /// Add a value to the set. Return true if the value was not already - /// present in the set. #[inline] - pub fn insert(&mut self, value: uint) -> bool { + fn is_subset(&self, other: &TrieSet) -> bool { + self.iter().all(|v| other.contains(&v)) + } + + #[inline] + fn is_superset(&self, other: &TrieSet) -> bool { + other.is_subset(self) + } +} + +impl MutableSet<uint> for TrieSet { + #[inline] + fn insert(&mut self, value: uint) -> bool { self.map.insert(value, ()) } - /// Remove a value from the set. Return true if the value was - /// present in the set. #[inline] - pub fn remove(&mut self, value: &uint) -> bool { + fn remove(&mut self, value: &uint) -> bool { self.map.remove(value) } +} + +impl TrieSet { + /// Create an empty TrieSet + #[inline] + pub fn new() -> TrieSet { + TrieSet{map: TrieMap::new()} + } /// Visit all values in reverse order #[inline] |
