Skip to content

Commit f50551f

Browse files
committed
---
yaml --- r: 602 b: refs/heads/master c: 5cf83dc h: refs/heads/master v: v3
1 parent 3d448a9 commit f50551f

File tree

2 files changed

+70
-3
lines changed

2 files changed

+70
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: c3c5e6c77388f3f81449c668e6a97b064cf41852
2+
refs/heads/master: 5cf83dcc1ae5575649ead36a7e4e8aeb6a017081

trunk/src/test/run-pass/lib-map.rs

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ fn test_simple() {
1313
ret u;
1414
}
1515

16-
let map.hashfn[uint] hasher = hash;
17-
let map.eqfn[uint] eqer = eq;
16+
// FIXME we don't really want to bind here but if we don't then the
17+
// hashmap's drop glue UMRs when trying to drop these functions, which
18+
// it stores internally.
19+
let map.hashfn[uint] hasher = bind hash(_);
20+
let map.eqfn[uint] eqer = bind eq(_, _);
1821
let map.hashmap[uint, uint] hm = map.mk_hashmap[uint, uint](hasher, eqer);
22+
1923
hm.insert(10u, 12u);
2024
hm.insert(11u, 13u);
2125
hm.insert(12u, 14u);
@@ -24,9 +28,72 @@ fn test_simple() {
2428
check (hm.get(12u) == 14u);
2529
check (hm.get(10u) == 12u);
2630

31+
hm.insert(12u, 14u);
32+
check (hm.get(12u) == 14u);
33+
34+
hm.insert(12u, 12u);
35+
check (hm.get(12u) == 12u);
36+
2737
log "*** finished test_simple";
2838
}
2939

40+
/**
41+
* Force map growth and rehashing.
42+
*/
43+
fn test_growth() {
44+
log "*** starting test_growth";
45+
46+
let uint map_capacity = 64u; // Keep in sync with map.mk_hashmap
47+
48+
fn eq(&uint x, &uint y) -> bool { ret x == y; }
49+
fn hash(&uint u) -> uint {
50+
// FIXME: can't use std.util.id since we'd be capturing a type param,
51+
// and presently we can't close items over type params.
52+
ret u;
53+
}
54+
55+
// FIXME: as in test_simple(), don't really want to bind.
56+
let map.hashfn[uint] hasher = bind hash(_);
57+
let map.eqfn[uint] eqer = bind eq(_, _);
58+
let map.hashmap[uint, uint] hm = map.mk_hashmap[uint, uint](hasher, eqer);
59+
60+
let uint i = 0u;
61+
while (i < map_capacity) {
62+
hm.insert(i, i * i);
63+
log "inserting " + std._uint.to_str(i, 10u)
64+
+ " -> " + std._uint.to_str(i * i, 10u);
65+
i += 1u;
66+
}
67+
68+
log "-----";
69+
70+
i = 0u;
71+
while (i < map_capacity) {
72+
log "get(" + std._uint.to_str(i, 10u) + ") = "
73+
+ std._uint.to_str(hm.get(i), 10u);
74+
check (hm.get(i) == i * i);
75+
i += 1u;
76+
}
77+
78+
hm.insert(map_capacity, 17u);
79+
check (hm.get(map_capacity) == 17u);
80+
81+
log "-----";
82+
83+
hm.rehash();
84+
85+
i = 0u;
86+
while (i < map_capacity) {
87+
log "get(" + std._uint.to_str(i, 10u) + ") = "
88+
+ std._uint.to_str(hm.get(i), 10u);
89+
check (hm.get(i) == i * i);
90+
i += 1u;
91+
}
92+
93+
log "*** finished test_growth";
94+
}
95+
3096
fn main() {
3197
test_simple();
98+
test_growth();
3299
}

0 commit comments

Comments
 (0)