diff options
-rw-r--r-- | source/blender/blenlib/BLI_edgehash.h | 7 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_ghash.h | 22 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_ghash.c | 37 | ||||
-rw-r--r-- | source/blender/blenlib/intern/edgehash.c | 15 | ||||
-rw-r--r-- | source/blender/editors/space_outliner/outliner_tree.c | 1 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_space_types.h | 2 |
6 files changed, 66 insertions, 18 deletions
diff --git a/source/blender/blenlib/BLI_edgehash.h b/source/blender/blenlib/BLI_edgehash.h index 9ece3afde37..5d945bb9efc 100644 --- a/source/blender/blenlib/BLI_edgehash.h +++ b/source/blender/blenlib/BLI_edgehash.h @@ -36,6 +36,10 @@ typedef struct EdgeHashIterator EdgeHashIterator; typedef void (*EdgeHashFreeFP)(void *key); +enum { + EDGEHASH_FLAG_ALLOW_DUPES = (1 << 0), /* only checked for in debug mode */ +}; + EdgeHash *BLI_edgehash_new(void); void BLI_edgehash_free(EdgeHash *eh, EdgeHashFreeFP valfreefp); @@ -65,6 +69,9 @@ int BLI_edgehash_size(EdgeHash *eh); /* Remove all edges from hash. */ void BLI_edgehash_clear(EdgeHash *eh, EdgeHashFreeFP valfreefp); +void BLI_edgehash_flag_set(EdgeHash *eh, unsigned short flag); +void BLI_edgehash_flag_clear(EdgeHash *eh, unsigned short flag); + /***/ /** diff --git a/source/blender/blenlib/BLI_ghash.h b/source/blender/blenlib/BLI_ghash.h index 3ad0e18c8d7..d914c32664d 100644 --- a/source/blender/blenlib/BLI_ghash.h +++ b/source/blender/blenlib/BLI_ghash.h @@ -42,21 +42,7 @@ typedef int (*GHashCmpFP) (const void *a, const void *b); typedef void (*GHashKeyFreeFP) (void *key); typedef void (*GHashValFreeFP) (void *val); -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, cursize; -} GHash; +typedef struct GHash GHash; typedef struct GHashIterator { GHash *gh; @@ -64,6 +50,10 @@ typedef struct GHashIterator { struct Entry *curEntry; } GHashIterator; +enum { + GHASH_FLAG_ALLOW_DUPES = (1 << 0), /* only checked for in debug mode */ +}; + /* *** */ GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info); @@ -75,6 +65,8 @@ void BLI_ghash_clear(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfr void *BLI_ghash_pop(GHash *gh, void *key, GHashKeyFreeFP keyfreefp); bool BLI_ghash_haskey(GHash *gh, const void *key); int BLI_ghash_size(GHash *gh); +void BLI_ghash_flag_set(GHash *gh, unsigned short flag); +void BLI_ghash_flag_clear(GHash *gh, unsigned short flag); /* *** */ 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) { diff --git a/source/blender/blenlib/intern/edgehash.c b/source/blender/blenlib/intern/edgehash.c index a3360921ee4..d3ce9bb4857 100644 --- a/source/blender/blenlib/intern/edgehash.c +++ b/source/blender/blenlib/intern/edgehash.c @@ -76,7 +76,8 @@ struct EdgeEntry { struct EdgeHash { EdgeEntry **buckets; BLI_mempool *epool; - unsigned int nbuckets, nentries, cursize; + unsigned int nbuckets, nentries; + unsigned short cursize, flag; }; /***/ @@ -100,6 +101,8 @@ void BLI_edgehash_insert(EdgeHash *eh, unsigned int v0, unsigned int v1, void *v unsigned int hash; EdgeEntry *e = BLI_mempool_alloc(eh->epool); + BLI_assert((eh->flag & EDGEHASH_FLAG_ALLOW_DUPES) || (BLI_edgehash_haskey(eh, v0, v1) == 0)); + /* this helps to track down errors with bad edge data */ BLI_assert(v0 != v1); @@ -199,6 +202,16 @@ void BLI_edgehash_free(EdgeHash *eh, EdgeHashFreeFP valfreefp) } +void BLI_edgehash_flag_set(EdgeHash *eh, unsigned short flag) +{ + eh->flag |= flag; +} + +void BLI_edgehash_flag_clear(EdgeHash *eh, unsigned short flag) +{ + eh->flag &= (unsigned short)~flag; +} + /***/ struct EdgeHashIterator { diff --git a/source/blender/editors/space_outliner/outliner_tree.c b/source/blender/editors/space_outliner/outliner_tree.c index af870f3ca5d..404821900df 100644 --- a/source/blender/editors/space_outliner/outliner_tree.c +++ b/source/blender/editors/space_outliner/outliner_tree.c @@ -194,6 +194,7 @@ static void check_persistent(SpaceOops *soops, TreeElement *te, ID *id, short ty } if (soops->treehash == NULL) { soops->treehash = BLI_ghash_new(tse_hash, tse_cmp, "treehash"); + BLI_ghash_flag_set(soops->treehash, GHASH_FLAG_ALLOW_DUPES); } if (restore_treehash) { diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h index c562a1fefae..85655ce09bd 100644 --- a/source/blender/makesdna/DNA_space_types.h +++ b/source/blender/makesdna/DNA_space_types.h @@ -253,7 +253,7 @@ typedef struct SpaceOops { struct TreeStoreElem search_tse; short flag, outlinevis, storeflag, search_flags; - struct GHash *treehash; + struct GHash *treehash; /* note, allows duplicates */ } SpaceOops; |