aboutsummaryrefslogtreecommitdiff
path: root/src/map.hff
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-14 07:25:40 +0200
committerlemon <lsof@mailbox.org>2022-08-14 07:25:53 +0200
commitf0def28d9aeeb7f1f9b3d8880a34a05ec59d80ed (patch)
tree72b4f9776a8bc1964d32b3db2e8bf2d78120ad57 /src/map.hff
parent4a656bf19a45e0b3f553f9c518e7e842cc6cbf51 (diff)
multiline comment and stuff
Diffstat (limited to 'src/map.hff')
-rw-r--r--src/map.hff34
1 files changed, 5 insertions, 29 deletions
diff --git a/src/map.hff b/src/map.hff
index d8bbf52..6900878 100644
--- a/src/map.hff
+++ b/src/map.hff
@@ -31,35 +31,6 @@ struct Map<K, V, KTraits> {
assert(#f, "unreachable");
}
- fn put(self *Map, key K, val V) void {
- if self.keys == #null {
- assert(self.vals == #null and self.bitmap == #null and self.N == 0 and self.count == 0,
- "?");
- self.keys = xcalloc(self.N = 16, sizeof K);
- self.vals = xcalloc(self.N, sizeof V);
- self.bitmap = xcalloc(self.N / 8, 1);
- }
-
- if self.count == self.N / 2 {
- // rehash
- }
- let i0 u32 = KTraits:hash(key);
- let i = i0 & (self.N - 1);
- do {
- if self->_iempty(i) {
- self.bitmap[i/8] |= (1 << (i%8));
- ++self.count;
- self.vals[i] = val;
- return;
- } else if KTraits:eq(self.keys[i], key) {
- self.vals[i] = val;
- return;
- }
- i = (i + 1) & (self.N - 1);
- } while i != i0;
- assert(#f, "unreachable");
- }
-
fn get_slot(self *Map, key K) *V {
if self.keys == #null {
assert(self.vals == #null and self.bitmap == #null and self.N == 0 and self.count == 0,
@@ -88,4 +59,9 @@ struct Map<K, V, KTraits> {
assert(#f, "unreachable");
}
+
+ fn put(self *Map, key K, val V) void {
+ *self->get_slot(key) = val;
+ }
+
}