bc5a73ec376d9d06861b8d07e7abfe615fc38501 angie Wed Apr 10 09:39:10 2019 -0700 Added hashIntReset, to quickly remove & reset to 0 all integer values of a hash. [It can also NULL out hashEl pointers, but mem alloc issues should be considered] diff --git src/lib/hash.c src/lib/hash.c index 7653201..82a7924 100644 --- src/lib/hash.c +++ src/lib/hash.c @@ -335,30 +335,37 @@ { long long sum = 0; int i; struct hashEl *hel; for (i=0; i<hash->size; ++i) { for (hel = hash->table[i]; hel != NULL; hel = hel->next) { int num = ptToInt(hel->val); sum += (long long)num; } } return sum; } +void hashIntReset(struct hash *hash) +/* Reset all values in hash of ints to 0. Reset element count to 0. */ +{ +memset(hash->table, 0, hash->size * sizeof hash->table[0]); +hash->elCount = 0; +} + struct hash *newHashExt(int powerOfTwoSize, boolean useLocalMem) /* Returns new hash table. Uses local memory optionally. */ { struct hash *hash = needMem(sizeof(*hash)); int memBlockPower = 16; if (powerOfTwoSize == 0) powerOfTwoSize = 12; assert(powerOfTwoSize <= hashMaxSize && powerOfTwoSize > 0); hash->powerOfTwoSize = powerOfTwoSize; hash->size = (1<<powerOfTwoSize); /* Make size of memory block for allocator vary between * 256 bytes and 64k depending on size of table. */ if (powerOfTwoSize < 8) memBlockPower = 8; else if (powerOfTwoSize < 16)