From 42fdb7eb02593476b5030ce4a7dc471d4b01a49e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 9 Nov 2009 18:05:43 -0800 Subject: Add hash removal. --- ChangeLog | 8 ++++++++ hash.c | 10 ++++++++++ hash.h | 1 + 3 files changed, 19 insertions(+) diff --git a/ChangeLog b/ChangeLog index e0cd1670..0f71e03d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-11-06 Kaz Kylheku + + Add hash removal. + + * hash.c (remhash): New function. + + * hash.h (remhash): Declared. + 2009-11-06 Kaz Kylheku Add hash table growth. 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); -- cgit v1.2.3