Skip to content

Commit 5426512

Browse files
committed
---
yaml --- r: 48766 b: refs/heads/snap-stage3 c: ebba8b4 h: refs/heads/master v: v3
1 parent 8f320af commit 5426512

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
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 3bbcac322669cff3abde5be937cc4ec3860f3985
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: dc5ad5070d06015d6a45f656882ae245197d0ff8
4+
refs/heads/snap-stage3: ebba8b4e3591c95508a4c1121784e768272a574a
55
refs/heads/try: 2a8fb58d79e685d5ca07b039badcf2ae3ef077ea
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/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)