Skip to content

Commit 64b64e5

Browse files
committed
---
yaml --- r: 42868 b: refs/heads/try c: 274e75c h: refs/heads/master v: v3
1 parent 6582df1 commit 64b64e5

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 19dfec2aaf746535de1521f68421f9980dbf25de
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
5-
refs/heads/try: aee79294699153ac7da9d2e5d076192c6eee3238
5+
refs/heads/try: 274e75cd82ac8b94c655e1cba9194f82c47f73d7
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278

branches/try/src/libstd/smallintmap.rs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
*/
1515
#[forbid(deprecated_mode)];
1616

17-
use map;
1817
use map::StdMap;
1918

19+
use core::container::{Container, Mutable, Map, Set};
2020
use core::dvec::DVec;
2121
use core::ops;
2222
use core::option::{Some, None};
@@ -80,9 +80,9 @@ pub pure fn contains_key<T: Copy>(self: SmallIntMap<T>, key: uint) -> bool {
8080
return !find(self, key).is_none();
8181
}
8282

83-
/// Implements the map::map interface for smallintmap
84-
impl<V: Copy> SmallIntMap<V>: map::StdMap<uint, V> {
85-
pure fn size() -> uint {
83+
impl<V> SmallIntMap<V>: Container {
84+
/// Return the number of elements in the map
85+
pure fn len(&self) -> uint {
8686
let mut sz = 0u;
8787
for self.v.each |item| {
8888
match *item {
@@ -92,6 +92,14 @@ impl<V: Copy> SmallIntMap<V>: map::StdMap<uint, V> {
9292
}
9393
sz
9494
}
95+
96+
/// Return true if the map contains no elements
97+
pure fn is_empty(&self) -> bool { self.len() == 0 }
98+
}
99+
100+
/// Implements the map::map interface for smallintmap
101+
impl<V: Copy> SmallIntMap<V>: StdMap<uint, V> {
102+
pure fn size() -> uint { self.len() }
95103
#[inline(always)]
96104
fn insert(key: uint, value: V) -> bool {
97105
let exists = contains_key(self, key);
@@ -165,8 +173,8 @@ impl<V: Copy> SmallIntMap<V>: ops::Index<uint, V> {
165173
}
166174

167175
/// Cast the given smallintmap to a map::map
168-
pub fn as_map<V: Copy>(s: SmallIntMap<V>) -> map::StdMap<uint, V> {
169-
s as map::StdMap::<uint, V>
176+
pub fn as_map<V: Copy>(s: SmallIntMap<V>) -> StdMap<uint, V> {
177+
s as StdMap::<uint, V>
170178
}
171179

172180
#[cfg(test)]
@@ -176,6 +184,22 @@ mod tests {
176184
use core::option::None;
177185
use core::option;
178186

187+
#[test]
188+
fn test_len() {
189+
let mut map = mk();
190+
assert map.len() == 0;
191+
assert map.is_empty();
192+
map.insert(5, 20);
193+
assert map.len() == 1;
194+
assert !map.is_empty();
195+
map.insert(11, 12);
196+
assert map.len() == 2;
197+
assert !map.is_empty();
198+
map.insert(14, 22);
199+
assert map.len() == 3;
200+
assert !map.is_empty();
201+
}
202+
179203
#[test]
180204
fn test_insert_with_key() {
181205
let map: SmallIntMap<uint> = mk();

0 commit comments

Comments
 (0)