diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2013-01-31 17:28:37 -0500 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2013-01-31 23:13:56 -0500 |
| commit | 9ba7114515db355ca36065d2730e3ee6c84cd6d1 (patch) | |
| tree | bd2791fd1b815b2fa7aee1b3f2fc4de5fa7606df | |
| parent | aac91267e3ea650649ee443b042fe04cd502da6c (diff) | |
| download | rust-9ba7114515db355ca36065d2730e3ee6c84cd6d1.tar.gz rust-9ba7114515db355ca36065d2730e3ee6c84cd6d1.zip | |
implement container::Mutable for SmallIntMap
| -rw-r--r-- | src/libstd/smallintmap.rs | 20 |
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(); |
