<div dir="ltr"><div><br></div>What's the best data structure to support a "nearest key" operation?<br><br>I want a data structure that supports the following operations:<br><br> new() -> NewTree<br><br>
insert(Key, Value, Tree) -> NewTree<br> <br> delete(Key, Tree) -> NewTree<br> <br> nearest(Key, N, Tree) -> [{Key1,Val1},{Key2,Val2} ...].<br><br> Keys are 20 byte binaries, values are 6 byte binaries<div>
<br></div><div> The maximum number of keys of Key-Value pairs is 10 million.<br><br> nearest(Key, N, Tree) returns the N nearest items to Key in the tree<br><br> "near" means that the keys are near to each other. Often the key I want will not<br>
be in the tree, so I want nearby keys. The nearness measure is just the<br>"distance" between the two keys (ie the nearest N keys to the given key if the keys were to<br>be sorted)<br><br>Are there any Erlang libraries that do this?<br>
<br>/Joe<br></div></div>