Skip to content
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

TreeMap #123

Open
pbadenski opened this issue Jan 9, 2020 · 2 comments
Open

TreeMap #123

pbadenski opened this issue Jan 9, 2020 · 2 comments

Comments

@pbadenski
Copy link
Contributor

Any plans to add TreeMap (or similar), ie. Map that preserves insertion order, but at the same time gives very good of performance of operations .

@Yomguithereal
Copy link
Owner

Hello @pbadenski

Any plans to add TreeMap (or similar), ie. Map that preserves insertion order,

I am not sure to know what you mean. ES6 Map already preserves insertion order (using linked nodes in the hashmap rather than using a tree in most implementation if I recall correctly).

but at the same time gives very good of performance of operations .

So I guess there is one kind of operation of the ES6 Map which is not fast enough for you. Could you give one of your use case so I can understand? I could very well add a TreeMap to the library but I would like to know what kind of use cases it could solve in JS that isn't handled by something else already.

@booi
Copy link

booi commented Mar 30, 2022

Just to revive an old conversation. I think @pbadenski is asking to add a similar data structure to java's TreeMap. The primary use case (that I've seen) is an efficient query the nearest key (floor or ceil) for a given search such as in floorKey and ceilKey. To do this you'd need to maintain an ordered list of the keys and binary search. I think the target efficiency is O(log n) insertion and O(log n) search (floor, ceil) and O(1) exact match.

I'd be happy to implement this since I ran into this today. Is there an ordered list data structure that can be used?

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

3 participants