]> git.lizzy.rs Git - rust.git/commitdiff
Added default impls for container methods
authorSteven Fackler <sfackler@gmail.com>
Thu, 25 Jul 2013 08:02:08 +0000 (04:02 -0400)
committerSteven Fackler <sfackler@gmail.com>
Thu, 25 Jul 2013 22:17:30 +0000 (15:17 -0700)
A couple of implementations of Container::is_empty weren't exactly
self.len() == 0 so I left them alone (e.g. Treemap).

src/libextra/bitv.rs
src/libextra/priority_queue.rs
src/libextra/ringbuf.rs
src/libextra/smallintmap.rs
src/libextra/treemap.rs
src/libstd/container.rs
src/libstd/hashmap.rs
src/libstd/str.rs
src/libstd/trie.rs

index 168d6a3991674e91a14849d75875ae6a61db0520..6e52802578c203a2fa2b7205239eb56fa5d30381 100644 (file)
@@ -703,8 +703,8 @@ fn ne(&self, other: &BitvSet) -> bool { !self.eq(other) }
 }
 
 impl Container for BitvSet {
+    #[inline]
     fn len(&self) -> uint { self.size }
-    fn is_empty(&self) -> bool { self.size == 0 }
 }
 
 impl Mutable for BitvSet {
index d07b645a541d22e9c9f229aa5eeb14a915bde6c5..dd24a2a9eb96ebe07cdd573f9a6476ee5bd7905b 100644 (file)
@@ -27,9 +27,6 @@ pub struct PriorityQueue<T> {
 impl<T:Ord> Container for PriorityQueue<T> {
     /// Returns the length of the queue
     fn len(&self) -> uint { self.data.len() }
-
-    /// Returns true if a queue contains no elements
-    fn is_empty(&self) -> bool { self.len() == 0 }
 }
 
 impl<T:Ord> Mutable for PriorityQueue<T> {
index f46af664b189f630508677050fababf46915a9d5..aa670ec5ff8d92ae262a891aab85a72e106b9938 100644 (file)
@@ -34,9 +34,6 @@ pub struct RingBuf<T> {
 impl<T> Container for RingBuf<T> {
     /// Return the number of elements in the RingBuf
     fn len(&self) -> uint { self.nelts }
-
-    /// Return true if the RingBufcontains no elements
-    fn is_empty(&self) -> bool { self.len() == 0 }
 }
 
 impl<T> Mutable for RingBuf<T> {
index bd78f41ddf51337ce1cb07cb187716e5ec7915ad..bf6f80534b4f3a91fa35ff001123b01447678d01 100644 (file)
@@ -37,9 +37,6 @@ fn len(&self) -> uint {
         }
         sz
     }
-
-    /// Return true if the map contains no elements
-    fn is_empty(&self) -> bool { self.len() == 0 }
 }
 
 impl<V> Mutable for SmallIntMap<V> {
index 303ae6a6d1de147552c936844354f3ac8039e4c9..8c7ace56412462640bd4a700a26897feef8846c4 100644 (file)
@@ -135,19 +135,6 @@ fn find_mut<'a>(&'a mut self, key: &K) -> Option<&'a mut V> {
         find_mut(&mut self.root, key)
     }
 
-    /// Insert a key-value pair into the map. An existing value for a
-    /// key is replaced by the new value. Return true if the key did
-    /// not already exist in the map.
-    fn insert(&mut self, key: K, value: V) -> bool {
-        self.swap(key, value).is_none()
-    }
-
-    /// Remove a key-value pair from the map. Return true if the key
-    /// was present in the map, otherwise false.
-    fn remove(&mut self, key: &K) -> bool {
-        self.pop(key).is_some()
-    }
-
     /// Insert a key-value pair from the map. If the key already had a value
     /// present in the map, that value is returned. Otherwise None is returned.
     fn swap(&mut self, key: K, value: V) -> Option<V> {
index 4bad28ca3383081bf04f3f140168074268a138f6..d855beea50b2ec9e02ab9aa22784f508244688cc 100644 (file)
@@ -19,7 +19,10 @@ pub trait Container {
     fn len(&self) -> uint;
 
     /// Return true if the container contains no elements
-    fn is_empty(&self) -> bool;
+    #[inline]
+    fn is_empty(&self) -> bool {
+        self.len() == 0
+    }
 }
 
 /// A trait to represent mutable containers
@@ -43,11 +46,17 @@ pub trait MutableMap<K, V>: Map<K, V> + Mutable {
     /// Insert a key-value pair into the map. An existing value for a
     /// key is replaced by the new value. Return true if the key did
     /// not already exist in the map.
-    fn insert(&mut self, key: K, value: V) -> bool;
+    #[inline]
+    fn insert(&mut self, key: K, value: V) -> bool {
+        self.swap(key, value).is_none()
+    }
 
     /// Remove a key-value pair from the map. Return true if the key
     /// was present in the map, otherwise false.
-    fn remove(&mut self, key: &K) -> bool;
+    #[inline]
+    fn remove(&mut self, key: &K) -> bool {
+        self.pop(key).is_some()
+    }
 
     /// Insert a key-value pair from the map. If the key already had a value
     /// present in the map, that value is returned. Otherwise None is returned.
index deeda5019422a63183585c39003fe7b4f40724aa..6bef110bfe59ba2caed24019f35a644969a1f38a 100644 (file)
@@ -282,9 +282,6 @@ fn search(&self, hash: uint,
 impl<K:Hash + Eq,V> Container for HashMap<K, V> {
     /// Return the number of elements in the map
     fn len(&self) -> uint { self.size }
-
-    /// Return true if the map contains no elements
-    fn is_empty(&self) -> bool { self.len() == 0 }
 }
 
 impl<K:Hash + Eq,V> Mutable for HashMap<K, V> {
@@ -325,19 +322,6 @@ fn find_mut<'a>(&'a mut self, k: &K) -> Option<&'a mut V> {
         Some(self.mut_value_for_bucket(idx))
     }
 
-    /// Insert a key-value pair into the map. An existing value for a
-    /// key is replaced by the new value. Return true if the key did
-    /// not already exist in the map.
-    fn insert(&mut self, k: K, v: V) -> bool {
-        self.swap(k, v).is_none()
-    }
-
-    /// Remove a key-value pair from the map. Return true if the key
-    /// was present in the map, otherwise false.
-    fn remove(&mut self, k: &K) -> bool {
-        self.pop(k).is_some()
-    }
-
     /// Insert a key-value pair from the map. If the key already had a value
     /// present in the map, that value is returned. Otherwise None is returned.
     fn swap(&mut self, k: K, v: V) -> Option<V> {
@@ -661,9 +645,6 @@ fn ne(&self, other: &HashSet<T>) -> bool { self.map != other.map }
 impl<T:Hash + Eq> Container for HashSet<T> {
     /// Return the number of elements in the set
     fn len(&self) -> uint { self.map.len() }
-
-    /// Return true if the set contains no elements
-    fn is_empty(&self) -> bool { self.map.is_empty() }
 }
 
 impl<T:Hash + Eq> Mutable for HashSet<T> {
index 636bbc48f8eb42100bb4441a153e0b2ee3ecac73..b97730e443c85d43c18921a973d6b9b5d2d9952d 100644 (file)
@@ -1097,24 +1097,16 @@ impl<'self> Container for &'self str {
     fn len(&self) -> uint {
         do self.as_imm_buf |_p, n| { n - 1u }
     }
-    #[inline]
-    fn is_empty(&self) -> bool {
-        self.len() == 0
-    }
 }
 
 impl Container for ~str {
     #[inline]
     fn len(&self) -> uint { self.as_slice().len() }
-    #[inline]
-    fn is_empty(&self) -> bool { self.len() == 0 }
 }
 
 impl Container for @str {
     #[inline]
     fn len(&self) -> uint { self.as_slice().len() }
-    #[inline]
-    fn is_empty(&self) -> bool { self.len() == 0 }
 }
 
 impl Mutable for ~str {
index 822b005de37a2d2051858266df598beeffb89c2e..4665f36134011206e57bfb2958c6768fa3f476c7 100644 (file)
@@ -36,10 +36,6 @@ impl<T> Container for TrieMap<T> {
     /// Return the number of elements in the map
     #[inline]
     fn len(&self) -> uint { self.length }
-
-    /// Return true if the map contains no elements
-    #[inline]
-    fn is_empty(&self) -> bool { self.len() == 0 }
 }
 
 impl<T> Mutable for TrieMap<T> {
@@ -87,21 +83,6 @@ fn find_mut<'a>(&'a mut self, key: &uint) -> Option<&'a mut T> {
         find_mut(&mut self.root.children[chunk(*key, 0)], *key, 1)
     }
 
-    /// Insert a key-value pair into the map. An existing value for a
-    /// key is replaced by the new value. Return true if the key did
-    /// not already exist in the map.
-    #[inline]
-    fn insert(&mut self, key: uint, value: T) -> bool {
-        self.swap(key, value).is_none()
-    }
-
-    /// Remove a key-value pair from the map. Return true if the key
-    /// was present in the map, otherwise false.
-    #[inline]
-    fn remove(&mut self, key: &uint) -> bool {
-        self.pop(key).is_some()
-    }
-
     /// Insert a key-value pair from the map. If the key already had a value
     /// present in the map, that value is returned. Otherwise None is returned.
     fn swap(&mut self, key: uint, value: T) -> Option<T> {
@@ -194,10 +175,6 @@ impl Container for TrieSet {
     /// Return the number of elements in the set
     #[inline]
     fn len(&self) -> uint { self.map.len() }
-
-    /// Return true if the set contains no elements
-    #[inline]
-    fn is_empty(&self) -> bool { self.map.is_empty() }
 }
 
 impl Mutable for TrieSet {