blob: 81c9f94d1b26c656184d5578e7df6317996a50e7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
def HASHMAP_SIZE: size = 1 << 14;
type hashmap = [HASHMAP_SIZE](size, stat);
fn getitem(map: *hashmap, hash: size) stat = {
let i = hash & (HASHMAP_SIZE - 1);
for (true) {
if (map[i].0 == 0 && map[i].1.count == 0)
break;
if (map[i].0 == hash)
return map[i].1;
i = (i + 1) & (HASHMAP_SIZE - 1);
};
return stat { ... };
};
fn setitem(map: *hashmap, hash: size, value: stat) void = {
let i = hash & (HASHMAP_SIZE - 1);
for (true) {
if (map[i].0 == 0 && map[i].1.count == 0)
break;
if (map[i].0 == hash) {
map[i].1 = value;
return;
};
i = (i + 1) & (HASHMAP_SIZE - 1);
};
map[i] = (hash, value);
};
|