Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-08-18 04:36:04 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-08-18 04:36:04 +0400
commitfbb446dff620c0719fd77692a0d401203ef1e966 (patch)
treec95104990f0da56ad6c5cd1d5ca4fb1ac4f277e7 /source/blender/blenlib/intern/BLI_ghash.c
parent763bce4d64eeed978c6e84212da0f9c59ed32a4d (diff)
add assert for hashes if an existing element is ever inserted into a ghash/edgehash.
the outliner does this intentionally, so add a flag to allow this situation optionally.
Diffstat (limited to 'source/blender/blenlib/intern/BLI_ghash.c')
-rw-r--r--source/blender/blenlib/intern/BLI_ghash.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index 14dfbcffebe..50d52a299a7 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -62,6 +62,27 @@ const unsigned int hashsizes[] = {
/***/
+typedef struct Entry {
+ struct Entry *next;
+
+ void *key, *val;
+} Entry;
+
+typedef struct GHash {
+ GHashHashFP hashfp;
+ GHashCmpFP cmpfp;
+
+ Entry **buckets;
+ struct BLI_mempool *entrypool;
+ unsigned int nbuckets;
+ unsigned int nentries;
+ unsigned short cursize, flag;
+} GHash;
+
+
+/* -------------------------------------------------------------------- */
+/* GHash API */
+
GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info)
{
GHash *gh = MEM_mallocN(sizeof(*gh), info);
@@ -88,6 +109,8 @@ void BLI_ghash_insert(GHash *gh, void *key, void *val)
unsigned int hash = gh->hashfp(key) % gh->nbuckets;
Entry *e = (Entry *)BLI_mempool_alloc(gh->entrypool);
+ BLI_assert((gh->flag & GHASH_FLAG_ALLOW_DUPES) || (BLI_ghash_haskey(gh, key) == 0));
+
e->next = gh->buckets[hash];
e->key = key;
e->val = val;
@@ -252,7 +275,19 @@ void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreef
MEM_freeN(gh);
}
-/***/
+void BLI_ghash_flag_set(GHash *gh, unsigned short flag)
+{
+ gh->flag |= flag;
+}
+
+void BLI_ghash_flag_clear(GHash *gh, unsigned short flag)
+{
+ gh->flag &= (unsigned short)~flag;
+}
+
+
+/* -------------------------------------------------------------------- */
+/* GHash Iterator API */
GHashIterator *BLI_ghashIterator_new(GHash *gh)
{