2019-12-22 00:38:43 +03:00
|
|
|
module hashmap
|
|
|
|
|
2019-10-01 02:14:12 +03:00
|
|
|
import rand
|
|
|
|
|
|
|
|
fn test_random_strings() {
|
2020-01-24 22:13:17 +03:00
|
|
|
mut m := new_hashmap()
|
2019-10-01 02:14:12 +03:00
|
|
|
for i in 0..1000 {
|
|
|
|
mut buf := []byte
|
|
|
|
for j in 0..10 {
|
|
|
|
buf << byte(rand.next(int(`z`) - int(`a`)) + `a`)
|
|
|
|
}
|
|
|
|
s := string(buf)
|
|
|
|
//println(s)
|
|
|
|
m.set(s, i)
|
|
|
|
assert m.get(s) == i
|
|
|
|
}
|
|
|
|
m.set('foo', 12)
|
|
|
|
val := m.get('foo')
|
|
|
|
assert val == 12
|
2019-12-22 00:38:43 +03:00
|
|
|
}
|
2019-10-01 02:14:12 +03:00
|
|
|
|
|
|
|
fn test_large_hashmap() {
|
|
|
|
N := 300 * 1000
|
2020-01-24 22:13:17 +03:00
|
|
|
mut nums := new_hashmap()
|
2019-10-01 02:14:12 +03:00
|
|
|
for i := 0; i < N; i++ {
|
|
|
|
key := i.str()
|
|
|
|
nums.set(key, i)
|
|
|
|
}
|
|
|
|
for i := 0; i < N; i++ {
|
|
|
|
key := i.str()
|
|
|
|
assert nums.get(key) == i
|
|
|
|
}
|
2019-12-22 00:38:43 +03:00
|
|
|
}
|