Skip to content

Commit 5c654d8

Browse files
committed
---
yaml --- r: 51416 b: refs/heads/incoming c: ebba8b4 h: refs/heads/master v: v3
1 parent 404ba58 commit 5c654d8

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/incoming: dc5ad5070d06015d6a45f656882ae245197d0ff8
9+
refs/heads/incoming: ebba8b4e3591c95508a4c1121784e768272a574a
1010
refs/heads/dist-snap: 8b98e5a296d95c5e832db0756828e5bec31c6f50
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libcore/trie.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ impl<T> Map<uint, T> for TrieMap<T> {
137137
}
138138

139139
impl<T> TrieMap<T> {
140+
/// Create an empty TrieMap
140141
#[inline(always)]
141142
static pure fn new() -> TrieMap<T> {
142143
TrieMap{root: TrieNode::new(), length: 0}
@@ -191,6 +192,12 @@ impl Mutable for TrieSet {
191192
}
192193

193194
impl TrieSet {
195+
/// Create an empty TrieSet
196+
#[inline(always)]
197+
static pure fn new() -> TrieSet {
198+
TrieSet{map: TrieMap::new()}
199+
}
200+
194201
/// Return true if the set contains a value
195202
#[inline(always)]
196203
pure fn contains(&self, value: &uint) -> bool {
@@ -265,8 +272,8 @@ impl<T> TrieNode<T> {
265272
// if this was done via a trait, the key could be generic
266273
#[inline(always)]
267274
pure fn chunk(n: uint, idx: uint) -> uint {
268-
let real_idx = uint::bytes - 1 - idx;
269-
(n >> (SHIFT * real_idx)) & MASK
275+
let sh = uint::bits - (SHIFT * (idx + 1));
276+
(n >> sh) & MASK
270277
}
271278

272279
fn insert<T>(count: &mut uint, child: &mut Child<T>, key: uint, value: T,
@@ -462,4 +469,26 @@ mod tests {
462469
n -= 1;
463470
}
464471
}
472+
473+
#[test]
474+
fn test_sane_chunk() {
475+
let x = 1;
476+
let y = 1 << (uint::bits - 1);
477+
478+
let mut trie = TrieSet::new();
479+
480+
fail_unless!(trie.insert(x));
481+
fail_unless!(trie.insert(y));
482+
483+
fail_unless!(trie.len() == 2);
484+
485+
let expected = [x, y];
486+
487+
let mut i = 0;
488+
489+
for trie.each |x| {
490+
fail_unless!(expected[i] == *x);
491+
i += 1;
492+
}
493+
}
465494
}

0 commit comments

Comments
 (0)