diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-08-26 00:03:45 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-08-26 00:03:45 +0400 |
commit | bbce51d11691acc561f1684c20e60613941d4e9b (patch) | |
tree | ada2418ebb181015b561df9e9c92035ee2a84b43 /source/blender/bmesh/operators | |
parent | 1d5eff36f5bd7fc7986e59d4dbe7b885ccb50e61 (diff) |
replace hashes with sets where possible.
Diffstat (limited to 'source/blender/bmesh/operators')
-rw-r--r-- | source/blender/bmesh/operators/bmo_beautify.c | 38 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_hull.c | 36 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_subdivide_edgering.c | 34 |
3 files changed, 54 insertions, 54 deletions
diff --git a/source/blender/bmesh/operators/bmo_beautify.c b/source/blender/bmesh/operators/bmo_beautify.c index 22b686db64e..3dbdb3ddc52 100644 --- a/source/blender/bmesh/operators/bmo_beautify.c +++ b/source/blender/bmesh/operators/bmo_beautify.c @@ -28,7 +28,7 @@ * * In principle this is very simple however there is the possibility of * going into an eternal loop where edges keep rotating. - * To avoid this - each edge stores a hash of it previous + * To avoid this - each edge stores a set of it previous * states so as not to rotate back. * * TODO @@ -54,14 +54,14 @@ enum { }; /* -------------------------------------------------------------------- */ -/* GHash for edge rotation */ +/* GSet for edge rotation */ typedef struct EdRotState { int v1, v2; /* edge vert, small -> large */ int f1, f2; /* face vert, small -> large */ } EdRotState; -static unsigned int erot_ghashutil_hash(const void *ptr) +static unsigned int erot_gsetutil_hash(const void *ptr) { const EdRotState *e_state = (const EdRotState *)ptr; unsigned int @@ -71,7 +71,7 @@ static unsigned int erot_ghashutil_hash(const void *ptr) hash ^= BLI_ghashutil_inthash(SET_INT_IN_POINTER(e_state->f2)); return hash; } -static int erot_ghashutil_cmp(const void *a, const void *b) +static int erot_gsetutil_cmp(const void *a, const void *b) { const EdRotState *e_state_a = (const EdRotState *)a; const EdRotState *e_state_b = (const EdRotState *)b; @@ -86,9 +86,9 @@ static int erot_ghashutil_cmp(const void *a, const void *b) else return 0; } -static GHash *erot_ghash_new(void) +static GSet *erot_gset_new(void) { - return BLI_ghash_new(erot_ghashutil_hash, erot_ghashutil_cmp, __func__); + return BLI_gset_new(erot_gsetutil_hash, erot_gsetutil_cmp, __func__); } /* ensure v0 is smaller */ @@ -236,12 +236,12 @@ static float bm_edge_calc_rotate_beauty(const BMEdge *e, const int flag) /* Update the edge cost of rotation in the heap */ /* recalc an edge in the heap (surrounding geometry has changed) */ -static void bm_edge_update_beauty_cost_single(BMEdge *e, Heap *eheap, HeapNode **eheap_table, GHash **edge_state_arr, +static void bm_edge_update_beauty_cost_single(BMEdge *e, Heap *eheap, HeapNode **eheap_table, GSet **edge_state_arr, const int flag) { if (BM_elem_flag_test(e, BM_ELEM_TAG)) { const int i = BM_elem_index_get(e); - GHash *e_state_hash = edge_state_arr[i]; + GSet *e_state_set = edge_state_arr[i]; if (eheap_table[i]) { BLI_heap_remove(eheap, eheap_table[i]); @@ -254,10 +254,10 @@ static void bm_edge_update_beauty_cost_single(BMEdge *e, Heap *eheap, HeapNode * // BMO_elem_flag_test(bm, e->l->radial_next->f, FACE_MARK)); /* check we're not moving back into a state we have been in before */ - if (e_state_hash != NULL) { + if (e_state_set != NULL) { EdRotState e_state_alt; erot_state_alternate(e, &e_state_alt); - if (BLI_ghash_haskey(e_state_hash, (void *)&e_state_alt)) { + if (BLI_gset_haskey(e_state_set, (void *)&e_state_alt)) { // printf(" skipping, we already have this state\n"); return; } @@ -277,7 +277,7 @@ static void bm_edge_update_beauty_cost_single(BMEdge *e, Heap *eheap, HeapNode * } /* we have rotated an edge, tag other edges and clear this one */ -static void bm_edge_update_beauty_cost(BMEdge *e, Heap *eheap, HeapNode **eheap_table, GHash **edge_state_arr, +static void bm_edge_update_beauty_cost(BMEdge *e, Heap *eheap, HeapNode **eheap_table, GSet **edge_state_arr, const int flag) { BMLoop *l; @@ -308,7 +308,7 @@ static void bm_mesh_beautify_fill(BMesh *bm, BMEdge **edge_array, const int edge Heap *eheap; /* edge heap */ HeapNode **eheap_table; /* edge index aligned table pointing to the eheap */ - GHash **edge_state_arr = MEM_callocN(edge_array_len * sizeof(GHash *), __func__); + GSet **edge_state_arr = MEM_callocN(edge_array_len * sizeof(GSet *), __func__); BLI_mempool *edge_state_pool = BLI_mempool_create(sizeof(EdRotState), 512, 512, BLI_MEMPOOL_SYSMALLOC); int i; @@ -338,18 +338,18 @@ static void bm_mesh_beautify_fill(BMesh *bm, BMEdge **edge_array, const int edge e = BM_edge_rotate(bm, e, false, BM_EDGEROT_CHECK_EXISTS); if (LIKELY(e)) { - GHash *e_state_hash = edge_state_arr[i]; + GSet *e_state_set = edge_state_arr[i]; - /* add the new state into the hash so we don't move into this state again + /* add the new state into the set so we don't move into this state again * note: we could add the previous state too but this isn't essential) * for avoiding eternal loops */ EdRotState *e_state = BLI_mempool_alloc(edge_state_pool); erot_state_current(e, e_state); - if (UNLIKELY(e_state_hash == NULL)) { - edge_state_arr[i] = e_state_hash = erot_ghash_new(); /* store previous state */ + if (UNLIKELY(e_state_set == NULL)) { + edge_state_arr[i] = e_state_set = erot_gset_new(); /* store previous state */ } - BLI_assert(BLI_ghash_haskey(e_state_hash, (void *)e_state) == false); - BLI_ghash_insert(e_state_hash, e_state, NULL); + BLI_assert(BLI_gset_haskey(e_state_set, (void *)e_state) == false); + BLI_gset_insert(e_state_set, e_state); // printf(" %d -> %d, %d\n", i, BM_elem_index_get(e->v1), BM_elem_index_get(e->v2)); @@ -373,7 +373,7 @@ static void bm_mesh_beautify_fill(BMesh *bm, BMEdge **edge_array, const int edge for (i = 0; i < edge_array_len; i++) { if (edge_state_arr[i]) { - BLI_ghash_free(edge_state_arr[i], NULL, NULL); + BLI_gset_free(edge_state_arr[i], NULL); } } diff --git a/source/blender/bmesh/operators/bmo_hull.c b/source/blender/bmesh/operators/bmo_hull.c index 9ba08f0a470..f0ec45b624f 100644 --- a/source/blender/bmesh/operators/bmo_hull.c +++ b/source/blender/bmesh/operators/bmo_hull.c @@ -67,7 +67,7 @@ typedef struct HullTriangle { /*************************** Hull Triangles ***************************/ -static void hull_add_triangle(BMesh *bm, GHash *hull_triangles, BLI_mempool *pool, +static void hull_add_triangle(BMesh *bm, GSet *hull_triangles, BLI_mempool *pool, BMVert *v1, BMVert *v2, BMVert *v3) { HullTriangle *t; @@ -82,7 +82,7 @@ static void hull_add_triangle(BMesh *bm, GHash *hull_triangles, BLI_mempool *poo for (i = 0; i < 3; i++) BMO_elem_flag_disable(bm, t->v[i], HULL_FLAG_INTERIOR_ELE); - BLI_ghash_insert(hull_triangles, t, NULL); + BLI_gset_insert(hull_triangles, t); normal_tri_v3(t->no, v1->co, v2->co, v3->co); } @@ -102,12 +102,12 @@ static BMFace *hull_find_example_face(BMesh *bm, BMEdge *e) return NULL; } -static void hull_output_triangles(BMesh *bm, GHash *hull_triangles) +static void hull_output_triangles(BMesh *bm, GSet *hull_triangles) { - GHashIterator iter; + GSetIterator iter; - GHASH_ITER (iter, hull_triangles) { - HullTriangle *t = BLI_ghashIterator_getKey(&iter); + GSET_ITER (iter, hull_triangles) { + HullTriangle *t = BLI_gsetIterator_getKey(&iter); int i; if (!t->skip) { @@ -206,22 +206,22 @@ static int hull_final_edges_lookup(HullFinalEdges *final_edges, } /* Used for checking whether a pre-existing edge lies on the hull */ -static HullFinalEdges *hull_final_edges(GHash *hull_triangles) +static HullFinalEdges *hull_final_edges(GSet *hull_triangles) { HullFinalEdges *final_edges; - GHashIterator iter; + GSetIterator iter; final_edges = MEM_callocN(sizeof(HullFinalEdges), "HullFinalEdges"); final_edges->edges = BLI_ghash_ptr_new("final edges ghash"); final_edges->base_pool = BLI_mempool_create(sizeof(ListBase), 128, 128, 0); final_edges->link_pool = BLI_mempool_create(sizeof(LinkData), 128, 128, 0); - GHASH_ITER (iter, hull_triangles) { + GSET_ITER (iter, hull_triangles) { LinkData *link; int i; for (i = 0; i < 3; i++) { - HullTriangle *t = BLI_ghashIterator_getKey(&iter); + HullTriangle *t = BLI_gsetIterator_getKey(&iter); BMVert *v1 = t->v[i]; BMVert *v2 = t->v[(i + 1) % 3]; ListBase *adj; @@ -259,13 +259,13 @@ static void hull_final_edges_free(HullFinalEdges *final_edges) /**************************** Final Output ****************************/ -static void hull_remove_overlapping(BMesh *bm, GHash *hull_triangles, +static void hull_remove_overlapping(BMesh *bm, GSet *hull_triangles, HullFinalEdges *final_edges) { - GHashIterator hull_iter; + GSetIterator hull_iter; - GHASH_ITER (hull_iter, hull_triangles) { - HullTriangle *t = BLI_ghashIterator_getKey(&hull_iter); + GSET_ITER (hull_iter, hull_triangles) { + HullTriangle *t = BLI_gsetIterator_getKey(&hull_iter); BMIter bm_iter1, bm_iter2; BMFace *f; bool f_on_hull; @@ -479,7 +479,7 @@ static BMVert **hull_verts_from_bullet(plConvexHull hull, } static void hull_from_bullet(BMesh *bm, BMOperator *op, - GHash *hull_triangles, + GSet *hull_triangles, BLI_mempool *pool) { int *fvi = NULL; @@ -556,7 +556,7 @@ void bmo_convex_hull_exec(BMesh *bm, BMOperator *op) BLI_mempool *hull_pool; BMElemF *ele; BMOIter oiter; - GHash *hull_triangles; + GSet *hull_triangles; /* Verify that at least three verts in the input */ if (!hull_num_input_verts_is_ok(op)) { @@ -575,7 +575,7 @@ void bmo_convex_hull_exec(BMesh *bm, BMOperator *op) } hull_pool = BLI_mempool_create(sizeof(HullTriangle), 128, 128, 0); - hull_triangles = BLI_ghash_ptr_new("hull_triangles"); + hull_triangles = BLI_gset_ptr_new("hull_triangles"); hull_from_bullet(bm, op, hull_triangles, hull_pool); @@ -597,7 +597,7 @@ void bmo_convex_hull_exec(BMesh *bm, BMOperator *op) hull_output_triangles(bm, hull_triangles); BLI_mempool_destroy(hull_pool); - BLI_ghash_free(hull_triangles, NULL, NULL); + BLI_gset_free(hull_triangles, NULL); hull_tag_unused(bm, op); diff --git a/source/blender/bmesh/operators/bmo_subdivide_edgering.c b/source/blender/bmesh/operators/bmo_subdivide_edgering.c index fa39ae68cdf..d9d87d0db78 100644 --- a/source/blender/bmesh/operators/bmo_subdivide_edgering.c +++ b/source/blender/bmesh/operators/bmo_subdivide_edgering.c @@ -203,7 +203,7 @@ finally: /* -------------------------------------------------------------------- */ /* Edge Loop Pairs */ /* key (ordered loop pointers) */ -static GHash *bm_edgering_pair_calc(BMesh *bm, ListBase *eloops_rim) +static GSet *bm_edgering_pair_calc(BMesh *bm, ListBase *eloops_rim) { /** * Method for for finding pairs: @@ -219,7 +219,7 @@ static GHash *bm_edgering_pair_calc(BMesh *bm, ListBase *eloops_rim) * could sort and optimize this but not really so important. */ - GHash *eloop_pair_gh = BLI_ghash_pair_new(__func__); + GSet *eloop_pair_gs = BLI_gset_pair_new(__func__); GHash *vert_eloop_gh = BLI_ghash_ptr_new(__func__); struct BMEdgeLoopStore *el_store; @@ -256,9 +256,9 @@ static GHash *bm_edgering_pair_calc(BMesh *bm, ListBase *eloops_rim) if (pair_test.first > pair_test.second) SWAP(const void *, pair_test.first, pair_test.second); - if (!BLI_ghash_haskey(eloop_pair_gh, &pair_test)) { + if (!BLI_gset_haskey(eloop_pair_gs, &pair_test)) { GHashPair *pair = BLI_ghashutil_pairalloc(pair_test.first, pair_test.second); - BLI_ghash_insert(eloop_pair_gh, pair, NULL); + BLI_gset_insert(eloop_pair_gs, pair); } } @@ -268,12 +268,12 @@ static GHash *bm_edgering_pair_calc(BMesh *bm, ListBase *eloops_rim) BLI_ghash_free(vert_eloop_gh, NULL, NULL); - if (BLI_ghash_size(eloop_pair_gh) == 0) { - BLI_ghash_free(eloop_pair_gh, NULL, NULL); - eloop_pair_gh = NULL; + if (BLI_gset_size(eloop_pair_gs) == 0) { + BLI_gset_free(eloop_pair_gs, NULL); + eloop_pair_gs = NULL; } - return eloop_pair_gh; + return eloop_pair_gs; } @@ -1175,23 +1175,23 @@ void bmo_subdivide_edgering_exec(BMesh *bm, BMOperator *op) } } else { - GHashIterator gh_iter; + GSetIterator gs_iter; int i; - GHash *eloop_pairs_gh = bm_edgering_pair_calc(bm, &eloops_rim); + GSet *eloop_pairs_gs = bm_edgering_pair_calc(bm, &eloops_rim); LoopPairStore **lpair_arr; - if (eloop_pairs_gh == NULL) { + if (eloop_pairs_gs == NULL) { BMO_error_raise(bm, op, BMERR_INVALID_SELECTION, "Edge-rings are not connected"); goto cleanup; } - lpair_arr = BLI_array_alloca(lpair_arr, BLI_ghash_size(eloop_pairs_gh)); + lpair_arr = BLI_array_alloca(lpair_arr, BLI_gset_size(eloop_pairs_gs)); /* first cache pairs */ - GHASH_ITER_INDEX (gh_iter, eloop_pairs_gh, i) { - GHashPair *eloop_pair = BLI_ghashIterator_getKey(&gh_iter); + GSET_ITER_INDEX (gs_iter, eloop_pairs_gs, i) { + GHashPair *eloop_pair = BLI_gsetIterator_getKey(&gs_iter); struct BMEdgeLoopStore *el_store_a = (void *)eloop_pair->first; struct BMEdgeLoopStore *el_store_b = (void *)eloop_pair->second; LoopPairStore *lpair; @@ -1207,8 +1207,8 @@ void bmo_subdivide_edgering_exec(BMesh *bm, BMOperator *op) BLI_assert(bm_verts_tag_count(bm) == 0); } - GHASH_ITER_INDEX (gh_iter, eloop_pairs_gh, i) { - GHashPair *eloop_pair = BLI_ghashIterator_getKey(&gh_iter); + GSET_ITER_INDEX (gs_iter, eloop_pairs_gs, i) { + GHashPair *eloop_pair = BLI_gsetIterator_getKey(&gs_iter); struct BMEdgeLoopStore *el_store_a = (void *)eloop_pair->first; struct BMEdgeLoopStore *el_store_b = (void *)eloop_pair->second; LoopPairStore *lpair = lpair_arr[i]; @@ -1222,7 +1222,7 @@ void bmo_subdivide_edgering_exec(BMesh *bm, BMOperator *op) BLI_assert(bm_verts_tag_count(bm) == 0); } - BLI_ghash_free(eloop_pairs_gh, MEM_freeN, NULL); + BLI_gset_free(eloop_pairs_gs, MEM_freeN); } cleanup: |