Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Sorted map please! #88

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

Open
chenglou opened this issue Aug 27, 2014 · 21 comments
Open

Sorted map please! #88

chenglou opened this issue Aug 27, 2014 · 21 comments

Comments

@chenglou
Copy link

A map that inserts new items in the correct position, providing a custom sort function on the keys.

Would be nice. Otherwise, I can do fine with keeping a key array for the sorting, and a map myself.

@leebyron
Copy link
Collaborator

Yes! I want to build this and SortedSet.

@KyleAMathews
Copy link
Contributor

+100

@dashed
Copy link
Contributor

dashed commented Feb 16, 2015

Just figured out I need this.

+1 from me.

@trevorbernard
Copy link

+1 indeed :shipit:

@qfox
Copy link

qfox commented May 8, 2015

πŸ‘

@ghost
Copy link

ghost commented Aug 4, 2015

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

@manuel
Copy link

manuel commented Aug 10, 2015

Sorted map would be great! πŸ‘

@matklad
Copy link

matklad commented Aug 13, 2015

Also, an OrderedMap can be implemented atop of a SortedMap without amortization.

@dozoisch
Copy link

That would be so useful!

@rhys-vdw
Copy link

Agreed. If I understand correctly .sort() creates a copy every time (even when called in withMutations). So if I want to insert sorted, I have to duplicate the OrderedMap twice. eg:

const map = OrdererMap({a: 'a', c: 'c'});
const sorted = map.set('b', 'b').sort(); // Creates two copies.

@thomasboyt
Copy link
Contributor

For prior art on this issue, Clojure(script)'s sorted-map implementation uses a persistent red-black tree:

There's a JavaScript implementation of the same data structure here that might be useful, too.

Clojure's sorted-set uses the same data structure, slightly wrapped: https://github.com/clojure/clojure/blob/clojure-1.7.0/src/jvm/clojure/lang/PersistentTreeSet.java

@leebyron
Copy link
Collaborator

leebyron commented Mar 8, 2017

RB Tree sounds like the right way to do this.

I'm putting this up for grabs for any adventurous contributors. Best way to learn about Persistent Immutable data structures is to implement them!

@youfoundron
Copy link

youfoundron commented May 18, 2017

Have not used yet but this SortedMap seems promising.

@crodriguez1a
Copy link

@akagomez Want to take a crack at RB Tree implementation?

@akagomez
Copy link

Tempting @crodriguez1a.

I've done a bunch of work with Red-Black Binary Tree's for CanJS (https://github.com/canjs/can-binarytree), based on a fork of this repo: https://github.com/vadimg/js_bintrees

Leveraging that RB Tree implementation again should make this a less daunting task.

If nobody disagrees with this approach I don't mind taking a crack at it with @crodriguez1a's help.

@youfoundron
Copy link

@akagomez feel free to steal from my toy SortedMap (api not fully implemented) that I started for a side project: https://github.com/rongierlach/immutable-sorted-map/

It is using a regular BST under the hood, am intending to convert it to RB later on.

@applitopia
Copy link

The long wait is over. Have a look at our immutable-js fork with highly optimized implementation of SortedMap and SortedSet. Current version is using classic B-trees. https://github.com/applitopia/immutable-sorted

@akagomez
Copy link

Darn, I was looking forward to playing with this myself.

Maybe @crodriguez1a and I can help convert @applitopia's implementation to use RB-trees.

@leebyron
Copy link
Collaborator

leebyron commented Oct 4, 2017

@applitopia - please consider contributing those implementations to this project!

@axefrog
Copy link

axefrog commented Jan 28, 2018

For reference if you want to adapt it, or as an alternative solution, my own immutable collections library has (among others) a sorted map, a sorted set and a red-black tree. The sorted map/set collections behave like Immutable.js' ordered equivalents by default, or you can supply a custom sorting predicate to have them sort their elements however you like. https://github.com/frptools/collectable

@jdizzle217
Copy link

Need this too! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests