about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2013-01-31 17:28:37 -0500
committerDaniel Micay <danielmicay@gmail.com>2013-01-31 23:13:56 -0500
commit9ba7114515db355ca36065d2730e3ee6c84cd6d1 (patch)
treebd2791fd1b815b2fa7aee1b3f2fc4de5fa7606df
parentaac91267e3ea650649ee443b042fe04cd502da6c (diff)
downloadrust-9ba7114515db355ca36065d2730e3ee6c84cd6d1.tar.gz
rust-9ba7114515db355ca36065d2730e3ee6c84cd6d1.zip
implement container::Mutable for SmallIntMap
-rw-r--r--src/libstd/smallintmap.rs20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs
index 381aa3b7963..59ae9f68d6e 100644
--- a/src/libstd/smallintmap.rs
+++ b/src/libstd/smallintmap.rs
@@ -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)
     }
@@ -192,6 +193,19 @@ mod tests {
     }
 
     #[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();