use unsigned int's for smallhash, avoids using ABS when converting an

int from a key.
This commit is contained in:
Campbell Barton
2013-05-08 12:54:07 +00:00
parent 6b1b20ef0d
commit 62db610220
4 changed files with 20 additions and 29 deletions

View File

@@ -49,9 +49,9 @@ typedef struct SmallHash {
SmallHashEntry _stacktable[SMSTACKSIZE];
SmallHashEntry _copytable[SMSTACKSIZE];
SmallHashEntry *stacktable, *copytable;
int used;
int curhash;
int size;
unsigned int used;
unsigned int curhash;
unsigned int size;
} SmallHash;
typedef struct {

View File

@@ -42,7 +42,7 @@
#include "MEM_sys_types.h" /* for intptr_t support */
/***/
unsigned int hashsizes[] = {
const unsigned int hashsizes[] = {
5, 11, 17, 37, 67, 131, 257, 521, 1031, 2053, 4099, 8209,
16411, 32771, 65537, 131101, 262147, 524309, 1048583, 2097169,
4194319, 8388617, 16777259, 33554467, 67108879, 134217757,

View File

@@ -41,7 +41,7 @@
#include "BLI_mempool.h"
/**************inlined code************/
static unsigned int _ehash_hashsizes[] = {
static const unsigned int _ehash_hashsizes[] = {
1, 3, 5, 11, 17, 37, 67, 131, 257, 521, 1031, 2053, 4099, 8209,
16411, 32771, 65537, 131101, 262147, 524309, 1048583, 2097169,
4194319, 8388617, 16777259, 33554467, 67108879, 134217757,

View File

@@ -45,23 +45,14 @@
#ifdef __GNUC__
# pragma GCC diagnostic ignored "-Wstrict-overflow"
# pragma GCC diagnostic error "-Wsign-conversion"
#endif
BLI_INLINE int smhash_nonzero(const int n)
{
return n + !n;
}
BLI_INLINE int smhash_abs_i(const int n)
{
return (n > 0) ? n : -n;
}
/* typically this re-assigns 'h' */
#define SMHASH_NEXT(h, hoff) ( \
CHECK_TYPE_INLINE(&(h), int), \
CHECK_TYPE_INLINE(&(hoff), int), \
smhash_abs_i((h) + (((hoff) = smhash_nonzero((hoff) * 2) + 1), (hoff))) \
CHECK_TYPE_INLINE(&(h), unsigned int), \
CHECK_TYPE_INLINE(&(hoff), unsigned int), \
((h) + (((hoff) = ((hoff) * 2) + 1), (hoff))) \
)
extern unsigned int hashsizes[];
@@ -94,10 +85,10 @@ void BLI_smallhash_release(SmallHash *hash)
void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item)
{
int h, hoff = 1;
unsigned int h, hoff = 1;
if (hash->size < hash->used * 3) {
int newsize = hashsizes[++hash->curhash];
unsigned int newsize = hashsizes[++hash->curhash];
SmallHashEntry *tmp;
int i = 0;
@@ -122,7 +113,7 @@ void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item)
continue;
}
h = ABS((int)(tmp[i].key));
h = (unsigned int)(tmp[i].key);
hoff = 1;
while (!ELEM(hash->table[h % newsize].val, SMHASH_CELL_UNUSED, SMHASH_CELL_FREE)) {
h = SMHASH_NEXT(h, hoff);
@@ -139,7 +130,7 @@ void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item)
}
}
h = ABS((int)key);
h = (unsigned int)(key);
hoff = 1;
while (!ELEM(hash->table[h % hash->size].val, SMHASH_CELL_UNUSED, SMHASH_CELL_FREE)) {
@@ -155,9 +146,9 @@ void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item)
void BLI_smallhash_remove(SmallHash *hash, uintptr_t key)
{
int h, hoff = 1;
unsigned int h, hoff = 1;
h = ABS((int)key);
h = (unsigned int)(key);
while ((hash->table[h % hash->size].key != key) ||
(hash->table[h % hash->size].val == SMHASH_CELL_UNUSED))
@@ -176,10 +167,10 @@ void BLI_smallhash_remove(SmallHash *hash, uintptr_t key)
void *BLI_smallhash_lookup(SmallHash *hash, uintptr_t key)
{
int h, hoff = 1;
unsigned int h, hoff = 1;
void *v;
h = ABS((int)key);
h = (unsigned int)(key);
while ((hash->table[h % hash->size].key != key) ||
(hash->table[h % hash->size].val == SMHASH_CELL_UNUSED))
@@ -202,8 +193,8 @@ void *BLI_smallhash_lookup(SmallHash *hash, uintptr_t key)
int BLI_smallhash_haskey(SmallHash *hash, uintptr_t key)
{
int h = ABS((int)key);
int hoff = 1;
unsigned int h = (unsigned int)(key);
unsigned int hoff = 1;
while ((hash->table[h % hash->size].key != key) ||
(hash->table[h % hash->size].val == SMHASH_CELL_UNUSED))
@@ -220,7 +211,7 @@ int BLI_smallhash_haskey(SmallHash *hash, uintptr_t key)
int BLI_smallhash_count(SmallHash *hash)
{
return hash->used;
return (int)hash->used;
}
void *BLI_smallhash_iternext(SmallHashIter *iter, uintptr_t *key)