Skip to content

Commit 0e2db0d

Browse files
committed
---
yaml --- r: 127760 b: refs/heads/master c: 8f71cb0 h: refs/heads/master v: v3
1 parent ff4c843 commit 0e2db0d

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 11b8f9c3f666e3a0533da0f3a00188689fc60cb4
2+
refs/heads/master: 8f71cb06bc019af707f119b5dda3d96a5ca1330c
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: aa98b25c4f0c10729dff37c699904ad57b8fbda8
55
refs/heads/try: d9c23fcbaea89871667272a67ecb8d3a512162f3

trunk/src/libcollections/trie.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,21 @@ impl<S: Writer, T: Hash<S>> Hash<S> for TrieMap<T> {
502502
}
503503
}
504504

505+
impl<T> Index<uint, T> for TrieMap<T> {
506+
#[inline]
507+
fn index<'a>(&'a self, i: &uint) -> &'a T {
508+
self.find(i).expect("key not present")
509+
}
510+
}
511+
512+
// FIXME(#12825) Indexing will always try IndexMut first and that causes issues.
513+
/*impl<T> IndexMut<uint, T> for TrieMap<T> {
514+
#[inline]
515+
fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut T {
516+
self.find_mut(i).expect("key not present")
517+
}
518+
}*/
519+
505520
/// A set implemented as a radix trie.
506521
///
507522
/// # Example
@@ -1391,6 +1406,29 @@ mod test_map {
13911406
assert!(map_str == "{1: a, 2: b}".to_string());
13921407
assert_eq!(format!("{}", empty), "{}".to_string());
13931408
}
1409+
1410+
#[test]
1411+
fn test_index() {
1412+
let mut map = TrieMap::new();
1413+
1414+
map.insert(1, 2i);
1415+
map.insert(2, 1i);
1416+
map.insert(3, 4i);
1417+
1418+
assert_eq!(map[2], 1);
1419+
}
1420+
1421+
#[test]
1422+
#[should_fail]
1423+
fn test_index_nonexistent() {
1424+
let mut map = TrieMap::new();
1425+
1426+
map.insert(1, 2i);
1427+
map.insert(2, 1i);
1428+
map.insert(3, 4i);
1429+
1430+
map[4];
1431+
}
13941432
}
13951433

13961434
#[cfg(test)]

0 commit comments

Comments
 (0)