Skip to content

Commit a0205f9

Browse files
committed
IMPORT: import cebtree (compact elastic binary trees)
This is an import of the compact elastic binary trees at commit a9cd84a ("OPTIM: descent: better prefetch less and for writes when deleting") These will be used to replace certain lists (and possibly certain tree nodes as well). They're as fast (or even faster) than ebtrees for lookups, as fast for insertion and slower for deletion, and a node only uses 2 pointers (like a list). The only changes were cebtree.h where common/tools.h was replaced with ebtree.h which we already have and already provides the needed functions and macros, and the addition of a wrapper cebtree-prv.h in src/ to redirect to import/cebtree-prv.h.
1 parent 6e92988 commit a0205f9

20 files changed

+3419
-0
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,9 @@ OBJS += src/mux_h2.o src/mux_h1.o src/mux_fcgi.o src/stream.o \
983983
src/hpack-tbl.o src/ebsttree.o src/ebistree.o src/auth.o \
984984
src/hpack-huff.o src/freq_ctr.o src/dict.o src/wdt.o \
985985
src/pipe.o src/init.o src/http_acl.o src/hpack-enc.o \
986+
src/cebu32_tree.o src/cebu64_tree.o src/cebua_tree.o \
987+
src/cebub_tree.o src/cebuib_tree.o src/cebuis_tree.o \
988+
src/cebul_tree.o src/cebus_tree.o \
986989
src/ebtree.o src/dgram.o src/hash.o src/version.o \
987990
src/limits.o src/mux_spop.o
988991

include/import/cebtree-prv.h

Lines changed: 1601 additions & 0 deletions
Large diffs are not rendered by default.

include/import/cebtree.h

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Compact Elastic Binary Trees - exported functions operating on node's address
3+
*
4+
* Copyright (C) 2014-2024 Willy Tarreau - [email protected]
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining
7+
* a copy of this software and associated documentation files (the
8+
* "Software"), to deal in the Software without restriction, including
9+
* without limitation the rights to use, copy, modify, merge, publish,
10+
* distribute, sublicense, and/or sell copies of the Software, and to
11+
* permit persons to whom the Software is furnished to do so, subject to
12+
* the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be
15+
* included in all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24+
* OTHER DEALINGS IN THE SOFTWARE.
25+
*/
26+
27+
#ifndef _CEBTREE_H
28+
#define _CEBTREE_H
29+
30+
#include <stddef.h>
31+
#include "ebtree.h"
32+
33+
/* Standard node when using absolute pointers */
34+
struct ceb_node {
35+
struct ceb_node *b[2]; /* branches: 0=left, 1=right */
36+
};
37+
38+
/* indicates whether a valid node is in a tree or not */
39+
static inline int ceb_intree(const struct ceb_node *node)
40+
{
41+
return !!node->b[0];
42+
}
43+
44+
/* tag an untagged pointer */
45+
static inline struct ceb_node *__ceb_dotag(const struct ceb_node *node)
46+
{
47+
return (struct ceb_node *)((size_t)node + 1);
48+
}
49+
50+
/* untag a tagged pointer */
51+
static inline struct ceb_node *__ceb_untag(const struct ceb_node *node)
52+
{
53+
return (struct ceb_node *)((size_t)node - 1);
54+
}
55+
56+
/* clear a pointer's tag */
57+
static inline struct ceb_node *__ceb_clrtag(const struct ceb_node *node)
58+
{
59+
return (struct ceb_node *)((size_t)node & ~((size_t)1));
60+
}
61+
62+
/* returns whether a pointer is tagged */
63+
static inline int __ceb_tagged(const struct ceb_node *node)
64+
{
65+
return !!((size_t)node & 1);
66+
}
67+
68+
/* returns an integer equivalent of the pointer */
69+
static inline size_t __ceb_intptr(struct ceb_node *tree)
70+
{
71+
return (size_t)tree;
72+
}
73+
74+
///* returns true if at least one of the branches is a subtree node, indicating
75+
// * that the current node is at the top of a duplicate sub-tree and that all
76+
// * values below it are the same.
77+
// */
78+
//static inline int __ceb_is_dup(const struct ceb_node *node)
79+
//{
80+
// return __ceb_tagged((struct ceb_node *)(__ceb_intptr(node->l) | __ceb_intptr(node->r)));
81+
//}
82+
83+
#endif /* _CEBTREE_H */

