-
Notifications
You must be signed in to change notification settings - Fork 32
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
suggestion: let the remove operation preserve node identity #55
Comments
That makes a lot of sense, I will look into how it can be done
…On Mon, 13 Mar 2023 at 11:15, farteryhr ***@***.***> wrote:
in C++ STL's term, don't invalidate iterators on removal, except those
pointing on the removed node.
(if the nodes returned in various APIs are to be regarded as "iterators",
with the assumption that users don't tamper with it, which is common in the
javascript world)
the modification is rather straightforward. in remove function, instead of
assigning the data and key of the "lifted node" to the "deleted node",
maintain the left, right, parentreferences to/from the "lifted node" and
cut the "deleted node"'s outward references (but preserve the key and data).
within my knowledge of the currently implemented APIs, the remove
operation is the only one that breaks this. (more care may be needed if split,
join are to be added)
this allows iterator usages to work (there might not be much, but i really
have code using iterators the iterator way). without this property, though
workaround exists, one has to find by .key, prev/next, store .key again
and again, that's hurts both readability (+code size) and overall
performance.
also returning the node deleted makes more sense (may be inserted again
with the fictional insertNode API).
there might be performance degradation due to more operations to do. but
since the remove operation is the fastest operation here, it's nice to have
this property with a little price. or maybe removeGracefully?
—
Reply to this email directly, view it on GitHub
<#55>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAGSBHMN6Y5772HQ3Q433TW33XVJANCNFSM6AAAAAAVY3P6PM>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
some other doc fixes
and further suggestions mainly due to my own taste (on those not mentioned here, your library is more of my taste than any other avl tree libraries found on npm):
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in C++ STL's term, don't invalidate iterators on removal of elements, except those pointing to the removed node.
(if the nodes returned in various APIs are to be regarded as "iterators", with the assumption that users don't tamper with it, which is common in the javascript world)
the modification is rather straightforward. in remove function, instead of assigning the
data
andkey
of the "lifted node" to the "deleted node", maintain theleft, right, parent
references to/from the "lifted node" and cut the "deleted node"'s outward references (but preserve the key and data).within my knowledge of the currently implemented APIs, the remove operation is the only one that breaks this. (more care may be needed if
split, join
are to be added)this allows iterator usages to work (there might not be much, but i really have code using iterators the iterator way). without this property, though workaround exists, one has to find by
.key
, prev/next, store.key
again and again, that's hurts both readability (+code size) and overall performance.also returning the node deleted makes more sense (may be inserted again with the fictional
insertNode
API).there might be performance degradation due to more operations to do. but since the remove operation is the fastest operation here, it's nice to have this property with a little price. or maybe
removeGracefully
?The text was updated successfully, but these errors were encountered: