nxt_lvlhsh_each() refactoring and nxt_lvlhsh_each_init().

This commit is contained in:
Igor Sysoev
2018-03-29 16:35:42 +03:00
parent 5a9c23e2b4
commit 5177b085b1
5 changed files with 34 additions and 24 deletions

View File

@@ -99,6 +99,21 @@ struct nxt_lvlhsh_query_s {
};
typedef struct {
const nxt_lvlhsh_proto_t *proto;
/*
* Fields to store current bucket entry position. They cannot be
* combined in a single bucket pointer with number of entries in low
* bits, because entry positions are not aligned. A current level is
* stored as key bit path from the root.
*/
uint32_t *bucket;
uint32_t current;
uint32_t entry;
uint32_t entries;
} nxt_lvlhsh_each_t;
#define \
nxt_lvlhsh_is_empty(lh) \
((lh)->slot == NULL)
@@ -145,24 +160,21 @@ NXT_EXPORT nxt_int_t nxt_lvlhsh_insert(nxt_lvlhsh_t *lh,
NXT_EXPORT nxt_int_t nxt_lvlhsh_delete(nxt_lvlhsh_t *lh,
nxt_lvlhsh_query_t *lhq);
/*
* nxt_lvlhsh_each_init() initializes iterator.
* It must be called before the first nxt_lvlhsh_each() call.
*/
#define nxt_lvlhsh_each_init(lhe, _proto) \
do { \
(lhe)->proto = _proto; \
(lhe)->bucket = NULL; \
} while (0)
typedef struct {
const nxt_lvlhsh_proto_t *proto;
/*
* Fields to store current bucket entry position. They cannot be
* combined in a single bucket pointer with number of entries in low
* bits, because entry positions are not aligned. A current level is
* stored as key bit path from the root.
*/
uint32_t *bucket;
uint32_t current;
uint32_t entry;
uint32_t entries;
} nxt_lvlhsh_each_t;
NXT_EXPORT void *nxt_lvlhsh_each(nxt_lvlhsh_t *lh, nxt_lvlhsh_each_t *le);
/*
* nxt_lvlhsh_each() iterates over a lvlhsh.
* It returns NULL if there is no more elements.
*/
NXT_EXPORT void *nxt_lvlhsh_each(nxt_lvlhsh_t *lh, nxt_lvlhsh_each_t *lhe);
/*
* nxt_lvlhsh_peek() is used to iterate over a lvlhsh during the lvlhsh