include/import/cebu32_tree.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Compact Elastic Binary Trees - exported functions operating on u32 keys
3+
*
4+
* Copyright (C) 2014-2024 Willy Tarreau - [email protected]
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining
7+
* a copy of this software and associated documentation files (the
8+
* "Software"), to deal in the Software without restriction, including
9+
* without limitation the rights to use, copy, modify, merge, publish,
10+
* distribute, sublicense, and/or sell copies of the Software, and to
11+
* permit persons to whom the Software is furnished to do so, subject to
12+
* the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be
15+
* included in all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24+
* OTHER DEALINGS IN THE SOFTWARE.
25+
*/
26+
27+
#include "cebtree.h"
28+
#include <inttypes.h>
29+
30+
/* simpler version */
31+
struct ceb_node *cebu32_insert(struct ceb_node **root, struct ceb_node *node);
32+
struct ceb_node *cebu32_first(struct ceb_node **root);
33+
struct ceb_node *cebu32_last(struct ceb_node **root);
34+
struct ceb_node *cebu32_lookup(struct ceb_node **root, uint32_t key);
35+
struct ceb_node *cebu32_lookup_le(struct ceb_node **root, uint32_t key);
36+
struct ceb_node *cebu32_lookup_lt(struct ceb_node **root, uint32_t key);
37+
struct ceb_node *cebu32_lookup_ge(struct ceb_node **root, uint32_t key);
38+
struct ceb_node *cebu32_lookup_gt(struct ceb_node **root, uint32_t key);
39+
struct ceb_node *cebu32_next(struct ceb_node **root, struct ceb_node *node);
40+
struct ceb_node *cebu32_prev(struct ceb_node **root, struct ceb_node *node);
41+
struct ceb_node *cebu32_delete(struct ceb_node **root, struct ceb_node *node);
42+
struct ceb_node *cebu32_pick(struct ceb_node **root, uint32_t key);
43+
void cebu32_default_dump(struct ceb_node **ceb_root, const char *label, const void *ctx);
44+
45+
/* version taking a key offset */
46+
struct ceb_node *cebu32_ofs_insert(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node);
47+
struct ceb_node *cebu32_ofs_first(struct ceb_node **root, ptrdiff_t kofs);
48+
struct ceb_node *cebu32_ofs_last(struct ceb_node **root, ptrdiff_t kofs);
49+
struct ceb_node *cebu32_ofs_lookup(struct ceb_node **root, ptrdiff_t kofs, uint32_t key);
50+
struct ceb_node *cebu32_ofs_lookup_le(struct ceb_node **root, ptrdiff_t kofs, uint32_t key);
51+
struct ceb_node *cebu32_ofs_lookup_lt(struct ceb_node **root, ptrdiff_t kofs, uint32_t key);
52+
struct ceb_node *cebu32_ofs_lookup_ge(struct ceb_node **root, ptrdiff_t kofs, uint32_t key);
53+
struct ceb_node *cebu32_ofs_lookup_gt(struct ceb_node **root, ptrdiff_t kofs, uint32_t key);
54+
struct ceb_node *cebu32_ofs_next(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node);
55+
struct ceb_node *cebu32_ofs_prev(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node);
56+
struct ceb_node *cebu32_ofs_delete(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node);
57+
struct ceb_node *cebu32_ofs_pick(struct ceb_node **root, ptrdiff_t kofs, uint32_t key);
58+
void cebu32_ofs_default_dump(struct ceb_node **root, ptrdiff_t kofs, const char *label, const void *ctx);

