diff options
author | Andrea Weikert <elubie@gmx.net> | 2005-12-22 01:21:43 +0300 |
---|---|---|
committer | Andrea Weikert <elubie@gmx.net> | 2005-12-22 01:21:43 +0300 |
commit | 80eb4d3b9e851c19638599b1821a083dc5a2f635 (patch) | |
tree | bfb42679c33f19c498d3f682924ffc3e40a5d482 /source/blender/blenlib | |
parent | 15766e1612040c41ed66fe618af1d28ab3c6d1ec (diff) |
Big commit in orange: Interface icons for materials, textures
world and lamp. Also for images in pupmenus.
Also preparation for work on using preview images in imagebrowser.
-- Andrea
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_ghash.h | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_ghash.c | 55 |
2 files changed, 59 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_ghash.h b/source/blender/blenlib/BLI_ghash.h index d2f2bcc95e4..ce5be5fc311 100644 --- a/source/blender/blenlib/BLI_ghash.h +++ b/source/blender/blenlib/BLI_ghash.h @@ -48,6 +48,7 @@ GHash* BLI_ghash_new (GHashHashFP hashfp, GHashCmpFP cmpfp); void BLI_ghash_free (GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp); void BLI_ghash_insert (GHash *gh, void *key, void *val); +int BLI_ghash_remove (GHash *gh, void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp); void* BLI_ghash_lookup (GHash *gh, void *key); int BLI_ghash_haskey (GHash *gh, void *key); @@ -110,5 +111,8 @@ int BLI_ghashutil_ptrcmp (void *a, void *b); unsigned int BLI_ghashutil_strhash (void *key); int BLI_ghashutil_strcmp (void *a, void *b); +unsigned int BLI_ghashutil_inthash (void *ptr); +int BLI_ghashutil_intcmp(void *a, void *b); + #endif diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index 23e21d4fb45..bc0f79d2cc4 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -128,6 +128,34 @@ void* BLI_ghash_lookup(GHash *gh, void *key) { return NULL; } +int BLI_ghash_remove (GHash *gh, void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp) +{ + unsigned int hash= gh->hashfp(key)%gh->nbuckets; + Entry *e; + Entry *p = 0; + + for (e= gh->buckets[hash]; e; e= e->next) { + if (gh->cmpfp(key, e->key)==0) { + Entry *n= e->next; + + if (keyfreefp) keyfreefp(e->key); + if (valfreefp) valfreefp(e->val); + free(e); + + + e= n; + if (p) + p->next = n; + else + gh->buckets[hash] = n; + return 1; + } + p = e; + } + + return 0; +} + int BLI_ghash_haskey(GHash *gh, void *key) { unsigned int hash= gh->hashfp(key)%gh->nbuckets; Entry *e; @@ -161,6 +189,9 @@ void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreef } free(gh->buckets); + gh->buckets = 0; + gh->nentries = 0; + gh->nbuckets = 0; MEM_freeN(gh); } @@ -223,6 +254,30 @@ int BLI_ghashutil_ptrcmp(void *a, void *b) { return (a<b)?-1:1; } +unsigned int BLI_ghashutil_inthash(void *ptr) { +#if defined(_WIN64) + unsigned __int64 key = (unsigned __int64)ptr; +#else + unsigned long key = (unsigned long)ptr; +#endif + + key += ~(key << 16); + key ^= (key >> 5); + key += (key << 3); + key ^= (key >> 13); + key += ~(key << 9); + key ^= (key >> 17); + + return (unsigned int)(key & 0xffffffff); +} + +int BLI_ghashutil_intcmp(void *a, void *b) { + if (a==b) + return 0; + else + return (a<b)?-1:1; +} + unsigned int BLI_ghashutil_strhash(void *ptr) { char *s= ptr; unsigned int i= 0; |