Skip to content

Commit 9ba7114

Browse files
committed
implement container::Mutable for SmallIntMap
1 parent aac9126 commit 9ba7114

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/libstd/smallintmap.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ impl<V> SmallIntMap<V>: Container {
9595
pure fn is_empty(&self) -> bool { self.len() == 0 }
9696
}
9797

98+
impl<V> SmallIntMap<V>: Mutable {
99+
fn clear(&mut self) { self.v.set(~[]) }
100+
}
101+
98102
/// Implements the map::map interface for smallintmap
99103
impl<V: Copy> SmallIntMap<V> {
100104
#[inline(always)]
@@ -111,9 +115,6 @@ impl<V: Copy> SmallIntMap<V> {
111115
self.v.set_elt(key, None);
112116
old.is_some()
113117
}
114-
fn clear() {
115-
self.v.set(~[]);
116-
}
117118
pure fn contains_key(key: uint) -> bool {
118119
contains_key(self, key)
119120
}
@@ -191,6 +192,19 @@ mod tests {
191192
assert !map.is_empty();
192193
}
193194

195+
#[test]
196+
fn test_clear() {
197+
let mut map = mk();
198+
map.insert(5, 20);
199+
map.insert(11, 12);
200+
map.insert(14, 22);
201+
map.clear();
202+
assert map.is_empty();
203+
assert map.find(5).is_none();
204+
assert map.find(11).is_none();
205+
assert map.find(14).is_none();
206+
}
207+
194208
#[test]
195209
fn test_insert_with_key() {
196210
let map: SmallIntMap<uint> = mk();

0 commit comments

Comments
 (0)