aboutsummaryrefslogtreecommitdiff
path: root/src/map.hff
diff options
context:
space:
mode:
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;
+ }
+
}