Skip to content

Commit b2a2fe4

Browse files
committed
---
yaml --- r: 128730 b: refs/heads/try c: 8f71cb0 h: refs/heads/master v: v3
1 parent f605612 commit b2a2fe4

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
@@ -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: 11b8f9c3f666e3a0533da0f3a00188689fc60cb4
5+
refs/heads/try: 8f71cb06bc019af707f119b5dda3d96a5ca1330c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/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)