From 7a9e5888e9b721452869e35b83e74b36844d3cfd Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 23 Jun 2023 14:44:05 +0000 Subject: Use less stack with avlnode Signed-off-by: Laurent Bercot --- src/libdatastruct/avlnode_delete.c | 10 ++++++---- src/libdatastruct/avlnode_insertnode.c | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'src/libdatastruct') 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 + #include #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 + #include #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) ; -- cgit v1.2.3