-
Notifications
You must be signed in to change notification settings - Fork 53
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
[Do Not Merge] PoC of cyclic previous node technique #38
Conversation
0e7fd1c
to
b44a404
Compare
Do you see any drawback in adding an implicit root node? I would suggest moving forward with that approach... :) |
If implicit root node exists, top-level nodes (created by the user) may have siblings, though they were not told to have. let mut arena = Arena::new();
let n1a = arena.new_node("1a");
let n1b = arena.new_node("1b");
let n2 = arena.new_node("2");
// arena
// `-- (implicit 1)
// `-- 1a
// `-- (implicit 2)
// `-- 1b
// `-- (implicit 3)
// `-- 2
n1a.insert_after(n1b, &mut arena);
// arena
// `-- (implicit 1)
// |-- 1a
// `-- 1b
// `-- (implicit 3)
// `-- 2 Mainly there are two problems:
I think they (implicit nodes) bring some complexity and exceptional rule, and it may make the code hard to read and maintain... |
b44a404
to
bb0fe3f
Compare
Required breaking change for this feature is additional parameter for neighbors accessors (such as If you really want this, you can change the interface before implementing internals. |
See <http://www.aosabook.org/en/posa/parsing-xml-at-the-speed-of-light.html>. Note that, by this implementation, node insersions and removals are not O(1) for top-level nodes. Fixes saschagrunert#12.
Currently `Node::previous_sibling()` and `Node::last_child()` really requires the arena, but others (such as `Node::parent()`) does not. However, it is implementation details and should be hidden from the users. So they should have the same interface.
bb0fe3f
to
03cf106
Compare
In one of my uses of |
TL;DR: I don't think this change is worth doing with non-obvious breaking change... The problem of the current PR is that insertion and detach of top-level nodes are not O(N). Possible solutions (currently I'm aware of) are:
Choice 1 will cause performance degration. This change reduces memory consumption a little, but also make the implementation more complex and may require semantics to change. |
Closing as the branch is outdated and I won't maintain this experimental PoC anymore. |
This is a PoC implementation of #12.
I noticed:
indextree
does not provide implicit root nodes, and toplevel nodes can have siblings without parents.For such nodes, updating neighbors are O(
num_of_siblings
).indextree/src/relations.rs
Lines 83 to 90 in 8e7fafa
Node::parent()
) should receive&Arena<T>
.This is not intrinsic difficutly, because when people wanted to get
NodeId
fromNode<T>
, then they would have&Arena<T>
.(However, I feel it is just annoying to pass
&arena
as an argument all the time).If this change is worth merging, then I think
indextree
should support some mechanism for pseudo-parent node or implicit root node to make updates constant time.