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 |
Weibye
left a comment
There was a problem hiding this comment.
The change itself looks good, I do agree with @TimJentzsch about the newtype id.
025cb79 to
23612e1
Compare
|
Ok, so I've introduced a
|
TimJentzsch
left a comment
There was a problem hiding this comment.
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
LayoutTreetrait without using aSlotMapas the backing storage because it usesslotmap::DefaultKeyin 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 twou32s) 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.