summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_lvlhsh.h
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2018-03-29 16:35:42 +0300
committerIgor Sysoev <igor@sysoev.ru>2018-03-29 16:35:42 +0300
commit5177b085b13be78d216441d21480caf81eb968c2 (patch)
treeea3c80a789a295d072fd339d10b23515d6dea549 /src/nxt_lvlhsh.h
parent5a9c23e2b4ff39ee4c25f67ece56e3d441edfeed (diff)
downloadunit-5177b085b13be78d216441d21480caf81eb968c2.tar.gz
unit-5177b085b13be78d216441d21480caf81eb968c2.tar.bz2
nxt_lvlhsh_each() refactoring and nxt_lvlhsh_each_init().
Diffstat (limited to 'src/nxt_lvlhsh.h')
-rw-r--r--src/nxt_lvlhsh.h46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/nxt_lvlhsh.h b/src/nxt_lvlhsh.h
index 07342d44..7127c0d0 100644
--- a/src/nxt_lvlhsh.h
+++ b/src/nxt_lvlhsh.h
@@ -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