mirror of https://github.com/rust-lang/rust.git
implement container::Mutable for SmallIntMap
This commit is contained in:
parent
aac91267e3
commit
9ba7114515
|
@ -95,6 +95,10 @@ impl<V> SmallIntMap<V>: Container {
|
|||
pure fn is_empty(&self) -> bool { self.len() == 0 }
|
||||
}
|
||||
|
||||
impl<V> SmallIntMap<V>: Mutable {
|
||||
fn clear(&mut self) { self.v.set(~[]) }
|
||||
}
|
||||
|
||||
/// Implements the map::map interface for smallintmap
|
||||
impl<V: Copy> SmallIntMap<V> {
|
||||
#[inline(always)]
|
||||
|
@ -111,9 +115,6 @@ impl<V: Copy> SmallIntMap<V> {
|
|||
self.v.set_elt(key, None);
|
||||
old.is_some()
|
||||
}
|
||||
fn clear() {
|
||||
self.v.set(~[]);
|
||||
}
|
||||
pure fn contains_key(key: uint) -> bool {
|
||||
contains_key(self, key)
|
||||
}
|
||||
|
@ -191,6 +192,19 @@ mod tests {
|
|||
assert !map.is_empty();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_clear() {
|
||||
let mut map = mk();
|
||||
map.insert(5, 20);
|
||||
map.insert(11, 12);
|
||||
map.insert(14, 22);
|
||||
map.clear();
|
||||
assert map.is_empty();
|
||||
assert map.find(5).is_none();
|
||||
assert map.find(11).is_none();
|
||||
assert map.find(14).is_none();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_insert_with_key() {
|
||||
let map: SmallIntMap<uint> = mk();
|
||||
|
|
Loading…
Reference in New Issue