Fix mod-bug in std.map, work around bug in closure typaram capture, enable insert-tests in lib-map.rs.
This commit is contained in:
parent
9ea37bd47b
commit
e846643d23
@ -47,18 +47,17 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
|
||||
// fixed key.
|
||||
|
||||
fn hashl[K](&hashfn[K] hasher, uint nbkts, &K key) -> uint {
|
||||
ret (hasher(key) >>> (sys.rustrt.size_of[uint]() * 8u / 2u))
|
||||
% nbkts;
|
||||
ret (hasher(key) >>> (sys.rustrt.size_of[uint]() * 8u / 2u));
|
||||
}
|
||||
|
||||
fn hashr[K](&hashfn[K] hasher, uint nbkts, &K key) -> uint {
|
||||
ret ((((~ 0u) >>> (sys.rustrt.size_of[uint]() * 8u / 2u))
|
||||
& hasher(key)) * 2u + 1u)
|
||||
% nbkts;
|
||||
& hasher(key)) * 2u + 1u);
|
||||
}
|
||||
|
||||
fn hash[K](&hashfn[K] hasher, uint nbkts, &K key, uint i) -> uint {
|
||||
ret hashl[K](hasher, nbkts, key) + i * hashr[K](hasher, nbkts, key);
|
||||
ret (hashl[K](hasher, nbkts, key)
|
||||
+ i * hashr[K](hasher, nbkts, key)) % nbkts;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7,11 +7,18 @@ fn test_simple() {
|
||||
log "*** starting test_simple";
|
||||
|
||||
fn eq(&uint x, &uint y) -> bool { ret x == y; }
|
||||
fn hash(&uint u) -> uint {
|
||||
// FIXME: can't use std.util.id since we'd be capturing a type param,
|
||||
// and presently we can't close items over type params.
|
||||
ret u;
|
||||
}
|
||||
|
||||
let map.hashfn[uint] hasher = std.util.id[uint];
|
||||
let map.hashfn[uint] hasher = hash;
|
||||
let map.eqfn[uint] eqer = eq;
|
||||
let map.hashmap[uint, uint] hm = map.mk_hashmap[uint, uint](hasher, eqer);
|
||||
|
||||
hm.insert(10u, 12u);
|
||||
hm.insert(11u, 13u);
|
||||
hm.insert(12u, 14u);
|
||||
log "*** finished test_simple";
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user