[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40053] branches/bmesh/blender/source/ blender: move smallhash into its own C file, was inlineing fairly large functions.

Campbell Barton ideasman42 at gmail.com
Fri Sep 9 04:52:21 CEST 2011


Revision: 40053
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40053
Author:   campbellbarton
Date:     2011-09-09 02:52:20 +0000 (Fri, 09 Sep 2011)
Log Message:
-----------
move smallhash into its own C file, was inlineing fairly large functions.

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/blenlib/BLI_smallhash.h
    branches/bmesh/blender/source/blender/blenlib/CMakeLists.txt
    branches/bmesh/blender/source/blender/editors/mesh/knifetool.c
    branches/bmesh/blender/source/blender/modifiers/intern/MOD_mirror.c

Modified: branches/bmesh/blender/source/blender/blenlib/BLI_smallhash.h
===================================================================
--- branches/bmesh/blender/source/blender/blenlib/BLI_smallhash.h	2011-09-09 02:29:44 UTC (rev 40052)
+++ branches/bmesh/blender/source/blender/blenlib/BLI_smallhash.h	2011-09-09 02:52:20 UTC (rev 40053)
@@ -28,15 +28,14 @@
 #ifndef BLI_SMALLHASH_H
 #define BLI_SMALLHASH_H
 
-/*******a light stack-friendly hash library******
- *      (it uses stack space for smallish hash tables)     */
+/** \file BLI_smallhash.h
+ *  \ingroup bli
+ */
 
-/*based on a doubling non-chaining approach */
+/* a light stack-friendly hash library,
+ * (it uses stack space for smallish hash tables) */
 
-#include "MEM_guardedalloc.h"
-#include "BLO_sys_types.h"
-#include "BLI_utildefines.h"
-#include <string.h>
+/* based on a doubling non-chaining approach */
 
 extern unsigned int hashsizes[];
 #define NONHASH	-25436536
@@ -57,192 +56,15 @@
 	int i;
 } SmallHashIter;
 
-/*CELL_UNUSED means this cell is inside a key series, while CELL_FREE
-  means this cell terminates a key series.
-  
-  no chance of anyone shoving INT32_MAX-2 into a *val pointer, I
-  imagine.  hopefully. */
-#define CELL_UNUSED	((void*)0x7FFFFFFF)
-#define CELL_FREE	((void*)0x7FFFFFFD)
+void	BLI_smallhash_init(SmallHash *hash);
+void	BLI_smallhash_release(SmallHash *hash);
+void	BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item);
+void	BLI_smallhash_remove(SmallHash *hash, uintptr_t key);
+void *	BLI_smallhash_lookup(SmallHash *hash, uintptr_t key);
+int		BLI_smallhash_haskey(SmallHash *hash, uintptr_t key);
+int		BLI_smallhash_count(SmallHash *hash);
+void *	BLI_smallhash_iternext(SmallHashIter *iter, uintptr_t *key);
+void *	BLI_smallhash_iternew(SmallHash *hash, SmallHashIter *iter, uintptr_t *key);
+/* void BLI_smallhash_print(SmallHash *hash); */ /* UNUSED */
 
