-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
applitopia's sorted Map and Sorted Set implementation #1998
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
base: main
Are you sure you want to change the base?
Conversation
Copy exactly `applitopia/immutable-sorted`'s implementation of sorted map and sorted set minus the partial sort impplementation applitopia/immutable-sorted@d700f18 Co-authored-by: Applitopia <[email protected]>
f41d323
to
b62ac0a
Compare
An interesting fork! Intuitively, I kinda would expect Sorted and Ordered types be the same thing? You can already get what Sorted does by always calling
and
|
Indeed, the performance is O(n) with calling |
Interesting idea! I see a reason to go this way from an API design point of view... a smaller API surface should be easier to learn. On the other hand, I would say Ordered and Sorted types are conceptually different... one is not a special case of the other, that is: there is no real comparator function that one can pass to a Sorted type to produce an Ordered type, since the comparator function needs to be commutative. I would say passing an Along the same lines, I can't think of a way to implement the "Ordered" behavior with a regular b-tree, so from an implementation standpoint it would make sense to still have the current "Ordered" data structures and code underneath. |
Possibly related to #88 |
OK now I understand this PR. To be sure, conceptually, it's the same as calling Whereas Set(['a', 'c', 'b'])
// order might be 'b', 'a', 'c' as Set will optimize the indexing
OrderedSet(['a', 'c', 'b'])
// order will be 'a', 'c', 'b' because Ordered Set keep the order by design
SortedSet(['a', 'c', 'b'])
// order will be 'a', 'b', 'c' as each item will be sorted |
This is an attempt to upstream applitopia's implementation of sorted map and sorted set.
The code, tests and type definitions are exactly as in the fork, except:
While I am happy with the result as it is (up to date immutable + sorted map), I am not that familiar with the internals of Immutable, therefore I am not particularly eager to steward this PR all the way to merge. If one of the maintainers is interested and willing to do so that would be much appreciated! Otherwise it can be closed and perhaps serve as a starting point for the next brave soul to attempt this feat :)