-
Notifications
You must be signed in to change notification settings - Fork 111
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
Use struct NodeId(u64)
instead of slotmap::DefaultKey
in all public APIs
#426
Use struct NodeId(u64)
instead of slotmap::DefaultKey
in all public APIs
#426
Conversation
I think I would prefer to have an explicit newtype for this (e.g. That would make the code easier to read (effectively adding more documentation) and would make it easier to change the internal representation later if needed. |
Hmm... so something like: struct NodeId(u64) I can see advantages of this (for one I could implement conversion function to and from slotmap keys, which would reduce a bunch of boilerplate). Would you want that type exposed externally in the |
Yup, that's exactly what I had in mind :)
I think it would be reasonable to export it as well, but I don't have strong opinions on this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change itself looks good, I do agree with @TimJentzsch about the newtype id.
025cb79
to
23612e1
Compare
Ok, so I've introduced a
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
I also like the naming of NodeId
more than the previous Node
, which indicated that there is some data stored in Node
.
This was a source of confusion for me before.
Do you want to add this to the release notes in this PR or in a future one? |
Release notes added :) |
u64
instead of slotmap::DefaultKey
in the LayoutTree
traitstruct NodeId(u64)
instead of slotmap::DefaultKey
in all public APIs
Performance seems to be roughly neutral :) Merging! |
Objective
It's not currenty possible to use the
LayoutTree
trait without using aSlotMap
as the backing storage because it usesslotmap::DefaultKey
in the API! This replaces that withu64
.Fixes #327
Notes
Benchmark result show this as perf neutral even though a small amount of work is introduced by converting the
DefaultKey
(backed by twou32
s) into au64
.Possible alternatives
We could make all of our code generic over the key type like in #326. However this introduces generics all over the place affecting both code readability and compile times. I figure that everyone is likely to have a u64 compatible key, and if someone doesn't then we can revisit this issue at a later date.