Skip to content

Commit 8057faa

Browse files
ericktalexcrichton
authored andcommitted
std: TrieSet should implement container::{,Mutable}Set
1 parent 7c48e53 commit 8057faa

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

src/libcollections/trie.rs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -293,32 +293,46 @@ impl Mutable for TrieSet {
293293
fn clear(&mut self) { self.map.clear() }
294294
}
295295

296-
impl TrieSet {
297-
/// Create an empty TrieSet
296+
impl Set<uint> for TrieSet {
298297
#[inline]
299-
pub fn new() -> TrieSet {
300-
TrieSet{map: TrieMap::new()}
298+
fn contains(&self, value: &uint) -> bool {
299+
self.map.contains_key(value)
301300
}
302301

303-
/// Return true if the set contains a value
304302
#[inline]
305-
pub fn contains(&self, value: &uint) -> bool {
306-
self.map.contains_key(value)
303+
fn is_disjoint(&self, other: &TrieSet) -> bool {
304+
self.iter().all(|v| !other.contains(&v))
307305
}
308306

309-
/// Add a value to the set. Return true if the value was not already
310-
/// present in the set.
311307
#[inline]
312-
pub fn insert(&mut self, value: uint) -> bool {
308+
fn is_subset(&self, other: &TrieSet) -> bool {
309+
self.iter().all(|v| other.contains(&v))
310+
}
311+
312+
#[inline]
313+
fn is_superset(&self, other: &TrieSet) -> bool {
314+
other.is_subset(self)
315+
}
316+
}
317+
318+
impl MutableSet<uint> for TrieSet {
319+
#[inline]
320+
fn insert(&mut self, value: uint) -> bool {
313321
self.map.insert(value, ())
314322
}
315323

316-
/// Remove a value from the set. Return true if the value was
317-
/// present in the set.
318324
#[inline]
319-
pub fn remove(&mut self, value: &uint) -> bool {
325+
fn remove(&mut self, value: &uint) -> bool {
320326
self.map.remove(value)
321327
}
328+
}
329+
330+
impl TrieSet {
331+
/// Create an empty TrieSet
332+
#[inline]
333+
pub fn new() -> TrieSet {
334+
TrieSet{map: TrieMap::new()}
335+
}
322336

323337
/// Visit all values in reverse order
324338
#[inline]

0 commit comments

Comments
 (0)