diff options
Diffstat (limited to 'rts/Hash.c')
-rw-r--r-- | rts/Hash.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/rts/Hash.c b/rts/Hash.c index 31a285aefa..6e1873ff29 100644 --- a/rts/Hash.c +++ b/rts/Hash.c @@ -492,6 +492,27 @@ mapHashTableKeys(HashTable *table, void *data, MapHashFnKeys fn) } } +void +iterHashTable(HashTable *table, void *data, IterHashFn fn) +{ + /* The last bucket with something in it is table->max + table->split - 1 */ + long segment = (table->max + table->split - 1) / HSEGSIZE; + long index = (table->max + table->split - 1) % HSEGSIZE; + + while (segment >= 0) { + while (index >= 0) { + for (HashList *hl = table->dir[segment][index]; hl != NULL; hl = hl->next) { + if (!fn(data, hl->key, hl->data)) { + return; + } + } + index--; + } + segment--; + index = HSEGSIZE - 1; + } +} + /* ----------------------------------------------------------------------------- * When we initialize a hash table, we set up the first segment as well, * initializing all of the first segment's hash buckets to NULL. @@ -522,12 +543,6 @@ allocHashTable(void) return table; } -void -exitHashTable(void) -{ - /* nothing to do */ -} - int keyCountHashTable (HashTable *table) { return table->kcount; |