Skip to content

Commit 5157e05

Browse files
committed
auto merge of #8036 : sfackler/rust/container-impls, r=msullivan
A couple of implementations of Container::is_empty weren't exactly self.len() == 0 so I left them alone (e.g. Treemap).
2 parents 0522955 + feb18fe commit 5157e05

File tree

9 files changed

+13
-76
lines changed

9 files changed

+13
-76
lines changed

src/libextra/bitv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,8 @@ impl cmp::Eq for BitvSet {
703703
}
704704

705705
impl Container for BitvSet {
706+
#[inline]
706707
fn len(&self) -> uint { self.size }
707-
fn is_empty(&self) -> bool { self.size == 0 }
708708
}
709709

710710
impl Mutable for BitvSet {

src/libextra/priority_queue.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ pub struct PriorityQueue<T> {
2727
impl<T:Ord> Container for PriorityQueue<T> {
2828
/// Returns the length of the queue
2929
fn len(&self) -> uint { self.data.len() }
30-
31-
/// Returns true if a queue contains no elements
32-
fn is_empty(&self) -> bool { self.len() == 0 }
3330
}
3431

3532
impl<T:Ord> Mutable for PriorityQueue<T> {

src/libextra/ringbuf.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ pub struct RingBuf<T> {
3434
impl<T> Container for RingBuf<T> {
3535
/// Return the number of elements in the RingBuf
3636
fn len(&self) -> uint { self.nelts }
37-
38-
/// Return true if the RingBufcontains no elements
39-
fn is_empty(&self) -> bool { self.len() == 0 }
4037
}
4138

4239
impl<T> Mutable for RingBuf<T> {

src/libextra/smallintmap.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ impl<V> Container for SmallIntMap<V> {
3737
}
3838
sz
3939
}
40-
41-
/// Return true if the map contains no elements
42-
fn is_empty(&self) -> bool { self.len() == 0 }
4340
}
4441

4542
impl<V> Mutable for SmallIntMap<V> {

src/libextra/treemap.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,6 @@ impl<K: TotalOrd, V> MutableMap<K, V> for TreeMap<K, V> {
135135
find_mut(&mut self.root, key)
136136
}
137137

138-
/// Insert a key-value pair into the map. An existing value for a
139-
/// key is replaced by the new value. Return true if the key did
140-
/// not already exist in the map.
141-
fn insert(&mut self, key: K, value: V) -> bool {
142-
self.swap(key, value).is_none()
143-
}
144-
145-
/// Remove a key-value pair from the map. Return true if the key
146-
/// was present in the map, otherwise false.
147-
fn remove(&mut self, key: &K) -> bool {
148-
self.pop(key).is_some()
149-
}
150-
151138
/// Insert a key-value pair from the map. If the key already had a value
152139
/// present in the map, that value is returned. Otherwise None is returned.
153140
fn swap(&mut self, key: K, value: V) -> Option<V> {

src/libstd/container.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ pub trait Container {
1919
fn len(&self) -> uint;
2020

2121
/// Return true if the container contains no elements
22-
fn is_empty(&self) -> bool;
22+
#[inline]
23+
fn is_empty(&self) -> bool {
24+
self.len() == 0
25+
}
2326
}
2427

2528
/// A trait to represent mutable containers
@@ -43,11 +46,17 @@ pub trait MutableMap<K, V>: Map<K, V> + Mutable {
4346
/// Insert a key-value pair into the map. An existing value for a
4447
/// key is replaced by the new value. Return true if the key did
4548
/// not already exist in the map.
46-
fn insert(&mut self, key: K, value: V) -> bool;
49+
#[inline]
50+
fn insert(&mut self, key: K, value: V) -> bool {
51+
self.swap(key, value).is_none()
52+
}
4753

4854
/// Remove a key-value pair from the map. Return true if the key
4955
/// was present in the map, otherwise false.
50-
fn remove(&mut self, key: &K) -> bool;
56+
#[inline]
57+
fn remove(&mut self, key: &K) -> bool {
58+
self.pop(key).is_some()
59+
}
5160

5261
/// Insert a key-value pair from the map. If the key already had a value
5362
/// present in the map, that value is returned. Otherwise None is returned.

src/libstd/hashmap.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,6 @@ impl<K:Hash + Eq,V> HashMap<K, V> {
282282
impl<K:Hash + Eq,V> Container for HashMap<K, V> {
283283
/// Return the number of elements in the map
284284
fn len(&self) -> uint { self.size }
285-
286-
/// Return true if the map contains no elements
287-
fn is_empty(&self) -> bool { self.len() == 0 }
288285
}
289286

290287
impl<K:Hash + Eq,V> Mutable for HashMap<K, V> {
@@ -325,19 +322,6 @@ impl<K:Hash + Eq,V> MutableMap<K, V> for HashMap<K, V> {
325322
Some(self.mut_value_for_bucket(idx))
326323
}
327324

328-
/// Insert a key-value pair into the map. An existing value for a
329-
/// key is replaced by the new value. Return true if the key did
330-
/// not already exist in the map.
331-
fn insert(&mut self, k: K, v: V) -> bool {
332-
self.swap(k, v).is_none()
333-
}
334-
335-
/// Remove a key-value pair from the map. Return true if the key
336-
/// was present in the map, otherwise false.
337-
fn remove(&mut self, k: &K) -> bool {
338-
self.pop(k).is_some()
339-
}
340-
341325
/// Insert a key-value pair from the map. If the key already had a value
342326
/// present in the map, that value is returned. Otherwise None is returned.
343327
fn swap(&mut self, k: K, v: V) -> Option<V> {
@@ -661,9 +645,6 @@ impl<T:Hash + Eq> Eq for HashSet<T> {
661645
impl<T:Hash + Eq> Container for HashSet<T> {
662646
/// Return the number of elements in the set
663647
fn len(&self) -> uint { self.map.len() }
664-
665-
/// Return true if the set contains no elements
666-
fn is_empty(&self) -> bool { self.map.is_empty() }
667648
}
668649

669650
impl<T:Hash + Eq> Mutable for HashSet<T> {

src/libstd/str.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,24 +1099,16 @@ impl<'self> Container for &'self str {
10991099
fn len(&self) -> uint {
11001100
do self.as_imm_buf |_p, n| { n - 1u }
11011101
}
1102-
#[inline]
1103-
fn is_empty(&self) -> bool {
1104-
self.len() == 0
1105-
}
11061102
}
11071103
11081104
impl Container for ~str {
11091105
#[inline]
11101106
fn len(&self) -> uint { self.as_slice().len() }
1111-
#[inline]
1112-
fn is_empty(&self) -> bool { self.len() == 0 }
11131107
}
11141108
11151109
impl Container for @str {
11161110
#[inline]
11171111
fn len(&self) -> uint { self.as_slice().len() }
1118-
#[inline]
1119-
fn is_empty(&self) -> bool { self.len() == 0 }
11201112
}
11211113
11221114
impl Mutable for ~str {

src/libstd/trie.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ impl<T> Container for TrieMap<T> {
3636
/// Return the number of elements in the map
3737
#[inline]
3838
fn len(&self) -> uint { self.length }
39-
40-
/// Return true if the map contains no elements
41-
#[inline]
42-
fn is_empty(&self) -> bool { self.len() == 0 }
4339
}
4440

4541
impl<T> Mutable for TrieMap<T> {
@@ -87,21 +83,6 @@ impl<T> MutableMap<uint, T> for TrieMap<T> {
8783
find_mut(&mut self.root.children[chunk(*key, 0)], *key, 1)
8884
}
8985

90-
/// Insert a key-value pair into the map. An existing value for a
91-
/// key is replaced by the new value. Return true if the key did
92-
/// not already exist in the map.
93-
#[inline]
94-
fn insert(&mut self, key: uint, value: T) -> bool {
95-
self.swap(key, value).is_none()
96-
}
97-
98-
/// Remove a key-value pair from the map. Return true if the key
99-
/// was present in the map, otherwise false.
100-
#[inline]
101-
fn remove(&mut self, key: &uint) -> bool {
102-
self.pop(key).is_some()
103-
}
104-
10586
/// Insert a key-value pair from the map. If the key already had a value
10687
/// present in the map, that value is returned. Otherwise None is returned.
10788
fn swap(&mut self, key: uint, value: T) -> Option<T> {
@@ -194,10 +175,6 @@ impl Container for TrieSet {
194175
/// Return the number of elements in the set
195176
#[inline]
196177
fn len(&self) -> uint { self.map.len() }
197-
198-
/// Return true if the set contains no elements
199-
#[inline]
200-
fn is_empty(&self) -> bool { self.map.is_empty() }
201178
}
202179

203180
impl Mutable for TrieSet {

0 commit comments

Comments
 (0)