|
|
|
|
@@ -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)
|
|
|
|
|
|