Blender  V2.93
BLI_edgehash.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
23 #include "BLI_compiler_attrs.h"
24 #include "BLI_utildefines.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 struct EdgeHash;
31 typedef struct EdgeHash EdgeHash;
32 
35 };
36 
38  struct _EdgeHash_Edge edge;
39  void *value;
40 };
41 
42 typedef struct EdgeHashIterator {
47 
48 typedef void (*EdgeHashFreeFP)(void *key);
49 
50 enum {
51  EDGEHASH_FLAG_ALLOW_DUPES = (1 << 0), /* only checked for in debug mode */
52 };
53 
54 EdgeHash *BLI_edgehash_new_ex(const char *info, const unsigned int nentries_reserve);
56 void BLI_edgehash_free(EdgeHash *eh, EdgeHashFreeFP free_value);
58 void BLI_edgehash_insert(EdgeHash *eh, unsigned int v0, unsigned int v1, void *val);
59 bool BLI_edgehash_reinsert(EdgeHash *eh, unsigned int v0, unsigned int v1, void *val);
60 void *BLI_edgehash_lookup(EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT;
62  unsigned int v0,
63  unsigned int v1,
64  void *default_value) ATTR_WARN_UNUSED_RESULT;
66  unsigned int v0,
67  unsigned int v1) ATTR_WARN_UNUSED_RESULT;
68 bool BLI_edgehash_ensure_p(EdgeHash *eh, unsigned int v0, unsigned int v1, void ***r_val)
71  unsigned int v0,
72  unsigned int v1,
73  EdgeHashFreeFP free_value);
74 
75 void *BLI_edgehash_popkey(EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT;
76 bool BLI_edgehash_haskey(EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT;
78 void BLI_edgehash_clear_ex(EdgeHash *eh, EdgeHashFreeFP free_value, const uint reserve);
79 void BLI_edgehash_clear(EdgeHash *eh, EdgeHashFreeFP free_value);
80 
84 
86 {
87  ehi->index++;
88 }
90 {
91  return ehi->index >= ehi->length;
92 }
94  unsigned int *r_v0,
95  unsigned int *r_v1)
96 {
97  struct _EdgeHash_Edge edge = ehi->entries[ehi->index].edge;
98  *r_v0 = edge.v_low;
99  *r_v1 = edge.v_high;
100 }
102 {
103  return ehi->entries[ehi->index].value;
104 }
106 {
107  return &ehi->entries[ehi->index].value;
108 }
110 {
111  ehi->entries[ehi->index].value = val;
112 }
113 
114 #define BLI_EDGEHASH_SIZE_GUESS_FROM_LOOPS(totloop) ((totloop) / 2)
115 #define BLI_EDGEHASH_SIZE_GUESS_FROM_POLYS(totpoly) ((totpoly)*2)
116 
117 /* *** EdgeSet *** */
118 
119 struct EdgeSet;
120 typedef struct EdgeSet EdgeSet;
121 
122 typedef struct EdgeSetIterator {
127 
128 EdgeSet *BLI_edgeset_new_ex(const char *info, const unsigned int nentries_reserve)
132 bool BLI_edgeset_add(EdgeSet *es, unsigned int v0, unsigned int v1);
133 void BLI_edgeset_insert(EdgeSet *es, unsigned int v0, unsigned int v1);
134 bool BLI_edgeset_haskey(EdgeSet *es, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT;
135 void BLI_edgeset_free(EdgeSet *es);
136 
137 /* rely on inline api for now */
140 
142  unsigned int *r_v0,
143  unsigned int *r_v1)
144 {
145  struct _EdgeHash_Edge edge = esi->edges[esi->index];
146  *r_v0 = edge.v_low;
147  *r_v1 = edge.v_high;
148 }
150 {
151  esi->index++;
152 }
154 {
155  return esi->index >= esi->length;
156 }
157 
158 #ifdef __cplusplus
159 }
160 #endif
#define ATTR_MALLOC
#define BLI_INLINE
@ EDGEHASH_FLAG_ALLOW_DUPES
Definition: BLI_edgehash.h:51
void BLI_edgehash_free(EdgeHash *eh, EdgeHashFreeFP free_value)
Definition: edgehash.c:244
BLI_INLINE void BLI_edgehashIterator_getKey(EdgeHashIterator *ehi, unsigned int *r_v0, unsigned int *r_v1)
Definition: BLI_edgehash.h:93
void(* EdgeHashFreeFP)(void *key)
Definition: BLI_edgehash.h:48
BLI_INLINE bool BLI_edgehashIterator_isDone(EdgeHashIterator *ehi)
Definition: BLI_edgehash.h:89
BLI_INLINE bool BLI_edgesetIterator_isDone(EdgeSetIterator *esi)
Definition: BLI_edgehash.h:153
EdgeHash * BLI_edgehash_new_ex(const char *info, const unsigned int nentries_reserve)
Definition: edgehash.c:226
bool BLI_edgehash_reinsert(EdgeHash *eh, unsigned int v0, unsigned int v1, void *val)
Definition: edgehash.c:289
void BLI_edgehash_insert(EdgeHash *eh, unsigned int v0, unsigned int v1, void *val)
Definition: edgehash.c:279
EdgeHashIterator * BLI_edgehashIterator_new(EdgeHash *eh) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: edgehash.c:471
bool BLI_edgeset_add(EdgeSet *es, unsigned int v0, unsigned int v1)
Definition: edgehash.c:578
bool BLI_edgehash_ensure_p(EdgeHash *eh, unsigned int v0, unsigned int v1, void ***r_val) ATTR_WARN_UNUSED_RESULT
Definition: edgehash.c:355
struct EdgeHashIterator EdgeHashIterator
EdgeHash * BLI_edgehash_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: edgehash.c:239
bool BLI_edgehash_remove(EdgeHash *eh, unsigned int v0, unsigned int v1, EdgeHashFreeFP free_value)
Definition: edgehash.c:383
int BLI_edgeset_len(EdgeSet *es) ATTR_WARN_UNUSED_RESULT
Definition: edgehash.c:536
void BLI_edgeset_insert(EdgeSet *es, unsigned int v0, unsigned int v1)
Definition: edgehash.c:598
BLI_INLINE void BLI_edgesetIterator_step(EdgeSetIterator *esi)
Definition: BLI_edgehash.h:149
BLI_INLINE void BLI_edgesetIterator_getKey(EdgeSetIterator *esi, unsigned int *r_v0, unsigned int *r_v1)
Definition: BLI_edgehash.h:141
void BLI_edgehash_print(EdgeHash *eh)
Definition: edgehash.c:252
void BLI_edgesetIterator_free(EdgeSetIterator *esi)
Definition: edgehash.c:634
void ** BLI_edgehash_lookup_p(EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT
Definition: edgehash.c:335
struct EdgeSetIterator EdgeSetIterator
void BLI_edgehashIterator_init(EdgeHashIterator *ehi, EdgeHash *eh)
Definition: edgehash.c:486
void BLI_edgeset_free(EdgeSet *es)
Definition: edgehash.c:529
void * BLI_edgehash_lookup_default(EdgeHash *eh, unsigned int v0, unsigned int v1, void *default_value) ATTR_WARN_UNUSED_RESULT
Definition: edgehash.c:313
BLI_INLINE void BLI_edgehashIterator_step(EdgeHashIterator *ehi)
Definition: BLI_edgehash.h:85
void * BLI_edgehash_popkey(EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT
Definition: edgehash.c:401
void BLI_edgehash_clear(EdgeHash *eh, EdgeHashFreeFP free_value)
Definition: edgehash.c:455
void BLI_edgehashIterator_free(EdgeHashIterator *ehi)
Definition: edgehash.c:496
BLI_INLINE void * BLI_edgehashIterator_getValue(EdgeHashIterator *ehi)
Definition: BLI_edgehash.h:101
EdgeSetIterator * BLI_edgesetIterator_new(EdgeSet *es)
Definition: edgehash.c:625
void * BLI_edgehash_lookup(EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT
Definition: edgehash.c:325
int BLI_edgehash_len(EdgeHash *eh) ATTR_WARN_UNUSED_RESULT
Definition: edgehash.c:434
EdgeSet * BLI_edgeset_new_ex(const char *info, const unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: edgehash.c:512
EdgeSet * BLI_edgeset_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: edgehash.c:524
bool BLI_edgehash_haskey(EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT
Definition: edgehash.c:426
BLI_INLINE void ** BLI_edgehashIterator_getValue_p(EdgeHashIterator *ehi)
Definition: BLI_edgehash.h:105
bool BLI_edgeset_haskey(EdgeSet *es, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT
Definition: edgehash.c:611
void BLI_edgehash_clear_ex(EdgeHash *eh, EdgeHashFreeFP free_value, const uint reserve)
BLI_INLINE void BLI_edgehashIterator_setValue(EdgeHashIterator *ehi, void *val)
Definition: BLI_edgehash.h:109
void BLI_kdtree_nd_() int BLI_kdtree_nd_() int BLI_kdtree_nd_() int BLI_kdtree_nd_() ATTR_WARN_UNUSED_RESULT
unsigned int uint
Definition: BLI_sys_types.h:83
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
struct _EdgeHash_Entry * entries
Definition: BLI_edgehash.h:43
struct _EdgeHash_Edge * edges
Definition: BLI_edgehash.h:123
Definition: BLI_edgehash.h:37
struct _EdgeHash_Edge edge
Definition: BLI_edgehash.h:38
void * value
Definition: BLI_edgehash.h:39