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:
authorHoward Trickey <howard.trickey@gmail.com>2011-09-06 17:48:20 +0400
committerHoward Trickey <howard.trickey@gmail.com>2011-09-06 17:48:20 +0400
commit7cf87f7e32bc16be972ad3b9203e5823a933359b (patch)
treee2c9233fbfef17cfe5813f198a687f7a89e98c6b /source/blender/blenlib/BLI_smallhash.h
parentd44982508ed3276aa46fef3a624b76ab033bd077 (diff)
Fix BLI_smallhash for 0 and negative keys. Fixes some problems with edge snapping in knife tool.
Diffstat (limited to 'source/blender/blenlib/BLI_smallhash.h')
-rwxr-xr-xsource/blender/blenlib/BLI_smallhash.h27
1 files changed, 14 insertions, 13 deletions
diff --git a/source/blender/blenlib/BLI_smallhash.h b/source/blender/blenlib/BLI_smallhash.h
index c4711204b8a..2fafda9b2b8 100755
--- a/source/blender/blenlib/BLI_smallhash.h
+++ b/source/blender/blenlib/BLI_smallhash.h
@@ -100,8 +100,6 @@ BM_INLINE void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item)
{
int h, hoff=1;
- /* key = ABS(key); BMESH_TODO: XXXXX this throws error with MSVC (warning as error) */
-
if (hash->size < hash->used*3) {
int newsize = hashsizes[++hash->curhash];
entry *tmp;
@@ -126,7 +124,8 @@ BM_INLINE void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item)
if (ELEM(tmp[i].val, CELL_UNUSED, CELL_FREE))
continue;
- h = tmp[i].key; hoff = 1;
+ h = ABS((int)(tmp[i].key));
+ hoff = 1;
while (!ELEM(hash->table[h % newsize].val, CELL_UNUSED, CELL_FREE))
h = HASHNEXT(h, hoff);
@@ -141,7 +140,8 @@ BM_INLINE void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item)
}
}
- h = key; hoff = 1;
+ h = ABS((int)key);
+ hoff = 1;
while (!ELEM(hash->table[h % hash->size].val, CELL_UNUSED, CELL_FREE))
h = HASHNEXT(h, hoff);
@@ -156,8 +156,7 @@ BM_INLINE void BLI_smallhash_remove(SmallHash *hash, uintptr_t key)
{
int h, hoff=1;
- /* key = ABS(key); BMESH_TODO: XXXXX this throws error with MSVC (warning as error) */
- h = key;
+ h = ABS((int)key);
while (hash->table[h % hash->size].key != key
|| hash->table[h % hash->size].val == CELL_UNUSED)
@@ -175,9 +174,9 @@ BM_INLINE void BLI_smallhash_remove(SmallHash *hash, uintptr_t key)
BM_INLINE void *BLI_smallhash_lookup(SmallHash *hash, uintptr_t key)
{
int h, hoff=1;
+ void *v;
- /* key = ABS(key); BMESH_TODO: XXXXX this throws error with MSVC (warning as error) */
- h = key;
+ h = ABS((int)key);
if (!hash->table)
return NULL;
@@ -190,15 +189,17 @@ BM_INLINE void *BLI_smallhash_lookup(SmallHash *hash, uintptr_t key)
h = HASHNEXT(h, hoff);
}
- return hash->table[h % hash->size].val;
+ v = hash->table[h % hash->size].val;
+ if (ELEM(v, CELL_UNUSED, CELL_FREE))
+ return NULL;
+ return v;
}
BM_INLINE int BLI_smallhash_haskey(SmallHash *hash, uintptr_t key)
{
- int h = key, hoff=1;
- h = ABS(h);
- /* key = ABS(key); BMESH_TODO: XXXXX this throws error with MSVC (warning as error) */
+ int h = ABS((int)key);
+ int hoff =1;
if (!hash->table)
return 0;
@@ -211,7 +212,7 @@ BM_INLINE int BLI_smallhash_haskey(SmallHash *hash, uintptr_t key)
h = HASHNEXT(h, hoff);
}
- return 1;
+ return !ELEM(hash->table[h % hash->size].val, CELL_UNUSED, CELL_FREE);
}
BM_INLINE int BLI_smallhash_count(SmallHash *hash)