Skip to content

Commit 0a19b8d

Browse files
committed
---
yaml --- r: 637 b: refs/heads/master c: ca14753 h: refs/heads/master i: 635: d04cce1 v: v3
1 parent 521d836 commit 0a19b8d

File tree

2 files changed

+96
-38
lines changed

2 files changed

+96
-38
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: 5e5112dac672d2364e446faf55a8fb326d53e741
2+
refs/heads/master: ca1475382e592176884187877a80900578bcf72b

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

Lines changed: 95 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use std;
44
import std.map;
55
import std._str;
6+
import std._uint;
67
import std.util;
78

89
fn test_simple() {
@@ -42,16 +43,20 @@ fn test_simple() {
4243
check (hm_uu.get(12u) == 12u);
4344

4445

45-
/*
46+
let str ten = "ten";
47+
let str eleven = "eleven";
48+
let str twelve = "twelve";
49+
4650
log "str -> uint";
4751

4852
let map.hashmap[str, uint] hm_su = map.mk_hashmap[str, uint](hasher_str,
4953
eqer_str);
50-
5154
check (hm_su.insert("ten", 12u));
52-
check (hm_su.insert("eleven", 13u));
55+
check (hm_su.insert(eleven, 13u));
5356
check (hm_su.insert("twelve", 14u));
5457

58+
check (hm_su.get(eleven) == 13u);
59+
5560
check (hm_su.get("eleven") == 13u);
5661
check (hm_su.get("twelve") == 14u);
5762
check (hm_su.get("ten") == 12u);
@@ -88,9 +93,9 @@ fn test_simple() {
8893
let map.hashmap[str, str] hm_ss = map.mk_hashmap[str, str](hasher_str,
8994
eqer_str);
9095

91-
check (hm_ss.insert("ten", "twelve"));
92-
check (hm_ss.insert("eleven", "thirteen"));
93-
check (hm_ss.insert("twelve", "fourteen"));
96+
check (hm_ss.insert(ten, "twelve"));
97+
check (hm_ss.insert(eleven, "thirteen"));
98+
check (hm_ss.insert(twelve, "fourteen"));
9499

95100
check (_str.eq(hm_ss.get("eleven"), "thirteen"));
96101
check (_str.eq(hm_ss.get("twelve"), "fourteen"));
@@ -101,8 +106,6 @@ fn test_simple() {
101106

102107
check (!hm_ss.insert("twelve", "twelve"));
103108
check (_str.eq(hm_ss.get("twelve"), "twelve"));
104-
*/
105-
106109

107110
log "*** finished test_simple";
108111
}
@@ -115,47 +118,100 @@ fn test_growth() {
115118

116119
let uint num_to_insert = 64u;
117120

118-
fn eq(&uint x, &uint y) -> bool { ret x == y; }
119-
fn hash(&uint u) -> uint {
121+
fn eq_uint(&uint x, &uint y) -> bool { ret x == y; }
122+
fn hash_uint(&uint u) -> uint {
120123
// FIXME: can't use std.util.id since we'd be capturing a type param,
121124
// and presently we can't close items over type params.
122125
ret u;
123126
}
124127

125-
let map.hashfn[uint] hasher = hash;
126-
let map.eqfn[uint] eqer = eq;
127-
let map.hashmap[uint, uint] hm = map.mk_hashmap[uint, uint](hasher, eqer);
128+
129+
log "uint -> uint";
130+
131+
let map.hashfn[uint] hasher_uint = hash_uint;
132+
let map.eqfn[uint] eqer_uint = eq_uint;
133+
let map.hashmap[uint, uint] hm_uu = map.mk_hashmap[uint, uint](hasher_uint,
134+
eqer_uint);
128135

129136
let uint i = 0u;
130137
while (i < num_to_insert) {
131-
check (hm.insert(i, i * i));
132-
log "inserting " + std._uint.to_str(i, 10u)
133-
+ " -> " + std._uint.to_str(i * i, 10u);
138+
check (hm_uu.insert(i, i * i));
139+
log "inserting " + _uint.to_str(i, 10u)
140+
+ " -> " + _uint.to_str(i * i, 10u);
134141
i += 1u;
135142
}
136143

137144
log "-----";
138145
139146
i = 0u;
140147
while (i < num_to_insert) {
141-
log "get(" + std._uint.to_str(i, 10u) + ") = "
142-
+ std._uint.to_str(hm.get(i), 10u);
143-
check (hm.get(i) == i * i);
148+
log "get(" + _uint.to_str(i, 10u) + ") = "
149+
+ _uint.to_str(hm_uu.get(i), 10u);
150+
check (hm_uu.get(i) == i * i);
144151
i += 1u;
145152
}
146153
147-
check (hm.insert(num_to_insert, 17u));
148-
check (hm.get(num_to_insert) == 17u);
154+
check (hm_uu.insert(num_to_insert, 17u));
155+
check (hm_uu.get(num_to_insert) == 17u);
149156
150157
log "-----";
151158
152-
hm.rehash();
159+
hm_uu.rehash();
153160
154161
i = 0u;
155162
while (i < num_to_insert) {
156-
log "get(" + std._uint.to_str(i, 10u) + ") = "
157-
+ std._uint.to_str(hm.get(i), 10u);
158-
check (hm.get(i) == i * i);
163+
log "get(" + _uint.to_str(i, 10u) + ") = "
164+
+ _uint.to_str(hm_uu.get(i), 10u);
165+
check (hm_uu.get(i) == i * i);
166+
i += 1u;
167+
}
168+
169+
170+
log "str -> str";
171+
172+
let map.hashfn[str] hasher_str = _str.hash;
173+
let map.eqfn[str] eqer_str = _str.eq;
174+
let map.hashmap[str, str] hm_ss = map.mk_hashmap[str, str](hasher_str,
175+
eqer_str);
176+
177+
i = 0u;
178+
while (i < num_to_insert) {
179+
check (hm_ss.insert(_uint.to_str(i, 2u), _uint.to_str(i * i, 2u)));
180+
log "inserting \"" + _uint.to_str(i, 2u)
181+
+ "\" -> \"" + _uint.to_str(i * i, 2u) + "\"";
182+
i += 1u;
183+
}
184+
185+
log "-----";
186+
187+
i = 0u;
188+
while (i < num_to_insert) {
189+
log "get(\""
190+
+ _uint.to_str(i, 2u)
191+
+ "\") = \""
192+
+ hm_ss.get(_uint.to_str(i, 2u)) + "\"";
193+
194+
check (_str.eq(hm_ss.get(_uint.to_str(i, 2u)),
195+
_uint.to_str(i * i, 2u)));
196+
i += 1u;
197+
}
198+
199+
check (hm_ss.insert(_uint.to_str(num_to_insert, 2u),
200+
_uint.to_str(17u, 2u)));
201+
202+
check (_str.eq(hm_ss.get(_uint.to_str(num_to_insert, 2u)),
203+
_uint.to_str(17u, 2u)));
204+
205+
log "-----";
206+
207+
hm_ss.rehash();
208+
209+
i = 0u;
210+
while (i < num_to_insert) {
211+
log "get(\"" + _uint.to_str(i, 2u) + "\") = \""
212+
+ hm_ss.get(_uint.to_str(i, 2u)) + "\"";
213+
check (_str.eq(hm_ss.get(_uint.to_str(i, 2u)),
214+
_uint.to_str(i * i, 2u)));
159215
i += 1u;
160216
}
161217

@@ -185,8 +241,8 @@ fn test_removal() {
185241
let uint i = 0u;
186242
while (i < num_to_insert) {
187243
check (hm.insert(i, i * i));
188-
log "inserting " + std._uint.to_str(i, 10u)
189-
+ " -> " + std._uint.to_str(i * i, 10u);
244+
log "inserting " + _uint.to_str(i, 10u)
245+
+ " -> " + _uint.to_str(i * i, 10u);
190246
i += 1u;
191247
}
192248

@@ -223,8 +279,8 @@ fn test_removal() {
223279
224280
i = 1u;
225281
while (i < num_to_insert) {
226-
log "get(" + std._uint.to_str(i, 10u) + ") = "
227-
+ std._uint.to_str(hm.get(i), 10u);
282+
log "get(" + _uint.to_str(i, 10u) + ") = "
283+
+ _uint.to_str(hm.get(i), 10u);
228284
check (hm.get(i) == i * i);
229285
i += 2u;
230286
}
@@ -238,8 +294,8 @@ fn test_removal() {
238294
239295
i = 1u;
240296
while (i < num_to_insert) {
241-
log "get(" + std._uint.to_str(i, 10u) + ") = "
242-
+ std._uint.to_str(hm.get(i), 10u);
297+
log "get(" + _uint.to_str(i, 10u) + ") = "
298+
+ _uint.to_str(hm.get(i), 10u);
243299
check (hm.get(i) == i * i);
244300
i += 2u;
245301
}
@@ -249,8 +305,8 @@ fn test_removal() {
249305
i = 0u;
250306
while (i < num_to_insert) {
251307
check (hm.insert(i, i * i));
252-
log "inserting " + std._uint.to_str(i, 10u)
253-
+ " -> " + std._uint.to_str(i * i, 10u);
308+
log "inserting " + _uint.to_str(i, 10u)
309+
+ " -> " + _uint.to_str(i * i, 10u);
254310
i += 2u;
255311
}
256312
@@ -260,8 +316,8 @@ fn test_removal() {
260316
261317
i = 0u;
262318
while (i < num_to_insert) {
263-
log "get(" + std._uint.to_str(i, 10u) + ") = "
264-
+ std._uint.to_str(hm.get(i), 10u);
319+
log "get(" + _uint.to_str(i, 10u) + ") = "
320+
+ _uint.to_str(hm.get(i), 10u);
265321
check (hm.get(i) == i * i);
266322
i += 1u;
267323
}
@@ -277,8 +333,8 @@ fn test_removal() {
277333
278334
i = 0u;
279335
while (i < num_to_insert) {
280-
log "get(" + std._uint.to_str(i, 10u) + ") = "
281-
+ std._uint.to_str(hm.get(i), 10u);
336+
log "get(" + _uint.to_str(i, 10u) + ") = "
337+
+ _uint.to_str(hm.get(i), 10u);
282338
check (hm.get(i) == i * i);
283339
i += 1u;
284340
}
@@ -290,4 +346,6 @@ fn main() {
290346
test_simple();
291347
test_growth();
292348
test_removal();
349+
350+
std.sys.rustrt.gc();
293351
}

0 commit comments

Comments
 (0)