From 9908dfdecbd22eacbc57a7863fe67cbb42b22f90 Mon Sep 17 00:00:00 2001 From: John Naylor Date: Sun, 22 Jan 2023 15:10:10 +0700 Subject: [PATCH v22 19/22] Standardize on testing for "is leaf" Some recent code decided to test for "is inner", so make everything consistent. --- src/include/lib/radixtree.h | 38 ++++++++++++------------- src/include/lib/radixtree_insert_impl.h | 18 ++++++------ 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/include/lib/radixtree.h b/src/include/lib/radixtree.h index 95124696ef..5927437034 100644 --- a/src/include/lib/radixtree.h +++ b/src/include/lib/radixtree.h @@ -1019,24 +1019,24 @@ RT_SHIFT_GET_MAX_VAL(int shift) * Allocate a new node with the given node kind. */ static RT_PTR_ALLOC -RT_ALLOC_NODE(RT_RADIX_TREE *tree, RT_SIZE_CLASS size_class, bool inner) +RT_ALLOC_NODE(RT_RADIX_TREE *tree, RT_SIZE_CLASS size_class, bool is_leaf) { RT_PTR_ALLOC allocnode; size_t allocsize; - if (inner) - allocsize = RT_SIZE_CLASS_INFO[size_class].inner_size; - else + if (is_leaf) allocsize = RT_SIZE_CLASS_INFO[size_class].leaf_size; + else + allocsize = RT_SIZE_CLASS_INFO[size_class].inner_size; #ifdef RT_SHMEM allocnode = dsa_allocate(tree->dsa, allocsize); #else - if (inner) - allocnode = (RT_PTR_ALLOC) MemoryContextAlloc(tree->inner_slabs[size_class], + if (is_leaf) + allocnode = (RT_PTR_ALLOC) MemoryContextAlloc(tree->leaf_slabs[size_class], allocsize); else - allocnode = (RT_PTR_ALLOC) MemoryContextAlloc(tree->leaf_slabs[size_class], + allocnode = (RT_PTR_ALLOC) MemoryContextAlloc(tree->inner_slabs[size_class], allocsize); #endif @@ -1050,12 +1050,12 @@ RT_ALLOC_NODE(RT_RADIX_TREE *tree, RT_SIZE_CLASS size_class, bool inner) /* Initialize the node contents */ static inline void -RT_INIT_NODE(RT_PTR_LOCAL node, uint8 kind, RT_SIZE_CLASS size_class, bool inner) +RT_INIT_NODE(RT_PTR_LOCAL node, uint8 kind, RT_SIZE_CLASS size_class, bool is_leaf) { - if (inner) - MemSet(node, 0, RT_SIZE_CLASS_INFO[size_class].inner_size); - else + if (is_leaf) MemSet(node, 0, RT_SIZE_CLASS_INFO[size_class].leaf_size); + else + MemSet(node, 0, RT_SIZE_CLASS_INFO[size_class].inner_size); node->kind = kind; @@ -1082,13 +1082,13 @@ static void RT_NEW_ROOT(RT_RADIX_TREE *tree, uint64 key) { int shift = RT_KEY_GET_SHIFT(key); - bool inner = shift > 0; + bool is_leaf = shift == 0; RT_PTR_ALLOC allocnode; RT_PTR_LOCAL newnode; - allocnode = RT_ALLOC_NODE(tree, RT_CLASS_3, inner); + allocnode = RT_ALLOC_NODE(tree, RT_CLASS_3, is_leaf); newnode = RT_PTR_GET_LOCAL(tree, allocnode); - RT_INIT_NODE(newnode, RT_NODE_KIND_3, RT_CLASS_3, inner); + RT_INIT_NODE(newnode, RT_NODE_KIND_3, RT_CLASS_3, is_leaf); newnode->shift = shift; tree->ctl->max_val = RT_SHIFT_GET_MAX_VAL(shift); tree->ctl->root = allocnode; @@ -1107,10 +1107,10 @@ RT_COPY_NODE(RT_PTR_LOCAL newnode, RT_PTR_LOCAL oldnode) */ static inline RT_PTR_LOCAL RT_SWITCH_NODE_KIND(RT_RADIX_TREE *tree, RT_PTR_ALLOC allocnode, RT_PTR_LOCAL node, - uint8 new_kind, uint8 new_class, bool inner) + uint8 new_kind, uint8 new_class, bool is_leaf) { RT_PTR_LOCAL newnode = RT_PTR_GET_LOCAL(tree, allocnode); - RT_INIT_NODE(newnode, new_kind, new_class, inner); + RT_INIT_NODE(newnode, new_kind, new_class, is_leaf); RT_COPY_NODE(newnode, node); return newnode; @@ -1247,11 +1247,11 @@ RT_SET_EXTEND(RT_RADIX_TREE *tree, uint64 key, RT_VALUE_TYPE value, RT_PTR_LOCAL RT_PTR_ALLOC allocchild; RT_PTR_LOCAL newchild; int newshift = shift - RT_NODE_SPAN; - bool inner = newshift > 0; + bool is_leaf = newshift == 0; - allocchild = RT_ALLOC_NODE(tree, RT_CLASS_3, inner); + allocchild = RT_ALLOC_NODE(tree, RT_CLASS_3, is_leaf); newchild = RT_PTR_GET_LOCAL(tree, allocchild); - RT_INIT_NODE(newchild, RT_NODE_KIND_3, RT_CLASS_3, inner); + RT_INIT_NODE(newchild, RT_NODE_KIND_3, RT_CLASS_3, is_leaf); newchild->shift = newshift; RT_NODE_INSERT_INNER(tree, parent, stored_node, node, key, allocchild); diff --git a/src/include/lib/radixtree_insert_impl.h b/src/include/lib/radixtree_insert_impl.h index 0fcebf1c6b..22aca0e6cc 100644 --- a/src/include/lib/radixtree_insert_impl.h +++ b/src/include/lib/radixtree_insert_impl.h @@ -16,10 +16,10 @@ bool chunk_exists = false; #ifdef RT_NODE_LEVEL_LEAF - const bool inner = false; + const bool is_leaf = true; Assert(RT_NODE_IS_LEAF(node)); #else - const bool inner = true; + const bool is_leaf = false; Assert(!RT_NODE_IS_LEAF(node)); #endif @@ -52,8 +52,8 @@ const RT_SIZE_CLASS new_class = RT_CLASS_32_MIN; /* grow node from 3 to 32 */ - allocnode = RT_ALLOC_NODE(tree, new_class, inner); - newnode = RT_SWITCH_NODE_KIND(tree, allocnode, node, new_kind, new_class, inner); + allocnode = RT_ALLOC_NODE(tree, new_class, is_leaf); + newnode = RT_SWITCH_NODE_KIND(tree, allocnode, node, new_kind, new_class, is_leaf); new32 = (RT_NODE32_TYPE *) newnode; #ifdef RT_NODE_LEVEL_LEAF @@ -124,7 +124,7 @@ Assert(n32->base.n.fanout == class32_min.fanout); /* grow to the next size class of this kind */ - allocnode = RT_ALLOC_NODE(tree, new_class, inner); + allocnode = RT_ALLOC_NODE(tree, new_class, is_leaf); newnode = RT_PTR_GET_LOCAL(tree, allocnode); n32 = (RT_NODE32_TYPE *) newnode; @@ -150,8 +150,8 @@ Assert(n32->base.n.fanout == class32_max.fanout); /* grow node from 32 to 125 */ - allocnode = RT_ALLOC_NODE(tree, new_class, inner); - newnode = RT_SWITCH_NODE_KIND(tree, allocnode, node, new_kind, new_class, inner); + allocnode = RT_ALLOC_NODE(tree, new_class, is_leaf); + newnode = RT_SWITCH_NODE_KIND(tree, allocnode, node, new_kind, new_class, is_leaf); new125 = (RT_NODE125_TYPE *) newnode; for (int i = 0; i < class32_max.fanout; i++) @@ -229,8 +229,8 @@ const RT_SIZE_CLASS new_class = RT_CLASS_256; /* grow node from 125 to 256 */ - allocnode = RT_ALLOC_NODE(tree, new_class, inner); - newnode = RT_SWITCH_NODE_KIND(tree, allocnode, node, new_kind, new_class, inner); + allocnode = RT_ALLOC_NODE(tree, new_class, is_leaf); + newnode = RT_SWITCH_NODE_KIND(tree, allocnode, node, new_kind, new_class, is_leaf); new256 = (RT_NODE256_TYPE *) newnode; for (int i = 0; i < RT_NODE_MAX_SLOTS && cnt < n125->base.n.count; i++) -- 2.39.0