Blender  V3.3
Classes | Macros | Typedefs | Enumerations | Functions
BLI_edgehash.h File Reference
#include "BLI_compiler_attrs.h"
#include "BLI_utildefines.h"

Go to the source code of this file.

Classes

struct  _EdgeHash_Edge
 
struct  _EdgeHash_Entry
 
struct  EdgeHashIterator
 
struct  EdgeSetIterator
 

Macros

#define BLI_EDGEHASH_SIZE_GUESS_FROM_LOOPS(totloop)   ((totloop) / 2)
 
#define BLI_EDGEHASH_SIZE_GUESS_FROM_POLYS(totpoly)   ((totpoly)*2)
 

Typedefs

typedef struct EdgeHash EdgeHash
 
typedef struct EdgeHashIterator EdgeHashIterator
 
typedef void(* EdgeHashFreeFP) (void *key)
 
typedef struct EdgeSet EdgeSet
 
typedef struct EdgeSetIterator EdgeSetIterator
 

Enumerations

enum  { EDGEHASH_FLAG_ALLOW_DUPES = (1 << 0) }
 

Functions

EdgeHashBLI_edgehash_new_ex (const char *info, unsigned int nentries_reserve)
 
EdgeHashBLI_edgehash_new (const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
 
void BLI_edgehash_free (EdgeHash *eh, EdgeHashFreeFP free_value)
 
void BLI_edgehash_print (EdgeHash *eh)
 
void BLI_edgehash_insert (EdgeHash *eh, unsigned int v0, unsigned int v1, void *val)
 
bool BLI_edgehash_reinsert (EdgeHash *eh, unsigned int v0, unsigned int v1, void *val)
 
voidBLI_edgehash_lookup (const EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT
 
voidBLI_edgehash_lookup_default (const EdgeHash *eh, unsigned int v0, unsigned int v1, void *default_value) ATTR_WARN_UNUSED_RESULT
 
void ** BLI_edgehash_lookup_p (EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT
 
bool BLI_edgehash_ensure_p (EdgeHash *eh, unsigned int v0, unsigned int v1, void ***r_val) ATTR_WARN_UNUSED_RESULT
 
bool BLI_edgehash_remove (EdgeHash *eh, unsigned int v0, unsigned int v1, EdgeHashFreeFP free_value)
 
voidBLI_edgehash_popkey (EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT
 
bool BLI_edgehash_haskey (const EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT
 
int BLI_edgehash_len (const EdgeHash *eh) ATTR_WARN_UNUSED_RESULT
 
void BLI_edgehash_clear_ex (EdgeHash *eh, EdgeHashFreeFP free_value, uint reserve)
 
void BLI_edgehash_clear (EdgeHash *eh, EdgeHashFreeFP free_value)
 
EdgeHashIteratorBLI_edgehashIterator_new (EdgeHash *eh) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
 
void BLI_edgehashIterator_init (EdgeHashIterator *ehi, EdgeHash *eh)
 
void BLI_edgehashIterator_free (EdgeHashIterator *ehi)
 
BLI_INLINE void BLI_edgehashIterator_step (EdgeHashIterator *ehi)
 
BLI_INLINE bool BLI_edgehashIterator_isDone (const EdgeHashIterator *ehi)
 
BLI_INLINE void BLI_edgehashIterator_getKey (EdgeHashIterator *ehi, unsigned int *r_v0, unsigned int *r_v1)
 
BLI_INLINE voidBLI_edgehashIterator_getValue (EdgeHashIterator *ehi)
 
BLI_INLINE void ** BLI_edgehashIterator_getValue_p (EdgeHashIterator *ehi)
 
BLI_INLINE void BLI_edgehashIterator_setValue (EdgeHashIterator *ehi, void *val)
 
EdgeSetBLI_edgeset_new_ex (const char *info, unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
 
EdgeSetBLI_edgeset_new (const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
 
int BLI_edgeset_len (const EdgeSet *es) ATTR_WARN_UNUSED_RESULT
 
bool BLI_edgeset_add (EdgeSet *es, unsigned int v0, unsigned int v1)
 
void BLI_edgeset_insert (EdgeSet *es, unsigned int v0, unsigned int v1)
 
bool BLI_edgeset_haskey (const EdgeSet *es, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT
 
void BLI_edgeset_free (EdgeSet *es)
 
EdgeSetIteratorBLI_edgesetIterator_new (EdgeSet *es)
 
void BLI_edgesetIterator_free (EdgeSetIterator *esi)
 
BLI_INLINE void BLI_edgesetIterator_getKey (EdgeSetIterator *esi, unsigned int *r_v0, unsigned int *r_v1)
 
BLI_INLINE void BLI_edgesetIterator_step (EdgeSetIterator *esi)
 
BLI_INLINE bool BLI_edgesetIterator_isDone (const EdgeSetIterator *esi)
 

Macro Definition Documentation

◆ BLI_EDGEHASH_SIZE_GUESS_FROM_LOOPS

#define BLI_EDGEHASH_SIZE_GUESS_FROM_LOOPS (   totloop)    ((totloop) / 2)

Definition at line 182 of file BLI_edgehash.h.

◆ BLI_EDGEHASH_SIZE_GUESS_FROM_POLYS

#define BLI_EDGEHASH_SIZE_GUESS_FROM_POLYS (   totpoly)    ((totpoly)*2)

Definition at line 183 of file BLI_edgehash.h.

Typedef Documentation

◆ EdgeHash

typedef struct EdgeHash EdgeHash

Definition at line 1 of file BLI_edgehash.h.

◆ EdgeHashFreeFP

typedef void(* EdgeHashFreeFP) (void *key)

Definition at line 34 of file BLI_edgehash.h.

◆ EdgeHashIterator

◆ EdgeSet

typedef struct EdgeSet EdgeSet

Definition at line 177 of file BLI_edgehash.h.

◆ EdgeSetIterator

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
EDGEHASH_FLAG_ALLOW_DUPES 

Only checked for in debug mode.

Definition at line 36 of file BLI_edgehash.h.

Function Documentation

◆ BLI_edgehash_clear()

void BLI_edgehash_clear ( EdgeHash eh,
EdgeHashFreeFP  free_value 
)

Wraps BLI_edgehash_clear_ex with zero entries reserved.

Definition at line 383 of file edgehash.c.

References BLI_edgehash_clear_ex().

Referenced by TEST().

◆ BLI_edgehash_clear_ex()

void BLI_edgehash_clear_ex ( EdgeHash eh,
EdgeHashFreeFP  free_value,
uint  reserve 
)

Remove all edges from hash.

◆ BLI_edgehash_ensure_p()

bool BLI_edgehash_ensure_p ( EdgeHash eh,
unsigned int  v0,
unsigned int  v1,
void ***  r_val 
)

Ensure (v0, v1) is exists in eh.

This handles the common situation where the caller needs ensure a key is added to eh, constructing a new value in the case the key isn't found. Otherwise use the existing value.

Such situations typically incur multiple lookups, however this function avoids them by ensuring the key is added, returning a pointer to the value so it can be used or initialized by the caller.

Returns
true when the value didn't need to be added. (when false, the caller must initialize the value).

Definition at line 307 of file edgehash.c.

References edgehash_ensure_can_insert(), edgehash_insert(), edgehash_insert_at_slot(), EH_INDEX_HAS_EDGE, EdgeHash::entries, init_edge(), ITER_SLOTS, NULL, SLOT_EMPTY, v1, and _EdgeHash_Entry::value.

Referenced by BKE_mesh_merge_verts(), laplacian_increase_edge_count(), blender::draw::lines_adjacency_triangle(), set_edge_adjacency_lines_indices(), split_faces_prepare_new_edges(), blender::draw::statvis_calc_sharp(), and TEST().

◆ BLI_edgehash_free()

void BLI_edgehash_free ( EdgeHash eh,
EdgeHashFreeFP  free_value 
)

◆ BLI_edgehash_haskey()

bool BLI_edgehash_haskey ( const EdgeHash eh,
unsigned int  v0,
unsigned int  v1 
)

Return boolean true/false if edge (v0,v1) in hash.

Definition at line 363 of file edgehash.c.

References edgehash_lookup_entry(), NULL, and v1.

Referenced by BKE_mesh_validate_arrays(), make_edges_mdata_extend(), and TEST().

◆ BLI_edgehash_insert()

void BLI_edgehash_insert ( EdgeHash eh,
unsigned int  v0,
unsigned int  v1,
void val 
)

◆ BLI_edgehash_len()

int BLI_edgehash_len ( const EdgeHash eh)

Return number of keys in hash.

Definition at line 368 of file edgehash.c.

References EdgeHash::length.

Referenced by make_edges_mdata_extend(), TEST(), and test_polyfill_topology().

◆ BLI_edgehash_lookup()

void* BLI_edgehash_lookup ( const EdgeHash eh,
unsigned int  v0,
unsigned int  v1 
)

Return value for given edge (v0, v1), or NULL if if key does not exist in hash. (If need exists to differentiate between key-value being NULL and lack of key then see BLI_edgehash_lookup_p().

Definition at line 295 of file edgehash.c.

References edgehash_lookup_entry(), NULL, v1, and _EdgeHash_Entry::value.

Referenced by BKE_mesh_validate_arrays(), copyFinalLoopArray_task_cb(), customdata_compare(), edgecut_get(), laplacian_edge_count(), make_edges_mdata_extend(), mesh_calc_edges_mdata(), blender::io::alembic::read_edge_creases(), sph_force_cb(), and TEST().

◆ BLI_edgehash_lookup_default()

void* BLI_edgehash_lookup_default ( const EdgeHash eh,
unsigned int  v0,
unsigned int  v1,
void default_value 
)

A version of BLI_edgehash_lookup which accepts a fallback argument.

Definition at line 289 of file edgehash.c.

References edgehash_lookup_entry(), v1, and _EdgeHash_Entry::value.

Referenced by TEST().

◆ BLI_edgehash_lookup_p()

void** BLI_edgehash_lookup_p ( EdgeHash eh,
unsigned int  v0,
unsigned int  v1 
)

Return pointer to value for given edge (v0, v1), or NULL if key does not exist in hash.

Definition at line 301 of file edgehash.c.

References edgehash_lookup_entry(), NULL, v1, and _EdgeHash_Entry::value.

Referenced by TEST(), and test_polyfill_topology().

◆ BLI_edgehash_new()

EdgeHash* BLI_edgehash_new ( const char *  info)

Definition at line 225 of file edgehash.c.

References BLI_edgehash_new_ex(), and CAPACITY_EXP_DEFAULT.

Referenced by cutEdges(), explodeMesh(), TEST(), and test_polyfill_topology().

◆ BLI_edgehash_new_ex()

EdgeHash* BLI_edgehash_new_ex ( const char *  info,
unsigned int  nentries_reserve 
)

◆ BLI_edgehash_popkey()

void* BLI_edgehash_popkey ( EdgeHash eh,
unsigned int  v0,
unsigned int  v1 
)

Remove key (v0, v1) from eh, returning the value or NULL if the key wasn't found.

Parameters
v0,v1The key to remove.
Returns
the value of key int eh or NULL.

Definition at line 338 of file edgehash.c.

References EdgeHash::dummy_count, _EdgeHash_Entry::edge, edgehash_change_index(), EH_INDEX_HAS_EDGE, EdgeHash::entries, init_edge(), ITER_SLOTS, blender::math::length(), EdgeHash::length, EdgeHash::map, NULL, SLOT_DUMMY, SLOT_EMPTY, v1, and _EdgeHash_Entry::value.

Referenced by BLI_edgehash_remove(), and TEST().

◆ BLI_edgehash_print()

void BLI_edgehash_print ( EdgeHash eh)

◆ BLI_edgehash_reinsert()

bool BLI_edgehash_reinsert ( EdgeHash eh,
unsigned int  v0,
unsigned int  v1,
void val 
)

◆ BLI_edgehash_remove()

bool BLI_edgehash_remove ( EdgeHash eh,
unsigned int  v0,
unsigned int  v1,
EdgeHashFreeFP  free_value 
)

Remove key (v0, v1) from eh, or return false if the key wasn't found.

Parameters
v0,v1The key to remove.
free_valueOptional callback to free the value.
Returns
true if key was removed from eh.

Definition at line 328 of file edgehash.c.

References BLI_edgehash_popkey(), EdgeHash::length, and v1.

Referenced by BKE_mesh_merge_verts(), and TEST().

◆ BLI_edgehashIterator_free()

void BLI_edgehashIterator_free ( EdgeHashIterator ehi)

◆ BLI_edgehashIterator_getKey()

BLI_INLINE void BLI_edgehashIterator_getKey ( EdgeHashIterator ehi,
unsigned int *  r_v0,
unsigned int *  r_v1 
)

◆ BLI_edgehashIterator_getValue()

BLI_INLINE void* BLI_edgehashIterator_getValue ( EdgeHashIterator ehi)

◆ BLI_edgehashIterator_getValue_p()

BLI_INLINE void** BLI_edgehashIterator_getValue_p ( EdgeHashIterator ehi)

◆ BLI_edgehashIterator_init()

void BLI_edgehashIterator_init ( EdgeHashIterator ehi,
EdgeHash eh 
)

Initialize an already allocated EdgeHashIterator. The hash table must not be mutated while the iterator is in use, and the iterator will step exactly BLI_edgehash_len(eh) times before becoming done.

Parameters
ehiThe EdgeHashIterator to initialize.
ehThe EdgeHash to iterate over.

Definition at line 401 of file edgehash.c.

References EdgeHashIterator::entries, EdgeHash::entries, EdgeHashIterator::index, EdgeHashIterator::length, and EdgeHash::length.

Referenced by BLI_edgehashIterator_new().

◆ BLI_edgehashIterator_isDone()

BLI_INLINE bool BLI_edgehashIterator_isDone ( const EdgeHashIterator ehi)

◆ BLI_edgehashIterator_new()

EdgeHashIterator* BLI_edgehashIterator_new ( EdgeHash eh)

Create a new EdgeHashIterator. The hash table must not be mutated while the iterator is in use, and the iterator will step exactly #BLI_edgehash_len(eh) times before becoming done.

Definition at line 394 of file edgehash.c.

References BLI_edgehashIterator_init(), and MEM_mallocN.

Referenced by cutEdges(), DRW_displist_indexbuf_create_edges_adjacency_lines(), explodeMesh(), blender::draw::extract_lines_adjacency_finish(), make_edges_mdata_extend(), blender::draw::statvis_calc_sharp(), TEST(), and test_polyfill_topology().

◆ BLI_edgehashIterator_setValue()

BLI_INLINE void BLI_edgehashIterator_setValue ( EdgeHashIterator ehi,
void val 
)

◆ BLI_edgehashIterator_step()

BLI_INLINE void BLI_edgehashIterator_step ( EdgeHashIterator ehi)

◆ BLI_edgeset_add()

bool BLI_edgeset_add ( EdgeSet es,
unsigned int  v0,
unsigned int  v1 
)

A version of BLI_edgeset_insert which checks first if the key is in the set.

Returns
true if a new key has been added.
Note
EdgeHash has no equivalent to this because typically the value would be different.

Definition at line 484 of file edgehash.c.

References edgeset_ensure_can_insert(), edgeset_insert_at_slot(), ES_INDEX_HAS_EDGE, init_edge(), ITER_SLOTS, SLOT_EMPTY, and v1.

Referenced by BKE_mesh_calc_edges_tessface(), cloth_brush_add_length_constraint(), cloth_build_springs(), ss_sync_from_uv(), and TEST().

◆ BLI_edgeset_free()

void BLI_edgeset_free ( EdgeSet es)

◆ BLI_edgeset_haskey()

bool BLI_edgeset_haskey ( const EdgeSet es,
unsigned int  v0,
unsigned int  v1 
)

◆ BLI_edgeset_insert()

void BLI_edgeset_insert ( EdgeSet es,
unsigned int  v0,
unsigned int  v1 
)

Adds the key to the set (no checks for unique keys!). Matching BLI_edgehash_insert

Definition at line 500 of file edgehash.c.

References edgeset_ensure_can_insert(), edgeset_insert_at_slot(), init_edge(), ITER_SLOTS, SLOT_EMPTY, and v1.

Referenced by cloth_build_springs(), and TEST().

◆ BLI_edgeset_len()

int BLI_edgeset_len ( const EdgeSet es)

Definition at line 448 of file edgehash.c.

References EdgeSet::length.

Referenced by BKE_mesh_calc_edges_tessface(), and TEST().

◆ BLI_edgeset_new()

EdgeSet* BLI_edgeset_new ( const char *  info)

◆ BLI_edgeset_new_ex()

EdgeSet* BLI_edgeset_new_ex ( const char *  info,
unsigned int  nentries_reserve 
)

◆ BLI_edgesetIterator_free()

void BLI_edgesetIterator_free ( EdgeSetIterator esi)

Definition at line 536 of file edgehash.c.

References MEM_freeN.

Referenced by BKE_mesh_calc_edges_tessface().

◆ BLI_edgesetIterator_getKey()

BLI_INLINE void BLI_edgesetIterator_getKey ( EdgeSetIterator esi,
unsigned int *  r_v0,
unsigned int *  r_v1 
)

Definition at line 222 of file BLI_edgehash.h.

References EdgeSetIterator::edges, and EdgeSetIterator::index.

Referenced by BKE_mesh_calc_edges_tessface().

◆ BLI_edgesetIterator_isDone()

BLI_INLINE bool BLI_edgesetIterator_isDone ( const EdgeSetIterator esi)

Definition at line 234 of file BLI_edgehash.h.

References EdgeSetIterator::index, and EdgeSetIterator::length.

Referenced by BKE_mesh_calc_edges_tessface().

◆ BLI_edgesetIterator_new()

EdgeSetIterator* BLI_edgesetIterator_new ( EdgeSet es)

◆ BLI_edgesetIterator_step()

BLI_INLINE void BLI_edgesetIterator_step ( EdgeSetIterator esi)

Definition at line 230 of file BLI_edgehash.h.

References EdgeSetIterator::index.

Referenced by BKE_mesh_calc_edges_tessface().