montagejs / collections

This package contains JavaScript implementations of common data structures with idiomatic interfaces.
http://www.collectionsjs.com
Other
2.09k stars 185 forks source link

[feature request] SortedMap pop and shift methods #245

Open anatol-grabowski opened 2 years ago

anatol-grabowski commented 2 years ago

This functionality was lacking when I was implementing order book service (https://docs.kraken.com/websockets/#message-book) through SortedMap. When the maximum stored length is reached and a new level comes we want to pop the last element.

This could of course be implemented through map.delete(map.entries()[0][0]) but a call to entries would run a loop over each item in the map which is ineffective.

Currently I've implemented pop through map.store.pop(); map.length = map.store.length which uses the internals but does the job. Maybe there already is a cleaner way?