Skip to content

Commit fa7a43c

Browse files
committed
---
yaml --- r: 64776 b: refs/heads/snap-stage3 c: d6bc438 h: refs/heads/master v: v3
1 parent b41bf07 commit fa7a43c

File tree

11 files changed

+81
-16
lines changed

11 files changed

+81
-16
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 5157e05049d76f1206c9f879961194d4ac26ce58
4+
refs/heads/snap-stage3: d6bc438bbcb9240d0303ffec81bf1a617f0903a5
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/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]
707706
fn len(&self) -> uint { self.size }
707+
fn is_empty(&self) -> bool { self.size == 0 }
708708
}
709709

710710
impl Mutable for BitvSet {

branches/snap-stage3/src/libextra/priority_queue.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ 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 }
3033
}
3134

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

branches/snap-stage3/src/libextra/ringbuf.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ 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 }
3740
}
3841

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

branches/snap-stage3/src/libextra/smallintmap.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ 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 }
4043
}
4144

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

branches/snap-stage3/src/libextra/treemap.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ 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+
138151
/// Insert a key-value pair from the map. If the key already had a value
139152
/// present in the map, that value is returned. Otherwise None is returned.
140153
fn swap(&mut self, key: K, value: V) -> Option<V> {

branches/snap-stage3/src/libstd/container.rs

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

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

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

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

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

branches/snap-stage3/src/libstd/hashmap.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ 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 }
285288
}
286289

287290
impl<K:Hash + Eq,V> Mutable for HashMap<K, V> {
@@ -322,6 +325,19 @@ impl<K:Hash + Eq,V> MutableMap<K, V> for HashMap<K, V> {
322325
Some(self.mut_value_for_bucket(idx))
323326
}
324327

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+
325341
/// Insert a key-value pair from the map. If the key already had a value
326342
/// present in the map, that value is returned. Otherwise None is returned.
327343
fn swap(&mut self, k: K, v: V) -> Option<V> {
@@ -645,6 +661,9 @@ impl<T:Hash + Eq> Eq for HashSet<T> {
645661
impl<T:Hash + Eq> Container for HashSet<T> {
646662
/// Return the number of elements in the set
647663
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() }
648667
}
649668

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

branches/snap-stage3/src/libstd/iterator.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use uint;
2929
/// Conversion from an `Iterator`
3030
pub trait FromIterator<A, T: Iterator<A>> {
3131
/// Build a container with elements from an external iterator.
32-
pub fn from_iterator(iterator: &mut T) -> Self;
32+
fn from_iterator(iterator: &mut T) -> Self;
3333
}
3434

3535
/// An interface for dealing with "external iterators". These types of iterators
@@ -52,7 +52,9 @@ pub trait DoubleEndedIterator<A>: Iterator<A> {
5252
}
5353

5454
/// An object implementing random access indexing by `uint`
55-
pub trait RandomAccessIterator<A> {
55+
///
56+
/// A `RandomAccessIterator` should be either infinite or a `DoubleEndedIterator`.
57+
pub trait RandomAccessIterator<A>: Iterator<A> {
5658
/// Return the number of indexable elements. At most `std::uint::max_value`
5759
/// elements are indexable, even if the iterator represents a longer range.
5860
fn indexable(&self) -> uint;

branches/snap-stage3/src/libstd/str.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,16 +1099,24 @@ 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+
}
11021106
}
11031107
11041108
impl Container for ~str {
11051109
#[inline]
11061110
fn len(&self) -> uint { self.as_slice().len() }
1111+
#[inline]
1112+
fn is_empty(&self) -> bool { self.len() == 0 }
11071113
}
11081114
11091115
impl Container for @str {
11101116
#[inline]
11111117
fn len(&self) -> uint { self.as_slice().len() }
1118+
#[inline]
1119+
fn is_empty(&self) -> bool { self.len() == 0 }
11121120
}
11131121
11141122
impl Mutable for ~str {

branches/snap-stage3/src/libstd/trie.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ 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 }
3943
}
4044

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

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+
86105
/// Insert a key-value pair from the map. If the key already had a value
87106
/// present in the map, that value is returned. Otherwise None is returned.
88107
fn swap(&mut self, key: uint, value: T) -> Option<T> {
@@ -175,6 +194,10 @@ impl Container for TrieSet {
175194
/// Return the number of elements in the set
176195
#[inline]
177196
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() }
178201
}
179202

180203
impl Mutable for TrieSet {

0 commit comments

Comments
 (0)