From f67b7c0f71788a910410def2a0a79e8fe36bf43b Mon Sep 17 00:00:00 2001 From: RomaLzhih <791191656@qq.com> Date: Wed, 4 Jun 2025 23:17:07 -0700 Subject: [PATCH] feat: basic_node allocation and aug_node iterate method - The basic_node should alloc memory based on its size, rather than the hard-coded size, which may bring trouble when developer may want to change the node structure. - When traverse the tree in augmented_node, one should cast the node to augmented_node type rather the basic node, as this may incur different offset problem. --- include/cpam/augmented_node.h | 6 +++--- include/cpam/basic_node.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/cpam/augmented_node.h b/include/cpam/augmented_node.h index e58cd14..dcf95c6 100644 --- a/include/cpam/augmented_node.h +++ b/include/cpam/augmented_node.h @@ -160,13 +160,13 @@ struct aug_node : public basic_node static void iterate_seq(node* a, const F& f) { if (!a) return; - if (basic::is_regular(a)) { - auto r = basic::cast_to_regular(a); + if (is_regular(a)) { + auto r = cast_to_regular(a); iterate_seq(r->lc, f); f(get_entry(r)); iterate_seq(r->rc, f); } else { - auto c = basic::cast_to_compressed(a); + auto c = cast_to_compressed(a); uint8_t* data_start = (((uint8_t*)c) + sizeof(aug_compressed_node)); AugEntryEncoder::decode(data_start, c->s, f); } diff --git a/include/cpam/basic_node.h b/include/cpam/basic_node.h index 1701ebc..b88a26b 100644 --- a/include/cpam/basic_node.h +++ b/include/cpam/basic_node.h @@ -193,7 +193,7 @@ struct basic_node { assert(s <= 2*B); size_t encoded_size = EntryEncoder::encoded_size(e, s); - size_t node_size = 3*sizeof(node_size_t) + encoded_size; + size_t node_size = sizeof(compressed_node) + encoded_size; compressed_node* c_node = (compressed_node*)utils::new_array_no_init(node_size); //compressed_node* c_node = (compressed_node*)complex_allocator::alloc(); @@ -201,7 +201,7 @@ struct basic_node { c_node->s = s; c_node->size_in_bytes = node_size; - uint8_t* encoded_data = (((uint8_t*)c_node) + 3*sizeof(node_size_t)); + uint8_t* encoded_data = (((uint8_t*)c_node) + sizeof(compressed_node)); EntryEncoder::encode(e, s, encoded_data); check_compressed_node(c_node);