diff options
author | Daniel Dunbar <daniel@zuster.org> | 2004-01-07 09:13:43 +0300 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2004-01-07 09:13:43 +0300 |
commit | 7f609ec2aa5f3c4ec3635bf9ab3ac636089ec891 (patch) | |
tree | 70e7998d20bb0be220869bf66e59f513fed55f8c /source/blender/blenlib/intern/BLI_ghash.c | |
parent | 8e9e9e6e357539caee8bbdc337b3369ffb574c14 (diff) |
- added BLI_ghash_size(), number of entries in table
- added GHashIterator ADT, for iterating over GHash-tables
Diffstat (limited to 'source/blender/blenlib/intern/BLI_ghash.c')
-rw-r--r-- | source/blender/blenlib/intern/BLI_ghash.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index bb7ef40ffb4..e523cdcdea9 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -139,6 +139,10 @@ int BLI_ghash_haskey(GHash *gh, void *key) { return 0; } +int BLI_ghash_size(GHash *gh) { + return gh->nentries; +} + void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp) { int i; @@ -162,6 +166,53 @@ void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreef /***/ +struct GHashIterator { + GHash *gh; + int curBucket; + Entry *curEntry; +}; + +GHashIterator *BLI_ghashIterator_new(GHash *gh) { + GHashIterator *ghi= malloc(sizeof(*ghi)); + ghi->gh= gh; + ghi->curEntry= NULL; + ghi->curBucket= -1; + while (!ghi->curEntry) { + ghi->curBucket++; + if (ghi->curBucket==ghi->gh->nbuckets) + break; + ghi->curEntry= ghi->gh->buckets[ghi->curBucket]; + } + return ghi; +} +void BLI_ghashIterator_free(GHashIterator *ghi) { + free(ghi); +} + +void *BLI_ghashIterator_getKey(GHashIterator *ghi) { + return ghi->curEntry?ghi->curEntry->key:NULL; +} +void *BLI_ghashIterator_getValue(GHashIterator *ghi) { + return ghi->curEntry?ghi->curEntry->val:NULL; +} + +void BLI_ghashIterator_step(GHashIterator *ghi) { + if (ghi->curEntry) { + ghi->curEntry= ghi->curEntry->next; + while (!ghi->curEntry) { + ghi->curBucket++; + if (ghi->curBucket==ghi->gh->nbuckets) + break; + ghi->curEntry= ghi->gh->buckets[ghi->curBucket]; + } + } +} +int BLI_ghashIterator_isDone(GHashIterator *ghi) { + return !ghi->curEntry; +} + +/***/ + unsigned int BLI_ghashutil_ptrhash(void *key) { return (unsigned int) key; } |