diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-01-30 13:51:44 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-01-30 14:10:55 +0400 |
commit | 1f64371ec036c2f6ab450e37ad5a9c1120f1c54f (patch) | |
tree | cf0d1a02880244407d25b267a8ce4920572f1454 /source/blender/blenlib/BLI_smallhash.h | |
parent | ab6157a06ab49fc1f78f1575d373c83037cd39b7 (diff) |
Smallhash: refactor and fixes
- BLI_smallhash_remove didnt decrement total entries.
- rename vars to match closer to ghash.
- smallhash_lookup returns NULL when no entry found.
- using a zero value key wasn't supported.
- no need to memset or calloc bucket arrays
- add asserts for unsupported conditions.
- added BLI_smallhash_lookup_p
Diffstat (limited to 'source/blender/blenlib/BLI_smallhash.h')
-rw-r--r-- | source/blender/blenlib/BLI_smallhash.h | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/source/blender/blenlib/BLI_smallhash.h b/source/blender/blenlib/BLI_smallhash.h index ec7b27f6651..07bd9975467 100644 --- a/source/blender/blenlib/BLI_smallhash.h +++ b/source/blender/blenlib/BLI_smallhash.h @@ -42,29 +42,31 @@ typedef struct { /*how much stack space to use before dynamically allocating memory*/ #define SMSTACKSIZE 64 typedef struct SmallHash { - SmallHashEntry *table; - SmallHashEntry _stacktable[SMSTACKSIZE]; - SmallHashEntry _copytable[SMSTACKSIZE]; - SmallHashEntry *stacktable, *copytable; - unsigned int used; - unsigned int curhash; - unsigned int size; + SmallHashEntry *buckets; + SmallHashEntry *buckets_stack; + SmallHashEntry *buckets_copy; + SmallHashEntry _buckets_stack[SMSTACKSIZE]; + SmallHashEntry _buckets_copy[SMSTACKSIZE]; + unsigned int nbuckets; + unsigned int nentries; + unsigned int cursize; } SmallHash; typedef struct { - SmallHash *hash; + SmallHash *sh; unsigned int i; } SmallHashIter; -void BLI_smallhash_init(SmallHash *hash) ATTR_NONNULL(1); -void BLI_smallhash_release(SmallHash *hash) ATTR_NONNULL(1); -void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item) ATTR_NONNULL(1); -void BLI_smallhash_remove(SmallHash *hash, uintptr_t key) ATTR_NONNULL(1); -void *BLI_smallhash_lookup(SmallHash *hash, uintptr_t key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; -bool BLI_smallhash_haskey(SmallHash *hash, uintptr_t key) ATTR_NONNULL(1); -int BLI_smallhash_count(SmallHash *hash) ATTR_NONNULL(1); +void BLI_smallhash_init(SmallHash *sh) ATTR_NONNULL(1); +void BLI_smallhash_release(SmallHash *sh) ATTR_NONNULL(1); +void BLI_smallhash_insert(SmallHash *sh, uintptr_t key, void *item) ATTR_NONNULL(1); +bool BLI_smallhash_remove(SmallHash *sh, uintptr_t key) ATTR_NONNULL(1); +void *BLI_smallhash_lookup(SmallHash *sh, uintptr_t key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; +void **BLI_smallhash_lookup_p(SmallHash *sh, uintptr_t key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; +bool BLI_smallhash_haskey(SmallHash *sh, uintptr_t key) ATTR_NONNULL(1); +int BLI_smallhash_count(SmallHash *sh) ATTR_NONNULL(1); void *BLI_smallhash_iternext(SmallHashIter *iter, uintptr_t *key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; -void *BLI_smallhash_iternew(SmallHash *hash, SmallHashIter *iter, uintptr_t *key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; -/* void BLI_smallhash_print(SmallHash *hash); */ /* UNUSED */ +void *BLI_smallhash_iternew(SmallHash *sh, SmallHashIter *iter, uintptr_t *key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; +/* void BLI_smallhash_print(SmallHash *sh); */ /* UNUSED */ #endif /* __BLI_SMALLHASH_H__ */ |