From 377840850455c39fedbf877f35091a011a7d48cf Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Wed, 20 Dec 2023 14:49:31 -0500 Subject: [PATCH] make proper use of the allocator --- include/blt/std/binary_tree.h | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/include/blt/std/binary_tree.h b/include/blt/std/binary_tree.h index 60775fb..bfd2b8f 100755 --- a/include/blt/std/binary_tree.h +++ b/include/blt/std/binary_tree.h @@ -29,16 +29,19 @@ namespace blt class AVL_node_tree { private: + ALLOC alloc; + struct node { T val; node* left; node* right; + ALLOC& alloc; - node(const T& t): val(t) + node(const T& t, ALLOC& alloc): val(t), alloc(alloc) {} - node(T&& m): val(m) + node(T&& m, ALLOC alloc): val(m), alloc(alloc) {} node(const node& copy) = delete; @@ -51,24 +54,19 @@ namespace blt ~node() { - delete left; - delete right; + left->~node(); + alloc.deallocate(left); + right->~node(); + alloc.deallocate(right); } }; - ALLOC alloc; - node* root = nullptr; - - inline node* newNode(const T& t) - { - return alloc.construct(alloc.allocate(1), t); - } - inline node* newNode(T&& t) { - return alloc.construct(alloc.allocate(1), t); + return new(alloc.allocate(1)) node(t); } - + + node* root = nullptr; public: AVL_node_tree() = default; @@ -139,7 +137,8 @@ namespace blt ~AVL_node_tree() { - delete root; + root->~node(); + alloc.deallocate(root); } };