-
Notifications
You must be signed in to change notification settings - Fork 159
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
Add dynamically-sized slices of maps and sets #177
Conversation
7bb54c3
to
ea9437c
Compare
This is very nice. Slices have such nice properties, so a lot can be done using this. I was unsure if Deref should be implemented, that creates a very strong link between the set of methods exposed in both types. |
I'm not sure either. There's a lot of duplication right now in indexing methods, and in a new semver we might let I'm not sure about |
I'd like to think of it as not contentious, more about a careful approach.. we don't know if it's a good idea with Deref, so we hold it off? However, I can see that both choices Deref/no deref impact the methods provided, so it's not necessarily that simple. Without looking at the details, I just suspect that there are methods/operators on Slice that will feel unintuitive and surprising, perhaps even misleading when applied on the IndexMap. That's why I'd like to hold off on the Deref impl. Now, Index impls on Slice should not apply on If we compare with Vec, the interface change (or "loss") because of the Vec -> slice conversion is relatively smaller than what we have here - both Vec and slice are integer-indexed sequences. A map slice is a whole another thing than a hash map, so it feels weird to have it implicit. If would be less weird, if it allowed map lookup! Maybe |
Ok, I rebased and left out |
Additional ideas:
|
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.
Seems great. If we can think of some basic tests to add, it could be indexing.
I've added a few more things, including some indexing tests. |
I love this idea! One question though: why not expose (and rename if needed) |
One reason is mutability -- we try not to expose key-changing abilities without at least opting in to the Otherwise I think it's just a preference not to expose implementation details, but you're probably right that it wouldn't be too bad to provide a simple public API on that. |
Ah, good point about A even simpler idea would be to only expose |
That's a lot of surface area to mess up, and there's no barrier to calling those methods. For example, |
Another idea I've just added is |
I think there are no concerns here, so let's go! |
Both
map::Slice<K, V>
andset::Slice<T>
are true DSTs, simply wrapping[Bucket]
, created by reference either indexing with ranges or callingas_slice()
oras_mut_slice()
. They support many of the normal indexing methods of slices, like splitting, but nothing that would change the order or require hashing. They also reuse the iterator types from map and set.Slice
equality does consider the order of the elements, and this is followed byPartialOrd
,Ord
, andHash
as well.