-#define NONZERO(n) ((n) + !(n))
-#define HASHNEXT(h, hoff) ABS(((h) + ((hoff=NONZERO(hoff*2)+1), hoff)))
-
-BM_INLINE void BLI_smallhash_init(SmallHash *hash)
-{
-	int i;
-	
-	memset(hash, 0, sizeof(*hash));
-	
-	hash->table = hash->_stacktable;
-	hash->curhash = 2;
-	hash->size = hashsizes[hash->curhash];
-	
-	hash->copytable = hash->_copytable;
-	hash->stacktable = hash->_stacktable;
-	
-	for (i=0; i<hash->size; i++) {
-		hash->table[i].val = CELL_FREE;
-	}
-}
-
-/*NOTE: does *not* free *hash itself!  only the direct data!*/
-BM_INLINE void BLI_smallhash_release(SmallHash *hash)
-{
-	if (!hash)
-		return;
-	
-	if (hash->table != hash->stacktable)
-		MEM_freeN(hash->table);
-}
-
-BM_INLINE void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item) 
-{
-	int h, hoff=1;
-
-	if (hash->size < hash->used*3) {
-		int newsize = hashsizes[++hash->curhash];
-		entry *tmp;
-		int i = 0;
-		
-		if (hash->table != hash->stacktable || newsize > SMSTACKSIZE) {
-			tmp = MEM_callocN(sizeof(*hash->table)*newsize, "new hashkeys");
-		} else {
-			SWAP(entry*, hash->stacktable, hash->copytable);
-			tmp = hash->stacktable;
-		}
-		
-		SWAP(entry*, tmp, hash->table);
-		
-		hash->size = newsize;
-		
-		for (i=0; i<hash->size; i++) {
-			hash->table[i].val = CELL_FREE;
-		}
-		
-		for (i=0; i<hashsizes[hash->curhash-1]; i++) {
-			if (ELEM(tmp[i].val, CELL_UNUSED, CELL_FREE))
-				continue;
-			
-			h = ABS((int)(tmp[i].key));
-			hoff = 1;
-			while (!ELEM(hash->table[h % newsize].val, CELL_UNUSED, CELL_FREE))
-				h = HASHNEXT(h, hoff);
-			
-			h %= newsize;
-			
-			hash->table[h].key = tmp[i].key;
-			hash->table[h].val = tmp[i].val;
-		}
-		
-		if (tmp != hash->stacktable && tmp != hash->copytable) {
-			MEM_freeN(tmp);
-		}
-	}
-	
-	h = ABS((int)key);
-	hoff = 1;
-	while (!ELEM(hash->table[h % hash->size].val, CELL_UNUSED, CELL_FREE))
-		h = HASHNEXT(h, hoff);
-	
-	h %= hash->size;
-	hash->table[h].key = key;
-	hash->table[h].val = item;
-	
-	hash->used++;
-}
-
-BM_INLINE void BLI_smallhash_remove(SmallHash *hash, uintptr_t key)
-{
-	int h, hoff=1;
-
-	h = ABS((int)key);
-	
-	while (hash->table[h % hash->size].key != key 
-	      || hash->table[h % hash->size].val == CELL_UNUSED)
-	{
-		if (hash->table[h % hash->size].val == CELL_FREE)
-			return;
-		h = HASHNEXT(h, hoff);
-	}
-	
-	h %= hash->size;
-	hash->table[h].key = 0;
-	hash->table[h].val = CELL_UNUSED;
-}
-
-BM_INLINE void *BLI_smallhash_lookup(SmallHash *hash, uintptr_t key)
-{
-	int h, hoff=1;
-	void *v;
-
-	h = ABS((int)key);
-	
-	if (!hash->table)
-		return NULL;
-	
-	while (hash->table[h % hash->size].key != key 
-	      || hash->table[h % hash->size].val == CELL_UNUSED)
-	{
-		if (hash->table[h % hash->size].val == CELL_FREE)
-			return NULL;
-		h = HASHNEXT(h, hoff);
-	}
-	
-	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 = ABS((int)key);
-	int hoff =1;
-	
-	if (!hash->table)
-		return 0;
-	
-	while (hash->table[h % hash->size].key != key 
-	      || hash->table[h % hash->size].val == CELL_UNUSED)
-	{
-		if (hash->table[h % hash->size].val == CELL_FREE)
-			return 0;
-		h = HASHNEXT(h, hoff);
-	}
-	
-	return !ELEM(hash->table[h % hash->size].val, CELL_UNUSED, CELL_FREE);
-}
-
-BM_INLINE int BLI_smallhash_count(SmallHash *hash)
-{
-	return hash->used;
-}
-
-BM_INLINE void *BLI_smallhash_iternext(SmallHashIter *iter, uintptr_t *key)
-{
-	while (iter->i < iter->hash->size) {
-		if (iter->hash->table[iter->i].val != CELL_UNUSED && iter->hash->table[iter->i].val != CELL_FREE) {
-			if (key)
-				*key = iter->hash->table[iter->i].key;
-			
-			iter->i++;
-			return iter->hash->table[iter->i-1].val;
-		}
-		
-		iter->i++;
-	}
-	
-	return NULL;
-}
-
-BM_INLINE void *BLI_smallhash_iternew(SmallHash *hash, SmallHashIter *iter, uintptr_t *key) 
-{
-	iter->hash = hash;
-	iter->i = 0;
-	
-	return BLI_smallhash_iternext(iter, key);
-}
-
 #endif // BLI_SMALLHASH_H

Modified: branches/bmesh/blender/source/blender/blenlib/CMakeLists.txt
===================================================================
--- branches/bmesh/blender/source/blender/blenlib/CMakeLists.txt	2011-09-09 02:29:44 UTC (rev 40052)
+++ branches/bmesh/blender/source/blender/blenlib/CMakeLists.txt	2011-09-09 02:52:20 UTC (rev 40053)
@@ -79,6 +79,7 @@
 	intern/rand.c
 	intern/rct.c
 	intern/scanfill.c
+	intern/smallhash.c
 	intern/storage.c
 	intern/string.c
 	intern/threads.c

Modified: branches/bmesh/blender/source/blender/editors/mesh/knifetool.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/mesh/knifetool.c	2011-09-09 02:29:44 UTC (rev 40052)
+++ branches/bmesh/blender/source/blender/editors/mesh/knifetool.c	2011-09-09 02:52:20 UTC (rev 40053)
@@ -745,34 +745,6 @@
 	glEnable(GL_DEPTH_TEST);
 }
 
-static void _print_smhash(SmallHash *hash)
-{
-	int i, linecol=79, c=0;
-	
-	printf("{");
-	for (i=0; i<hash->size; i++) {
-		if (hash->table[i].val == CELL_UNUSED) {
-			printf("--u-");
-		} else if (hash->table[i].val == CELL_FREE) {
-			printf("--f-");
-		} else	{
-			printf("%2x", (unsigned int)hash->table[i].key);
-		}
-		
-		if (i != hash->size-1)
-			printf(", ");
-		
-		c += 6;
-		
-		if (c >= linecol) {
-			printf("\n ");
-			c = 0;
-		}
-	}
-	
-	fflush(stdout);
-}
-
 static int kfe_vert_in_edge(KnifeEdge *e, KnifeVert *v) {
 	return e->v1 == v || e->v2 == v;
 }

Modified: branches/bmesh/blender/source/blender/modifiers/intern/MOD_mirror.c
===================================================================
--- branches/bmesh/blender/source/blender/modifiers/intern/MOD_mirror.c	2011-09-09 02:29:44 UTC (rev 40052)
+++ branches/bmesh/blender/source/blender/modifiers/intern/MOD_mirror.c	2011-09-09 02:52:20 UTC (rev 40053)
@@ -33,6 +33,8 @@
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
 
+#include "MEM_guardedalloc.h"
+
 #include "BLI_math.h"
 #include "BLI_smallhash.h"
 #include "BLI_array.h"
@@ -44,7 +46,6 @@
 #include "BKE_utildefines.h"
 #include "BKE_tessmesh.h"
 
-#include "MEM_guardedalloc.h"
 #include "depsgraph_private.h"
 
 static void initData(ModifierData *md)




More information about the Bf-blender-cvs mailing list