diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-06-23 14:44:05 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-06-23 14:44:05 +0000 |
commit | 7a9e5888e9b721452869e35b83e74b36844d3cfd (patch) | |
tree | e16a89e0c5440e2e895c7086436bcfa67b633487 /src | |
parent | 193a7be520502f24e995b71768dd89c37b3776eb (diff) | |
download | skalibs-7a9e5888e9b721452869e35b83e74b36844d3cfd.tar.xz |
Use less stack with avlnode
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/libdatastruct/avlnode_delete.c | 10 | ||||
-rw-r--r-- | src/libdatastruct/avlnode_insertnode.c | 6 |
2 files changed, 10 insertions, 6 deletions
diff --git a/src/libdatastruct/avlnode_delete.c b/src/libdatastruct/avlnode_delete.c index e75e0cc..8c68d39 100644 --- a/src/libdatastruct/avlnode_delete.c +++ b/src/libdatastruct/avlnode_delete.c @@ -1,15 +1,17 @@ /* ISC license. */ +#include <stdint.h> + #include <skalibs/avlnode.h> #include "avlnode-internal.h" uint32_t avlnode_delete (avlnode *s, uint32_t max, uint32_t *root, void const *k, dtok_func_ref dtok, cmp_func_ref f, void *p) { - uint32_t stack[AVLNODE_MAXDEPTH] ; - int spin[AVLNODE_MAXDEPTH] ; - unsigned int sp = 0 ; uint32_t r = *root ; uint32_t itodel ; + uint32_t stack[AVLNODE_MAXDEPTH] ; + uint8_t spin[AVLNODE_MAXDEPTH] ; + uint8_t sp = 0 ; for (; r < max ; sp++) { @@ -24,7 +26,7 @@ uint32_t avlnode_delete (avlnode *s, uint32_t max, uint32_t *root, void const *k if ((s[r].child[0] < max) || (s[r].child[1] < max)) { - int subspin = s[r].child[1] < max ; + uint8_t subspin = s[r].child[1] < max ; stack[sp] = r ; spin[sp++] = subspin ; r = s[r].child[subspin] ; diff --git a/src/libdatastruct/avlnode_insertnode.c b/src/libdatastruct/avlnode_insertnode.c index cfeb6d4..294b109 100644 --- a/src/libdatastruct/avlnode_insertnode.c +++ b/src/libdatastruct/avlnode_insertnode.c @@ -1,13 +1,15 @@ /* ISC license. */ +#include <stdint.h> + #include <skalibs/avlnode.h> #include "avlnode-internal.h" uint32_t avlnode_insertnode (avlnode *s, uint32_t max, uint32_t r, uint32_t i, dtok_func_ref dtok, cmp_func_ref f, void *p) { uint32_t stack[AVLNODE_MAXDEPTH] ; - int spin[AVLNODE_MAXDEPTH] ; - unsigned int sp = 0 ; + uint8_t spin[AVLNODE_MAXDEPTH] ; + uint8_t sp = 0 ; { void const *k = (*dtok)(s[i].data, p) ; |