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
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.
-rw-r--r--source/blender/blenlib/BLI_edgehash.h7
-rw-r--r--source/blender/blenlib/BLI_ghash.h22
-rw-r--r--source/blender/blenlib/intern/BLI_ghash.c37
-rw-r--r--source/blender/blenlib/intern/edgehash.c15
-rw-r--r--source/blender/editors/space_outliner/outliner_tree.c1
-rw-r--r--source/blender/makesdna/DNA_space_types.h2
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;