[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39968] branches/bmesh/blender/source/ blender/blenlib/BLI_smallhash.h: Fix BLI_smallhash for 0 and negative keys.

Howard Trickey howard.trickey at gmail.com
Tue Sep 6 15:48:20 CEST 2011


Revision: 39968
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39968
Author:   howardt
Date:     2011-09-06 13:48:20 +0000 (Tue, 06 Sep 2011)
Log Message:
-----------
Fix BLI_smallhash for 0 and negative keys.  Fixes some problems with edge snapping in knife tool.

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/blenlib/BLI_smallhash.h

Modified: branches/bmesh/blender/source/blender/blenlib/BLI_smallhash.h
===================================================================
--- branches/bmesh/blender/source/blender/blenlib/BLI_smallhash.h	2011-09-06 13:00:46 UTC (rev 39967)
+++ branches/bmesh/blender/source/blender/blenlib/BLI_smallhash.h	2011-09-06 13:48:20 UTC (rev 39968)
@@ -100,8 +100,6 @@
 {
 	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 @@
 			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 @@
 		}
 	}
 	
-	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 @@
 {
 	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_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 @@
 		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 @@
 		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)




More information about the Bf-blender-cvs mailing list