include/import/cebu64_tree.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Compact Elastic Binary Trees - exported functions for operations on u64 keys
3+
*
4+
* Copyright (C) 2014-2024 Willy Tarreau - [email protected]
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining
7+
* a copy of this software and associated documentation files (the
8+
* "Software"), to deal in the Software without restriction, including
9+
* without limitation the rights to use, copy, modify, merge, publish,
10+
* distribute, sublicense, and/or sell copies of the Software, and to
11+
* permit persons to whom the Software is furnished to do so, subject to
12+
* the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be
15+
* included in all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24+
* OTHER DEALINGS IN THE SOFTWARE.
25+
*/
26+
27+
#include "cebtree.h"
28+
#include <inttypes.h>
29+
30+
/* simpler version */
31+
struct ceb_node *cebu64_insert(struct ceb_node **root, struct ceb_node *node);
32+
struct ceb_node *cebu64_first(struct ceb_node **root);
33+
struct ceb_node *cebu64_last(struct ceb_node **root);
34+
struct ceb_node *cebu64_lookup(struct ceb_node **root, uint64_t key);
35+
struct ceb_node *cebu64_lookup_le(struct ceb_node **root, uint64_t key);
36+
struct ceb_node *cebu64_lookup_lt(struct ceb_node **root, uint64_t key);
37+
struct ceb_node *cebu64_lookup_ge(struct ceb_node **root, uint64_t key);
38+
struct ceb_node *cebu64_lookup_gt(struct ceb_node **root, uint64_t key);
39+
struct ceb_node *cebu64_next(struct ceb_node **root, struct ceb_node *node);
40+
struct ceb_node *cebu64_prev(struct ceb_node **root, struct ceb_node *node);
41+
struct ceb_node *cebu64_delete(struct ceb_node **root, struct ceb_node *node);
42+
struct ceb_node *cebu64_pick(struct ceb_node **root, uint64_t key);
43+
void cebu64_default_dump(struct ceb_node **ceb_root, const char *label, const void *ctx);
44+
45+
/* version taking a key offset */
46+
struct ceb_node *cebu64_ofs_insert(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node);
47+
struct ceb_node *cebu64_ofs_first(struct ceb_node **root, ptrdiff_t kofs);
48+
struct ceb_node *cebu64_ofs_last(struct ceb_node **root, ptrdiff_t kofs);
49+
struct ceb_node *cebu64_ofs_lookup(struct ceb_node **root, ptrdiff_t kofs, uint64_t key);
50+
struct ceb_node *cebu64_ofs_lookup_le(struct ceb_node **root, ptrdiff_t kofs, uint64_t key);
51+
struct ceb_node *cebu64_ofs_lookup_lt(struct ceb_node **root, ptrdiff_t kofs, uint64_t key);
52+
struct ceb_node *cebu64_ofs_lookup_ge(struct ceb_node **root, ptrdiff_t kofs, uint64_t key);
53+
struct ceb_node *cebu64_ofs_lookup_gt(struct ceb_node **root, ptrdiff_t kofs, uint64_t key);
54+
struct ceb_node *cebu64_ofs_next(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node);
55+
struct ceb_node *cebu64_ofs_prev(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node);
56+
struct ceb_node *cebu64_ofs_delete(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node);
57+
struct ceb_node *cebu64_ofs_pick(struct ceb_node **root, ptrdiff_t kofs, uint64_t key);
58+
void cebu64_ofs_default_dump(struct ceb_node **root, ptrdiff_t kofs, const char *label, const void *ctx);

include/import/cebua_tree.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Compact Elastic Binary Trees - exported functions operating on addr keys
3+
*
4+
* Copyright (C) 2014-2024 Willy Tarreau - [email protected]
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining
7+
* a copy of this software and associated documentation files (the
8+
* "Software"), to deal in the Software without restriction, including
9+
* without limitation the rights to use, copy, modify, merge, publish,
10+
* distribute, sublicense, and/or sell copies of the Software, and to
11+
* permit persons to whom the Software is furnished to do so, subject to
12+
* the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be
15+
* included in all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24+
* OTHER DEALINGS IN THE SOFTWARE.
25+
*/
26+
27+
#include "cebtree.h"
28+
29+
/* simpler version */
30+
struct ceb_node *cebua_insert(struct ceb_node **root, struct ceb_node *node);
31+
struct ceb_node *cebua_first(struct ceb_node **root);
32+
struct ceb_node *cebua_last(struct ceb_node **root);
33+
struct ceb_node *cebua_lookup(struct ceb_node **root, const void *key);
34+
struct ceb_node *cebua_lookup_le(struct ceb_node **root, const void *key);
35+
struct ceb_node *cebua_lookup_lt(struct ceb_node **root, const void *key);
36+
struct ceb_node *cebua_lookup_ge(struct ceb_node **root, const void *key);
37+
struct ceb_node *cebua_lookup_gt(struct ceb_node **root, const void *key);
38+
struct ceb_node *cebua_next(struct ceb_node **root, struct ceb_node *node);
39+
struct ceb_node *cebua_prev(struct ceb_node **root, struct ceb_node *node);
40+
struct ceb_node *cebua_delete(struct ceb_node **root, struct ceb_node *node);
41+
struct ceb_node *cebua_pick(struct ceb_node **root, const void *key);
42+
void cebua_default_dump(struct ceb_node **root, const char *label, const void *ctx);
43+
44+
/* version taking a key offset */
45+
struct ceb_node *cebua_ofs_insert(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node);
46+
struct ceb_node *cebua_ofs_first(struct ceb_node **root, ptrdiff_t kofs);
47+
struct ceb_node *cebua_ofs_last(struct ceb_node **root, ptrdiff_t kofs);
48+
struct ceb_node *cebua_ofs_lookup(struct ceb_node **root, ptrdiff_t kofs, const void *key);
49+
struct ceb_node *cebua_ofs_lookup_le(struct ceb_node **root, ptrdiff_t kofs, const void *key);
50+
struct ceb_node *cebua_ofs_lookup_lt(struct ceb_node **root, ptrdiff_t kofs, const void *key);
51+
struct ceb_node *cebua_ofs_lookup_ge(struct ceb_node **root, ptrdiff_t kofs, const void *key);
52+
struct ceb_node *cebua_ofs_lookup_gt(struct ceb_node **root, ptrdiff_t kofs, const void *key);
53+
struct ceb_node *cebua_ofs_next(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node);
54+
struct ceb_node *cebua_ofs_prev(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node);
55+
struct ceb_node *cebua_ofs_delete(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node);
56+
struct ceb_node *cebua_ofs_pick(struct ceb_node **root, ptrdiff_t kofs, const void *key);
57+
void cebua_ofs_default_dump(struct ceb_node **root, ptrdiff_t kofs, const char *label, const void *ctx);

