w8r / splay-tree

Fast splay-tree data structure
https://npm.runkit.com/splaytree
114 stars 18 forks source link

Documentation: equal keys in "range" #4

Open shaunc opened 6 years ago

shaunc commented 6 years ago

Thanks for the library. It would be great to document what happens in the case of equal keys (by the comparator function).

I want to store (numerical) ranges, and be able to search for all items whose range is overlapping. (In fact, the items indexed have disjoint ranges, but the search range may have start and end overlapping several.) My idea was to have a comparator that took a range as a key, and returned 0 for overlapping ranges, but otherwise ordered by start of range. With a quick test, it seems to work, but the documentation doesn't guarantee that it will work. Also "find" does seem non-deterministic when it comes to retrieving items with equal keys.

UPDATE In fact, doesn't always seem to return all nodes in range if there are several equal. (Is this a bug?) Switched to querying for range [start,start] -> [end,end] to get elements overlapping range [start, end]. This seems to work (given indexed items are disjoint). In any case, documentation would be welcome.