1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:27:35 +00:00

AK: Set IntrusiveRBTree Node key on insertion instead of construction

This makes the API look much nicer.
This commit is contained in:
Idan Horowitz 2021-09-08 03:07:34 +03:00
parent 1db9250766
commit cb9720baab
3 changed files with 33 additions and 37 deletions

View file

@ -48,10 +48,11 @@ public:
return node_to_value(*node);
}
void insert(V& value)
void insert(K key, V& value)
{
auto& node = value.*member;
VERIFY(!node.m_in_tree);
node.key = key;
BaseTree::insert(&node);
if constexpr (!TreeNode::IsRaw)
node.m_self.reference = &value; // Note: Self-reference ensures that the object will keep a ref to itself when the Container is a smart pointer.
@ -165,11 +166,6 @@ namespace Detail {
template<Integral K, typename V, typename Container>
class IntrusiveRedBlackTreeNode : public BaseRedBlackTree<K>::Node {
public:
IntrusiveRedBlackTreeNode(K key)
: BaseRedBlackTree<K>::Node(key)
{
}
~IntrusiveRedBlackTreeNode()
{
VERIFY(!is_in_tree());

View file

@ -38,6 +38,9 @@ public:
: key(key)
{
}
Node()
{
}
virtual ~Node() {};
};