diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-04-15 08:17:54 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-04-15 08:22:36 +0400 |
commit | a7241d09cdd204a63e10a6e53c575f36639a3102 (patch) | |
tree | a436fbac1010ece84d9d15c617d5be3728469133 /source/blender/blenlib/BLI_ghash.h | |
parent | ea610e655cd8b8f9fb97f0a9a4fc5fd46418bd9e (diff) |
GHash: add typed hash functions (were all (void *))
- BLI_ghashutil_strhash_n takes string length, to avoid terminating the string before hashing.
- BLI_ghashutil_inthash/uinthash take ints, to avoid casting to (void *)
This also showed up incorrect use of inthash, which was using a pointer.
Diffstat (limited to 'source/blender/blenlib/BLI_ghash.h')
-rw-r--r-- | source/blender/blenlib/BLI_ghash.h | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/source/blender/blenlib/BLI_ghash.h b/source/blender/blenlib/BLI_ghash.h index 61a75ebb7e8..1e51bd9afea 100644 --- a/source/blender/blenlib/BLI_ghash.h +++ b/source/blender/blenlib/BLI_ghash.h @@ -112,17 +112,31 @@ BLI_INLINE bool BLI_ghashIterator_done(GHashIterator *ghi) { return !ghi BLI_ghashIterator_done(&gh_iter_) == false; \ BLI_ghashIterator_step(&gh_iter_), i_++) -/* *** */ +/** \name Callbacks for GHash + * + * \note '_p' suffix denotes void pointer arg, + * so we can have functions that take correctly typed args too. + * \{ */ unsigned int BLI_ghashutil_ptrhash(const void *key); int BLI_ghashutil_ptrcmp(const void *a, const void *b); -unsigned int BLI_ghashutil_strhash(const void *key); +unsigned int BLI_ghashutil_strhash_n(const char *key, size_t n); +#define BLI_ghashutil_strhash(key) ( \ + CHECK_TYPE_INLINE(key, char *), \ + BLI_ghashutil_strhash_p(key)) +unsigned int BLI_ghashutil_strhash_p(const void *key); int BLI_ghashutil_strcmp(const void *a, const void *b); -unsigned int BLI_ghashutil_inthash(const void *ptr); +#define BLI_ghashutil_inthash(key) ( \ + CHECK_TYPE_INLINE(key, int), \ + BLI_ghashutil_uinthash((unsigned int)key)) +unsigned int BLI_ghashutil_uinthash(unsigned int key); +unsigned int BLI_ghashutil_inthash_p(const void *ptr); int BLI_ghashutil_intcmp(const void *a, const void *b); +/** \} */ + GHash *BLI_ghash_ptr_new_ex(const char *info, const unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT; GHash *BLI_ghash_ptr_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT; |