|
|
|
|
|
by zaroth
4469 days ago
|
|
The data structure they mention using is an 'inversion map' which in their case is a mapping of numeric ranges to values. I did some quick searching and didn't find it... I wonder how they implement a key search in the inversion map. I assume you do something like populate a tree with the range transition points and then you can search in O(log n). A search on the tree would have to find the node with the highest value that was <= the requested value, or the lowest value that was >= the requested value. I assume the work of constructing the tree would have to be amortized over multiple searches to make it worth the effort. Could you do better than O(n) without building a tree? In creditcardjs.com's case, they have overlapping ranges, which means you can possibly return multiple values for a given key. |
|