include/import/cebub_tree.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Compact Elastic Binary Trees - exported functions operating on mb keys
3+
*
4+
* Copyright (C) 2014-2024 Willy Tarreau - [email protected]
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining
7+
* a copy of this software and associated documentation files (the
8+
* "Software"), to deal in the Software without restriction, including
9+
* without limitation the rights to use, copy, modify, merge, publish,
10+
* distribute, sublicense, and/or sell copies of the Software, and to
11+
* permit persons to whom the Software is furnished to do so, subject to
12+
* the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be
15+
* included in all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24+
* OTHER DEALINGS IN THE SOFTWARE.
25+
*/
26+
27+
#include "cebtree.h"
28+
29+
/* simpler version */
30+
struct ceb_node *cebub_insert(struct ceb_node **root, struct ceb_node *node, size_t len);
31+
struct ceb_node *cebub_first(struct ceb_node **root);
32+
struct ceb_node *cebub_last(struct ceb_node **root);
33+
struct ceb_node *cebub_lookup(struct ceb_node **root, const void *key, size_t len);
34+
struct ceb_node *cebub_lookup_le(struct ceb_node **root, const void *key, size_t len);
35+
struct ceb_node *cebub_lookup_lt(struct ceb_node **root, const void *key, size_t len);
36+
struct ceb_node *cebub_lookup_ge(struct ceb_node **root, const void *key, size_t len);
37+
struct ceb_node *cebub_lookup_gt(struct ceb_node **root, const void *key, size_t len);
38+
struct ceb_node *cebub_next(struct ceb_node **root, struct ceb_node *node, size_t len);
39+
struct ceb_node *cebub_prev(struct ceb_node **root, struct ceb_node *node, size_t len);
40+
struct ceb_node *cebub_delete(struct ceb_node **root, struct ceb_node *node, size_t len);
41+
struct ceb_node *cebub_pick(struct ceb_node **root, const void *key, size_t len);
42+
43+
/* version taking a key offset */
44+
struct ceb_node *cebub_ofs_insert(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node, size_t len);
45+
struct ceb_node *cebub_ofs_first(struct ceb_node **root, ptrdiff_t kofs, size_t len);
46+
struct ceb_node *cebub_ofs_last(struct ceb_node **root, ptrdiff_t kofs, size_t len);
47+
struct ceb_node *cebub_ofs_lookup(struct ceb_node **root, ptrdiff_t kofs, const void *key, size_t len);
48+
struct ceb_node *cebub_ofs_lookup_le(struct ceb_node **root, ptrdiff_t kofs, const void *key, size_t len);
49+
struct ceb_node *cebub_ofs_lookup_lt(struct ceb_node **root, ptrdiff_t kofs, const void *key, size_t len);
50+
struct ceb_node *cebub_ofs_lookup_ge(struct ceb_node **root, ptrdiff_t kofs, const void *key, size_t len);
51+
struct ceb_node *cebub_ofs_lookup_gt(struct ceb_node **root, ptrdiff_t kofs, const void *key, size_t len);
52+
struct ceb_node *cebub_ofs_next(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node, size_t len);
53+
struct ceb_node *cebub_ofs_prev(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node, size_t len);
54+
struct ceb_node *cebub_ofs_delete(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node, size_t len);
55+
struct ceb_node *cebub_ofs_pick(struct ceb_node **root, ptrdiff_t kofs, const void *key, size_t len);

0 commit comments

Comments
 (0)