Skip to content

Commit 18e3db7

Browse files
committed
auto merge of #8246 : stepancheg/rust/contains-key, r=thestinger
Map::contains_key can be implemented with Map::find. Remove several implementations of contains_key.
2 parents b5d77d2 + cf9e9b2 commit 18e3db7

File tree

5 files changed

+5
-27
lines changed

5 files changed

+5
-27
lines changed

src/libextra/smallintmap.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ impl<V> Mutable for SmallIntMap<V> {
4646
}
4747

4848
impl<V> Map<uint, V> for SmallIntMap<V> {
49-
/// Return true if the map contains a value for the specified key
50-
fn contains_key(&self, key: &uint) -> bool {
51-
self.find(key).is_some()
52-
}
53-
5449
/// Return a reference to the value corresponding to the key
5550
fn find<'a>(&'a self, key: &uint) -> Option<&'a V> {
5651
if *key < self.v.len() {

src/libextra/treemap.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,6 @@ impl<K: TotalOrd, V> Mutable for TreeMap<K, V> {
105105
}
106106

107107
impl<K: TotalOrd, V> Map<K, V> for TreeMap<K, V> {
108-
/// Return true if the map contains a value for the specified key
109-
fn contains_key(&self, key: &K) -> bool {
110-
self.find(key).is_some()
111-
}
112-
113108
/// Return a reference to the value corresponding to the key
114109
fn find<'a>(&'a self, key: &K) -> Option<&'a V> {
115110
let mut current: &'a Option<~TreeNode<K, V>> = &self.root;

src/libstd/container.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ pub trait Mutable: Container {
3434
/// A map is a key-value store where values may be looked up by their keys. This
3535
/// trait provides basic operations to operate on these stores.
3636
pub trait Map<K, V>: Container {
37-
/// Return true if the map contains a value for the specified key
38-
fn contains_key(&self, key: &K) -> bool;
39-
4037
/// Return a reference to the value corresponding to the key
4138
fn find<'a>(&'a self, key: &K) -> Option<&'a V>;
39+
40+
/// Return true if the map contains a value for the specified key
41+
fn contains_key(&self, key: &K) -> bool {
42+
self.find(key).is_some()
43+
}
4244
}
4345

4446
/// This trait provides basic operations to modify the contents of a map.

src/libstd/hashmap.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,6 @@ impl<K:Hash + Eq,V> Mutable for HashMap<K, V> {
272272
}
273273

274274
impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
275-
/// Return true if the map contains a value for the specified key
276-
fn contains_key(&self, k: &K) -> bool {
277-
match self.bucket_for_key(k) {
278-
FoundEntry(_) => {true}
279-
TableFull | FoundHole(_) => {false}
280-
}
281-
}
282-
283275
/// Return a reference to the value corresponding to the key
284276
fn find<'a>(&'a self, k: &K) -> Option<&'a V> {
285277
match self.bucket_for_key(k) {

src/libstd/trie.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ impl<T> Mutable for TrieMap<T> {
4848
}
4949

5050
impl<T> Map<uint, T> for TrieMap<T> {
51-
/// Return true if the map contains a value for the specified key
52-
#[inline]
53-
fn contains_key(&self, key: &uint) -> bool {
54-
self.find(key).is_some()
55-
}
56-
5751
/// Return a reference to the value corresponding to the key
5852
#[inline]
5953
fn find<'a>(&'a self, key: &uint) -> Option<&'a T> {

0 commit comments

Comments
 (0)