Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intrusive RBLTree #77

Closed
crusader-mike opened this issue Oct 16, 2022 · 2 comments
Closed

intrusive RBLTree #77

crusader-mike opened this issue Oct 16, 2022 · 2 comments

Comments

@crusader-mike
Copy link

crusader-mike commented Oct 16, 2022

(For reasons outside of this question) I need to build an intrusive RB tree where:

  • elements automatically remove themselves from the tree in their drop implementation
  • iterating over rb tree produces a sequence of Rc<T> elements (i.e. if I got cursor to point to an element -- that element will stay alive until cursor moves on)
  • this rb tree is an equivalent of C++ multiset<T> (i.e. multiple elements with the same key are allowed)

Is it possible to do this with intrusive_collections::rbtree::RBTree?

@Amanieu
Copy link
Owner

Amanieu commented Oct 16, 2022

Yes for points 2 and 3. However for point 1 that is not possible, You need a mutable reference to the RBTree itself to remove an element from it. Consider the case where this is the last element in the tree: you need to be able to update the RBTree itself to set its root node pointer to null.

@crusader-mike
Copy link
Author

I am not sure about rbtree implementation, but in theory it shouldn't be a problem -- just like in case of a keyring (double-linked list with special null node) removing last element will simply make null node it's own neighbor...

@crusader-mike crusader-mike closed this as not planned Won't fix, can't repro, duplicate, stale Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants