summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--hash.c10
-rw-r--r--hash.h1
3 files changed, 19 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index e0cd1670..0f71e03d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2009-11-06 Kaz Kylheku <kkylheku@gmail.com>
+ Add hash removal.
+
+ * hash.c (remhash): New function.
+
+ * hash.h (remhash): Declared.
+
+2009-11-06 Kaz Kylheku <kkylheku@gmail.com>
+
Add hash table growth.
hash.c (hash_grow): New function.
diff --git a/hash.c b/hash.c
index 7516a128..d583862f 100644
--- a/hash.c
+++ b/hash.c
@@ -246,6 +246,16 @@ obj_t *gethash(obj_t *hash, obj_t *key)
return cdr(found);
}
+obj_t *remhash(obj_t *hash, obj_t *key)
+{
+ struct hash *h = (struct hash *) hash->co.handle;
+ obj_t **pchain = vecref_l(h->table, num(ll_hash(key) % h->modulus));
+ *pchain = alist_remove1(*pchain, key);
+ h->count--;
+ bug_unless (h->count >= 0);
+ return nil;
+}
+
/*
* Called from garbage collector. Hash module must process all weak tables
* that were visited during the marking phase, maintained in the list
diff --git a/hash.h b/hash.h
index 0240546a..bdce904a 100644
--- a/hash.h
+++ b/hash.h
@@ -28,6 +28,7 @@ obj_t *hash_obj(obj_t *);
obj_t *make_hash(obj_t *weak_keys, obj_t *weak_vals);
obj_t **gethash_l(obj_t *hash, obj_t *key);
obj_t *gethash(obj_t *hash, obj_t *key);
+obj_t *remhash(obj_t *hash, obj_t *key);
void hash_process_weak(void);
void hash_init(void);