From ac49d2b7b9c4bb8d4e0fc07dd308f8bd38eaea9b Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 14 Nov 2014 12:34:06 +0100 Subject: Use new BLI_hash_mm2a. --- source/blender/bmesh/intern/bmesh_queries.c | 95 +++-------------------------- 1 file changed, 10 insertions(+), 85 deletions(-) diff --git a/source/blender/bmesh/intern/bmesh_queries.c b/source/blender/bmesh/intern/bmesh_queries.c index aa5ebbe15e5..64df3af8643 100644 --- a/source/blender/bmesh/intern/bmesh_queries.c +++ b/source/blender/bmesh/intern/bmesh_queries.c @@ -35,6 +35,7 @@ #include "BLI_math.h" #include "BLI_alloca.h" +#include "BLI_hash_mm2a.h" #include "BLI_linklist.h" #include "BLI_stackdefines.h" @@ -2350,83 +2351,6 @@ int BM_mesh_calc_edge_groups(BMesh *bm, int *r_groups_array, int (**r_group_inde return group_curr; } -/* TOPO hashing helpers. */ -/* murmur2A hashing func. */ -/* TODO: should go into BLI! */ - -#define MM2A_M 0x5bd1e995 - -#define MM2A_MIX(h, k) \ -{ \ - (k) *= MM2A_M; \ - (k) ^= (k) >> 24; \ - (k) *= MM2A_M; \ - (h) *= ((h) * MM2A_M) ^ (k); \ -} (void)0 - -typedef struct Murmur2A { - uint32_t hash; - uint32_t tail; - uint32_t count; - uint32_t size; -} Murmur2A; - -static void mm2a_mix_tail(Murmur2A *mm2, const unsigned char *data, size_t len) -{ - while (len && ((len < 4) || mm2->count)) { - mm2->tail |= *(uint32_t *)(data++) << (mm2->count * 8); - - mm2->count++; - len--; - - if (mm2->count == 4) { - MM2A_MIX(mm2->hash, mm2->tail); - mm2->tail = 0; - mm2->count = 0; - } - } -} - -static void mm2a_init(Murmur2A *mm2, uint32_t seed) -{ - mm2->hash = seed; - mm2->tail = 0; - mm2->count = 0; - mm2->size = 0; -} - -static void mm2a_add(Murmur2A *mm2, const unsigned char *data, size_t len) -{ - mm2->size += (uint32_t)len; - - mm2a_mix_tail(mm2, data, len); - - for (; len >= 4; data += 4, len -= 4) { - uint32_t k = *(uint32_t *)data; - - MM2A_MIX(mm2->hash, k); - } - - mm2a_mix_tail(mm2, data, len); -} - -static void mm2a_add_int(Murmur2A *mm2, int data) -{ - mm2a_add(mm2, (const unsigned char *)&data, sizeof(data)); -} - -static uint32_t mm2a_end(Murmur2A *mm2) -{ - MM2A_MIX(mm2->hash, mm2->tail); - MM2A_MIX(mm2->hash, mm2->size); - - mm2->hash ^= mm2->hash >> 13; - mm2->hash *= MM2A_M; - mm2->hash ^= mm2->hash >> 15; - - return mm2->hash; -} - /** * Calculate a hash of current topology. * @@ -2442,7 +2366,7 @@ unsigned int BM_mesh_topology_hash(BMesh *bm) BMLoop *l; BMFace *f; - Murmur2A mm2; + BLI_HashMurmur2A mm2; unsigned int seed = (unsigned int)(bm->totvert + bm->totedge + bm->totloop + bm->totface); @@ -2459,29 +2383,30 @@ unsigned int BM_mesh_topology_hash(BMesh *bm) BM_mesh_elem_index_ensure(bm, BM_VERT); /* Init the murmur hash. */ - mm2a_init(&mm2, seed); + BLI_hash_mm2a_init(&mm2, seed); /* Compute edge topology, using only vert indices. */ BM_ITER_MESH(e, &iter, bm, BM_EDGES_OF_MESH) { /* Edge topology is fully defined by its two vertices. */ - mm2a_add_int(&mm2, BM_elem_index_get(e->v1)); - mm2a_add_int(&mm2, BM_elem_index_get(e->v2)); + BLI_hash_mm2a_add_int(&mm2, BM_elem_index_get(e->v1)); + BLI_hash_mm2a_add_int(&mm2, BM_elem_index_get(e->v2)); } if (bm->totface == 0) { /* No face (nor loop), we are done. */ - return mm2a_end(&mm2); + return (unsigned int)BLI_hash_mm2a_end(&mm2); } - /* Else, we have to check all faces too - it *is* possible to change topology without affecting edges! */ + /* Else, we have to check all faces too - it *is* possible to change topology + * without affecting edges nor changing numbers of verts/edges/faces/loops! */ BM_ITER_MESH(f, &iter, bm, BM_FACES_OF_MESH) { /* Face topology is fully defined by its vertices and their order in it. */ BM_ITER_ELEM(l, &iter, f, BM_LOOPS_OF_FACE) { - mm2a_add_int(&mm2, BM_elem_index_get(l->v)); + BLI_hash_mm2a_add_int(&mm2, BM_elem_index_get(l->v)); } } - return mm2a_end(&mm2); + return (unsigned int)BLI_hash_mm2a_end(&mm2); } float bmesh_subd_falloff_calc(const int falloff, float val) -- cgit v1.2.3