mnemonist
mnemonist copied to clipboard
TreeMap
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 .
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.
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?