Blender  V2.93
BLI_smallhash.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  * The Original Code is Copyright (C) 2008 Blender Foundation.
17  * All rights reserved.
18  */
19 
20 #pragma once
21 
26 #include "BLI_compiler_attrs.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 typedef struct {
34  void *val;
36 
37 /* how much stack space to use before dynamically allocating memory.
38  * set to match one of the values in 'hashsizes' to avoid too many mallocs */
39 #define SMSTACKSIZE 131
40 typedef struct SmallHash {
41  unsigned int nbuckets;
42  unsigned int nentries;
43  unsigned int cursize;
44 
48 
49 typedef struct {
50  const SmallHash *sh;
51  unsigned int i;
53 
54 void BLI_smallhash_init_ex(SmallHash *sh, const unsigned int nentries_reserve) ATTR_NONNULL(1);
57 void BLI_smallhash_insert(SmallHash *sh, uintptr_t key, void *item) ATTR_NONNULL(1);
58 bool BLI_smallhash_reinsert(SmallHash *sh, uintptr_t key, void *item) ATTR_NONNULL(1);
60 void *BLI_smallhash_lookup(const SmallHash *sh, uintptr_t key)
62 void **BLI_smallhash_lookup_p(const SmallHash *sh, uintptr_t key)
65 int BLI_smallhash_len(const SmallHash *sh) ATTR_NONNULL(1);
70 void *BLI_smallhash_iternew(const SmallHash *sh, SmallHashIter *iter, uintptr_t *key)
72 void **BLI_smallhash_iternew_p(const SmallHash *sh, SmallHashIter *iter, uintptr_t *key)
74 /* void BLI_smallhash_print(SmallHash *sh); */ /* UNUSED */
75 
76 #ifdef DEBUG
77 double BLI_smallhash_calc_quality(SmallHash *sh);
78 #endif
79 
80 #ifdef __cplusplus
81 }
82 #endif
#define ATTR_NONNULL(...)
void BLI_kdtree_nd_() int BLI_kdtree_nd_() int BLI_kdtree_nd_() int BLI_kdtree_nd_() ATTR_WARN_UNUSED_RESULT
#define SMSTACKSIZE
Definition: BLI_smallhash.h:39
void ** BLI_smallhash_iternew_p(const SmallHash *sh, SmallHashIter *iter, uintptr_t *key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
Definition: smallhash.c:344
void * BLI_smallhash_iternext(SmallHashIter *iter, uintptr_t *key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
Definition: smallhash.c:322
bool BLI_smallhash_haskey(const SmallHash *sh, uintptr_t key) ATTR_NONNULL(1)
Definition: smallhash.c:293
void BLI_smallhash_init(SmallHash *sh) ATTR_NONNULL(1)
Definition: smallhash.c:212
struct SmallHash SmallHash
void ** BLI_smallhash_lookup_p(const SmallHash *sh, uintptr_t key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
Definition: smallhash.c:286
void ** BLI_smallhash_iternext_p(SmallHashIter *iter, uintptr_t *key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
Definition: smallhash.c:329
void BLI_smallhash_insert(SmallHash *sh, uintptr_t key, void *item) ATTR_NONNULL(1)
Definition: smallhash.c:225
void BLI_smallhash_release(SmallHash *sh) ATTR_NONNULL(1)
Definition: smallhash.c:218
void BLI_smallhash_init_ex(SmallHash *sh, const unsigned int nentries_reserve) ATTR_NONNULL(1)
Definition: smallhash.c:191
void * BLI_smallhash_lookup(const SmallHash *sh, uintptr_t key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
Definition: smallhash.c:279
bool BLI_smallhash_reinsert(SmallHash *sh, uintptr_t key, void *item) ATTR_NONNULL(1)
Definition: smallhash.c:249
int BLI_smallhash_len(const SmallHash *sh) ATTR_NONNULL(1)
Definition: smallhash.c:300
void * BLI_smallhash_iternew(const SmallHash *sh, SmallHashIter *iter, uintptr_t *key) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
Definition: smallhash.c:336
bool BLI_smallhash_remove(SmallHash *sh, uintptr_t key) ATTR_NONNULL(1)
_W64 unsigned int uintptr_t
Definition: stdint.h:122
uintptr_t key
Definition: BLI_smallhash.h:33
unsigned int i
Definition: BLI_smallhash.h:51
const SmallHash * sh
Definition: BLI_smallhash.h:50
unsigned int cursize
Definition: BLI_smallhash.h:43
unsigned int nentries
Definition: BLI_smallhash.h:42
SmallHashEntry * buckets
Definition: BLI_smallhash.h:45
SmallHashEntry buckets_stack[SMSTACKSIZE]
Definition: BLI_smallhash.h:46
unsigned int nbuckets
Definition: BLI_smallhash.h:41