forked from haproxy/haproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
20 changed files
with
3,419 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Compact Elastic Binary Trees - exported functions operating on node's address | ||
* | ||
* Copyright (C) 2014-2024 Willy Tarreau - [email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to | ||
* the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
* OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#ifndef _CEBTREE_H | ||
#define _CEBTREE_H | ||
|
||
#include <stddef.h> | ||
#include "ebtree.h" | ||
|
||
/* Standard node when using absolute pointers */ | ||
struct ceb_node { | ||
struct ceb_node *b[2]; /* branches: 0=left, 1=right */ | ||
}; | ||
|
||
/* indicates whether a valid node is in a tree or not */ | ||
static inline int ceb_intree(const struct ceb_node *node) | ||
{ | ||
return !!node->b[0]; | ||
} | ||
|
||
/* tag an untagged pointer */ | ||
static inline struct ceb_node *__ceb_dotag(const struct ceb_node *node) | ||
{ | ||
return (struct ceb_node *)((size_t)node + 1); | ||
} | ||
|
||
/* untag a tagged pointer */ | ||
static inline struct ceb_node *__ceb_untag(const struct ceb_node *node) | ||
{ | ||
return (struct ceb_node *)((size_t)node - 1); | ||
} | ||
|
||
/* clear a pointer's tag */ | ||
static inline struct ceb_node *__ceb_clrtag(const struct ceb_node *node) | ||
{ | ||
return (struct ceb_node *)((size_t)node & ~((size_t)1)); | ||
} | ||
|
||
/* returns whether a pointer is tagged */ | ||
static inline int __ceb_tagged(const struct ceb_node *node) | ||
{ | ||
return !!((size_t)node & 1); | ||
} | ||
|
||
/* returns an integer equivalent of the pointer */ | ||
static inline size_t __ceb_intptr(struct ceb_node *tree) | ||
{ | ||
return (size_t)tree; | ||
} | ||
|
||
///* returns true if at least one of the branches is a subtree node, indicating | ||
// * that the current node is at the top of a duplicate sub-tree and that all | ||
// * values below it are the same. | ||
// */ | ||
//static inline int __ceb_is_dup(const struct ceb_node *node) | ||
//{ | ||
// return __ceb_tagged((struct ceb_node *)(__ceb_intptr(node->l) | __ceb_intptr(node->r))); | ||
//} | ||
|
||
#endif /* _CEBTREE_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Compact Elastic Binary Trees - exported functions operating on u32 keys | ||
* | ||
* Copyright (C) 2014-2024 Willy Tarreau - [email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to | ||
* the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
* OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#include "cebtree.h" | ||
#include <inttypes.h> | ||
|
||
/* simpler version */ | ||
struct ceb_node *cebu32_insert(struct ceb_node **root, struct ceb_node *node); | ||
struct ceb_node *cebu32_first(struct ceb_node **root); | ||
struct ceb_node *cebu32_last(struct ceb_node **root); | ||
struct ceb_node *cebu32_lookup(struct ceb_node **root, uint32_t key); | ||
struct ceb_node *cebu32_lookup_le(struct ceb_node **root, uint32_t key); | ||
struct ceb_node *cebu32_lookup_lt(struct ceb_node **root, uint32_t key); | ||
struct ceb_node *cebu32_lookup_ge(struct ceb_node **root, uint32_t key); | ||
struct ceb_node *cebu32_lookup_gt(struct ceb_node **root, uint32_t key); | ||
struct ceb_node *cebu32_next(struct ceb_node **root, struct ceb_node *node); | ||
struct ceb_node *cebu32_prev(struct ceb_node **root, struct ceb_node *node); | ||
struct ceb_node *cebu32_delete(struct ceb_node **root, struct ceb_node *node); | ||
struct ceb_node *cebu32_pick(struct ceb_node **root, uint32_t key); | ||
void cebu32_default_dump(struct ceb_node **ceb_root, const char *label, const void *ctx); | ||
|
||
/* version taking a key offset */ | ||
struct ceb_node *cebu32_ofs_insert(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node); | ||
struct ceb_node *cebu32_ofs_first(struct ceb_node **root, ptrdiff_t kofs); | ||
struct ceb_node *cebu32_ofs_last(struct ceb_node **root, ptrdiff_t kofs); | ||
struct ceb_node *cebu32_ofs_lookup(struct ceb_node **root, ptrdiff_t kofs, uint32_t key); | ||
struct ceb_node *cebu32_ofs_lookup_le(struct ceb_node **root, ptrdiff_t kofs, uint32_t key); | ||
struct ceb_node *cebu32_ofs_lookup_lt(struct ceb_node **root, ptrdiff_t kofs, uint32_t key); | ||
struct ceb_node *cebu32_ofs_lookup_ge(struct ceb_node **root, ptrdiff_t kofs, uint32_t key); | ||
struct ceb_node *cebu32_ofs_lookup_gt(struct ceb_node **root, ptrdiff_t kofs, uint32_t key); | ||
struct ceb_node *cebu32_ofs_next(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node); | ||
struct ceb_node *cebu32_ofs_prev(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node); | ||
struct ceb_node *cebu32_ofs_delete(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node); | ||
struct ceb_node *cebu32_ofs_pick(struct ceb_node **root, ptrdiff_t kofs, uint32_t key); | ||
void cebu32_ofs_default_dump(struct ceb_node **root, ptrdiff_t kofs, const char *label, const void *ctx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Compact Elastic Binary Trees - exported functions for operations on u64 keys | ||
* | ||
* Copyright (C) 2014-2024 Willy Tarreau - [email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to | ||
* the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
* OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#include "cebtree.h" | ||
#include <inttypes.h> | ||
|
||
/* simpler version */ | ||
struct ceb_node *cebu64_insert(struct ceb_node **root, struct ceb_node *node); | ||
struct ceb_node *cebu64_first(struct ceb_node **root); | ||
struct ceb_node *cebu64_last(struct ceb_node **root); | ||
struct ceb_node *cebu64_lookup(struct ceb_node **root, uint64_t key); | ||
struct ceb_node *cebu64_lookup_le(struct ceb_node **root, uint64_t key); | ||
struct ceb_node *cebu64_lookup_lt(struct ceb_node **root, uint64_t key); | ||
struct ceb_node *cebu64_lookup_ge(struct ceb_node **root, uint64_t key); | ||
struct ceb_node *cebu64_lookup_gt(struct ceb_node **root, uint64_t key); | ||
struct ceb_node *cebu64_next(struct ceb_node **root, struct ceb_node *node); | ||
struct ceb_node *cebu64_prev(struct ceb_node **root, struct ceb_node *node); | ||
struct ceb_node *cebu64_delete(struct ceb_node **root, struct ceb_node *node); | ||
struct ceb_node *cebu64_pick(struct ceb_node **root, uint64_t key); | ||
void cebu64_default_dump(struct ceb_node **ceb_root, const char *label, const void *ctx); | ||
|
||
/* version taking a key offset */ | ||
struct ceb_node *cebu64_ofs_insert(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node); | ||
struct ceb_node *cebu64_ofs_first(struct ceb_node **root, ptrdiff_t kofs); | ||
struct ceb_node *cebu64_ofs_last(struct ceb_node **root, ptrdiff_t kofs); | ||
struct ceb_node *cebu64_ofs_lookup(struct ceb_node **root, ptrdiff_t kofs, uint64_t key); | ||
struct ceb_node *cebu64_ofs_lookup_le(struct ceb_node **root, ptrdiff_t kofs, uint64_t key); | ||
struct ceb_node *cebu64_ofs_lookup_lt(struct ceb_node **root, ptrdiff_t kofs, uint64_t key); | ||
struct ceb_node *cebu64_ofs_lookup_ge(struct ceb_node **root, ptrdiff_t kofs, uint64_t key); | ||
struct ceb_node *cebu64_ofs_lookup_gt(struct ceb_node **root, ptrdiff_t kofs, uint64_t key); | ||
struct ceb_node *cebu64_ofs_next(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node); | ||
struct ceb_node *cebu64_ofs_prev(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node); | ||
struct ceb_node *cebu64_ofs_delete(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node); | ||
struct ceb_node *cebu64_ofs_pick(struct ceb_node **root, ptrdiff_t kofs, uint64_t key); | ||
void cebu64_ofs_default_dump(struct ceb_node **root, ptrdiff_t kofs, const char *label, const void *ctx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Compact Elastic Binary Trees - exported functions operating on addr keys | ||
* | ||
* Copyright (C) 2014-2024 Willy Tarreau - [email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to | ||
* the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
* OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#include "cebtree.h" | ||
|
||
/* simpler version */ | ||
struct ceb_node *cebua_insert(struct ceb_node **root, struct ceb_node *node); | ||
struct ceb_node *cebua_first(struct ceb_node **root); | ||
struct ceb_node *cebua_last(struct ceb_node **root); | ||
struct ceb_node *cebua_lookup(struct ceb_node **root, const void *key); | ||
struct ceb_node *cebua_lookup_le(struct ceb_node **root, const void *key); | ||
struct ceb_node *cebua_lookup_lt(struct ceb_node **root, const void *key); | ||
struct ceb_node *cebua_lookup_ge(struct ceb_node **root, const void *key); | ||
struct ceb_node *cebua_lookup_gt(struct ceb_node **root, const void *key); | ||
struct ceb_node *cebua_next(struct ceb_node **root, struct ceb_node *node); | ||
struct ceb_node *cebua_prev(struct ceb_node **root, struct ceb_node *node); | ||
struct ceb_node *cebua_delete(struct ceb_node **root, struct ceb_node *node); | ||
struct ceb_node *cebua_pick(struct ceb_node **root, const void *key); | ||
void cebua_default_dump(struct ceb_node **root, const char *label, const void *ctx); | ||
|
||
/* version taking a key offset */ | ||
struct ceb_node *cebua_ofs_insert(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node); | ||
struct ceb_node *cebua_ofs_first(struct ceb_node **root, ptrdiff_t kofs); | ||
struct ceb_node *cebua_ofs_last(struct ceb_node **root, ptrdiff_t kofs); | ||
struct ceb_node *cebua_ofs_lookup(struct ceb_node **root, ptrdiff_t kofs, const void *key); | ||
struct ceb_node *cebua_ofs_lookup_le(struct ceb_node **root, ptrdiff_t kofs, const void *key); | ||
struct ceb_node *cebua_ofs_lookup_lt(struct ceb_node **root, ptrdiff_t kofs, const void *key); | ||
struct ceb_node *cebua_ofs_lookup_ge(struct ceb_node **root, ptrdiff_t kofs, const void *key); | ||
struct ceb_node *cebua_ofs_lookup_gt(struct ceb_node **root, ptrdiff_t kofs, const void *key); | ||
struct ceb_node *cebua_ofs_next(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node); | ||
struct ceb_node *cebua_ofs_prev(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node); | ||
struct ceb_node *cebua_ofs_delete(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node); | ||
struct ceb_node *cebua_ofs_pick(struct ceb_node **root, ptrdiff_t kofs, const void *key); | ||
void cebua_ofs_default_dump(struct ceb_node **root, ptrdiff_t kofs, const char *label, const void *ctx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Compact Elastic Binary Trees - exported functions operating on mb keys | ||
* | ||
* Copyright (C) 2014-2024 Willy Tarreau - [email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to | ||
* the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
* OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#include "cebtree.h" | ||
|
||
/* simpler version */ | ||
struct ceb_node *cebub_insert(struct ceb_node **root, struct ceb_node *node, size_t len); | ||
struct ceb_node *cebub_first(struct ceb_node **root); | ||
struct ceb_node *cebub_last(struct ceb_node **root); | ||
struct ceb_node *cebub_lookup(struct ceb_node **root, const void *key, size_t len); | ||
struct ceb_node *cebub_lookup_le(struct ceb_node **root, const void *key, size_t len); | ||
struct ceb_node *cebub_lookup_lt(struct ceb_node **root, const void *key, size_t len); | ||
struct ceb_node *cebub_lookup_ge(struct ceb_node **root, const void *key, size_t len); | ||
struct ceb_node *cebub_lookup_gt(struct ceb_node **root, const void *key, size_t len); | ||
struct ceb_node *cebub_next(struct ceb_node **root, struct ceb_node *node, size_t len); | ||
struct ceb_node *cebub_prev(struct ceb_node **root, struct ceb_node *node, size_t len); | ||
struct ceb_node *cebub_delete(struct ceb_node **root, struct ceb_node *node, size_t len); | ||
struct ceb_node *cebub_pick(struct ceb_node **root, const void *key, size_t len); | ||
|
||
/* version taking a key offset */ | ||
struct ceb_node *cebub_ofs_insert(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node, size_t len); | ||
struct ceb_node *cebub_ofs_first(struct ceb_node **root, ptrdiff_t kofs, size_t len); | ||
struct ceb_node *cebub_ofs_last(struct ceb_node **root, ptrdiff_t kofs, size_t len); | ||
struct ceb_node *cebub_ofs_lookup(struct ceb_node **root, ptrdiff_t kofs, const void *key, size_t len); | ||
struct ceb_node *cebub_ofs_lookup_le(struct ceb_node **root, ptrdiff_t kofs, const void *key, size_t len); | ||
struct ceb_node *cebub_ofs_lookup_lt(struct ceb_node **root, ptrdiff_t kofs, const void *key, size_t len); | ||
struct ceb_node *cebub_ofs_lookup_ge(struct ceb_node **root, ptrdiff_t kofs, const void *key, size_t len); | ||
struct ceb_node *cebub_ofs_lookup_gt(struct ceb_node **root, ptrdiff_t kofs, const void *key, size_t len); | ||
struct ceb_node *cebub_ofs_next(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node, size_t len); | ||
struct ceb_node *cebub_ofs_prev(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node, size_t len); | ||
struct ceb_node *cebub_ofs_delete(struct ceb_node **root, ptrdiff_t kofs, struct ceb_node *node, size_t len); | ||
struct ceb_node *cebub_ofs_pick(struct ceb_node **root, ptrdiff_t kofs, const void *key, size_t len); |
Oops, something went wrong.