|
26 | 26 | #define SHARE_UTILITIES_RBTREE_HPP |
27 | 27 |
|
28 | 28 | #include "cppstdlib/type_traits.hpp" |
| 29 | +#include "memory/allocation.hpp" |
| 30 | +#include "memory/arena.hpp" |
| 31 | +#include "memory/resourceArea.hpp" |
29 | 32 | #include "metaprogramming/enableIf.hpp" |
30 | 33 | #include "nmt/memTag.hpp" |
31 | 34 | #include "runtime/os.hpp" |
@@ -458,7 +461,8 @@ class RBTree : public AbstractRBTree<K, RBNode<K, V>, COMPARATOR> { |
458 | 461 | ALLOCATOR _allocator; |
459 | 462 |
|
460 | 463 | public: |
461 | | - RBTree() : BaseType(), _allocator() {} |
| 464 | + template<typename... AllocArgs> |
| 465 | + RBTree(AllocArgs... alloc_args) : BaseType(), _allocator(alloc_args...) {} |
462 | 466 | NONCOPYABLE(RBTree); |
463 | 467 | ~RBTree() { remove_all(); } |
464 | 468 |
|
@@ -580,9 +584,40 @@ class RBTreeCHeapAllocator { |
580 | 584 | void free(void* ptr) { os::free(ptr); } |
581 | 585 | }; |
582 | 586 |
|
| 587 | +template <AllocFailType strategy> |
| 588 | +class RBTreeArenaAllocator { |
| 589 | + Arena* _arena; |
| 590 | +public: |
| 591 | + RBTreeArenaAllocator(Arena* arena) : _arena(arena) {} |
| 592 | + |
| 593 | + void* allocate(size_t sz) { |
| 594 | + return _arena->Amalloc(sz, strategy); |
| 595 | + } |
| 596 | + void free(void* ptr) { /* NOP */ } |
| 597 | +}; |
| 598 | + |
| 599 | +template <AllocFailType strategy> |
| 600 | +class RBTreeResourceAreaAllocator { |
| 601 | + ResourceArea* _rarea; |
| 602 | +public: |
| 603 | + RBTreeResourceAreaAllocator(ResourceArea* rarea) : _rarea(rarea) {} |
| 604 | + void* allocate(size_t sz) { |
| 605 | + return _rarea->Amalloc(sz, strategy); |
| 606 | + } |
| 607 | + void free(void* ptr) { /* NOP */ } |
| 608 | +}; |
| 609 | + |
| 610 | + |
| 611 | + |
583 | 612 | template <typename K, typename V, typename COMPARATOR, MemTag mem_tag, AllocFailType strategy = AllocFailStrategy::EXIT_OOM> |
584 | 613 | using RBTreeCHeap = RBTree<K, V, COMPARATOR, RBTreeCHeapAllocator<mem_tag, strategy>>; |
585 | 614 |
|
| 615 | +template <typename K, typename V, typename COMPARATOR, AllocFailType strategy = AllocFailStrategy::EXIT_OOM> |
| 616 | +using RBTreeArena = RBTree<K, V, COMPARATOR, RBTreeArenaAllocator<strategy>>; |
| 617 | + |
| 618 | +template <typename K, typename V, typename COMPARATOR, AllocFailType strategy = AllocFailStrategy::EXIT_OOM> |
| 619 | +using RBTreeResourceArea = RBTree<K, V, COMPARATOR, RBTreeResourceAreaAllocator<strategy>>; |
| 620 | + |
586 | 621 | template <typename K, typename COMPARATOR> |
587 | 622 | using IntrusiveRBTree = AbstractRBTree<K, IntrusiveRBNode, COMPARATOR>; |
588 | 623 |
|
|
0 commit comments