commit 7a9e5888e9b721452869e35b83e74b36844d3cfd
parent 193a7be520502f24e995b71768dd89c37b3776eb
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date: Fri, 23 Jun 2023 14:44:05 +0000
Use less stack with avlnode
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat:
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git 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
@@ -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) ;