about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorStepan Koltsov <stepan.koltsov@gmail.com>2013-08-03 05:54:05 +0400
committerStepan Koltsov <stepan.koltsov@gmail.com>2013-08-03 05:54:05 +0400
commitcf9e9b21d59eaf6f4d57904ef882a654caa37085 (patch)
tree58a993b3762edb78f849bfd871f60339089d49a7 /src/libstd
parent3ddc72f69be4d0a2027ff598ad262ea2b2ca3812 (diff)
downloadrust-cf9e9b21d59eaf6f4d57904ef882a654caa37085.tar.gz
rust-cf9e9b21d59eaf6f4d57904ef882a654caa37085.zip
Add default implementation of Map::contains_key function
Map::contains_key can be implemented with Map::find.

Remove several implementations of contains_key.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/container.rs8
-rw-r--r--src/libstd/hashmap.rs8
-rw-r--r--src/libstd/trie.rs6
3 files changed, 5 insertions, 17 deletions
diff --git a/src/libstd/container.rs b/src/libstd/container.rs
index 10f3fc6586f..22525d4cab4 100644
--- a/src/libstd/container.rs
+++ b/src/libstd/container.rs
@@ -34,11 +34,13 @@ pub trait Mutable: Container {
 /// A map is a key-value store where values may be looked up by their keys. This
 /// trait provides basic operations to operate on these stores.
 pub trait Map<K, V>: Container {
-    /// Return true if the map contains a value for the specified key
-    fn contains_key(&self, key: &K) -> bool;
-
     /// Return a reference to the value corresponding to the key
     fn find<'a>(&'a self, key: &K) -> Option<&'a V>;
+
+    /// Return true if the map contains a value for the specified key
+    fn contains_key(&self, key: &K) -> bool {
+        self.find(key).is_some()
+    }
 }
 
 /// This trait provides basic operations to modify the contents of a map.
diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs
index e7d51106c58..424a6884d94 100644
--- a/src/libstd/hashmap.rs
+++ b/src/libstd/hashmap.rs
@@ -292,14 +292,6 @@ impl<K:Hash + Eq,V> Mutable for HashMap<K, V> {
 }
 
 impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
-    /// Return true if the map contains a value for the specified key
-    fn contains_key(&self, k: &K) -> bool {
-        match self.bucket_for_key(k) {
-            FoundEntry(_) => {true}
-            TableFull | FoundHole(_) => {false}
-        }
-    }
-
     /// Return a reference to the value corresponding to the key
     fn find<'a>(&'a self, k: &K) -> Option<&'a V> {
         match self.bucket_for_key(k) {
diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs
index 97e2b3b3c34..234f8e31873 100644
--- a/src/libstd/trie.rs
+++ b/src/libstd/trie.rs
@@ -48,12 +48,6 @@ impl<T> Mutable for TrieMap<T> {
 }
 
 impl<T> Map<uint, T> for TrieMap<T> {
-    /// Return true if the map contains a value for the specified key
-    #[inline]
-    fn contains_key(&self, key: &uint) -> bool {
-        self.find(key).is_some()
-    }
-
     /// Return a reference to the value corresponding to the key
     #[inline]
     fn find<'a>(&'a self, key: &uint) -> Option<&'a T> {