GHash: add BLI_ghashutil_uinthash_v4 for hashing 4 ints at once
authorCampbell Barton <ideasman42@gmail.com>
Tue, 15 Apr 2014 04:39:23 +0000 (14:39 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 15 Apr 2014 04:40:33 +0000 (14:40 +1000)
source/blender/blenlib/BLI_ghash.h
source/blender/blenlib/intern/BLI_ghash.c
source/blender/bmesh/tools/bmesh_beautify.c

index 1e51bd9afea64283037603083cfcc97b6519011a..d762876a55a3a0e8025207ccfbb591ab5943d983 100644 (file)
@@ -132,6 +132,12 @@ int             BLI_ghashutil_strcmp(const void *a, const void *b);
                 CHECK_TYPE_INLINE(key, int), \
                 BLI_ghashutil_uinthash((unsigned int)key))
 unsigned int    BLI_ghashutil_uinthash(unsigned int key);
+#define         BLI_ghashutil_inthash_v4(key) ( \
+                CHECK_TYPE_INLINE(key, int *), \
+                BLI_ghashutil_uinthash_v4((const unsigned int *)key))
+unsigned int    BLI_ghashutil_uinthash_v4(const unsigned int key[4]);
+#define         BLI_ghashutil_inthash_v4_p \
+   ((GSetHashFP)BLI_ghashutil_uinthash_v4)
 unsigned int    BLI_ghashutil_inthash_p(const void *ptr);
 int             BLI_ghashutil_intcmp(const void *a, const void *b);
 
index 33a3ba30e4b97184ba232f17133a7a4d1e986a45..4849ef3e9589fc50c7fcb55463448dd82853aba2 100644 (file)
@@ -679,6 +679,19 @@ int BLI_ghashutil_ptrcmp(const void *a, const void *b)
                return (a < b) ? -1 : 1;
 }
 
+unsigned int BLI_ghashutil_uinthash_v4(const unsigned int key[4])
+{
+       unsigned int hash;
+       hash  = key[0];
+       hash *= 37;
+       hash += key[1];
+       hash *= 37;
+       hash += key[2];
+       hash *= 37;
+       hash += key[3];
+       return hash;
+}
+
 unsigned int BLI_ghashutil_uinthash(unsigned int key)
 {
        key += ~(key << 16);
index b19a7d0e9b6a5d6fb061b27b53e5069fef725aef..8223a122e2be36bfdebe038b0ab2c20b56f9303e 100644 (file)
@@ -59,16 +59,14 @@ typedef struct EdRotState {
        int f1, f2; /*  face vert, small -> large */
 } EdRotState;
 
+#if 0
+/* use BLI_ghashutil_inthash_v4 direct */
 static unsigned int erot_gsetutil_hash(const void *ptr)
 {
        const EdRotState *e_state = (const EdRotState *)ptr;
-       unsigned int hash;
-       hash  = BLI_ghashutil_inthash(e_state->v1);
-       hash ^= BLI_ghashutil_inthash(e_state->v2);
-       hash ^= BLI_ghashutil_inthash(e_state->f1);
-       hash ^= BLI_ghashutil_inthash(e_state->f2);
-       return hash;
+       return BLI_ghashutil_inthash_v4(&e_state->v1);
 }
+#endif
 static int erot_gsetutil_cmp(const void *a, const void *b)
 {
        const EdRotState *e_state_a = (const EdRotState *)a;
@@ -86,7 +84,7 @@ static int erot_gsetutil_cmp(const void *a, const void *b)
 
 static GSet *erot_gset_new(void)
 {
-       return BLI_gset_new(erot_gsetutil_hash, erot_gsetutil_cmp, __func__);
+       return BLI_gset_new(BLI_ghashutil_inthash_v4_p, erot_gsetutil_cmp, __func__);
 }
 
 /* ensure v0 is smaller */