Skip to content

Commit 8a7c5f5

Browse files
committed
---
yaml --- r: 128728 b: refs/heads/try c: 2dd6bc6 h: refs/heads/master v: v3
1 parent caaec62 commit 8a7c5f5

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
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: 07d86b46a949a94223da714e35b343243e4ecce4
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a86d9ad15e339ab343a12513f9c90556f677b9ca
5-
refs/heads/try: 32f5898bea0ebed00b066a211749ce155aa2b8a6
5+
refs/heads/try: 2dd6bc6887858f91b846ffa7dbd9f0f49b9f3b87
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libcollections/treemap.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,20 @@ impl<K: Ord, V> Default for TreeMap<K,V> {
237237
fn default() -> TreeMap<K, V> { TreeMap::new() }
238238
}
239239

240+
impl<K: Ord, V> Index<K, V> for TreeMap<K, V> {
241+
#[inline]
242+
fn index<'a>(&'a self, i: &K) -> &'a V {
243+
self.find(i).expect("no entry found for key")
244+
}
245+
}
246+
247+
/*impl<K: Ord, V> IndexMut<K, V> for TreeMap<K, V> {
248+
#[inline]
249+
fn index_mut<'a>(&'a mut self, i: &K) -> &'a mut V {
250+
self.find_mut(i).expect("no entry found for key")
251+
}
252+
}*/
253+
240254
impl<K: Ord, V> TreeMap<K, V> {
241255
/// Create an empty `TreeMap`.
242256
///
@@ -2131,6 +2145,28 @@ mod test_treemap {
21312145
}
21322146
}
21332147

2148+
#[test]
2149+
fn test_index() {
2150+
let mut map: TreeMap<int, int> = TreeMap::new();
2151+
2152+
map.insert(1, 2);
2153+
map.insert(2, 1);
2154+
map.insert(3, 4);
2155+
2156+
assert_eq!(map[2], 1);
2157+
}
2158+
2159+
#[test]
2160+
#[should_fail]
2161+
fn test_index_nonexistent() {
2162+
let mut map: TreeMap<int, int> = TreeMap::new();
2163+
2164+
map.insert(1, 2);
2165+
map.insert(2, 1);
2166+
map.insert(3, 4);
2167+
2168+
map[4];
2169+
}
21342170
}
21352171

21362172
#[cfg(test)]

0 commit comments

Comments
 (0)