flatbush
flatbush copied to clipboard
simple existence check
hi @mourner — i think there may be some utility in having a function similar to search
but is more efficient for the use case of when we want to simply check if at least 1 result exists such that the first value found in the search that passes the filter function makes it return true. this might only really be useful if the filterFn
we're sending does somewhat heavy computation, and i guess it might just make more sense to accept the results and filter outside the hash. i don't know how the search works internally, but if there's any optimizations for an exists
function, that'd be awesome!
Thanks for the suggestion! Perhaps the easiest approach would be to add an optional maxResults
parameters to search
(similar to how it works in neighbors
), and return early when reaching the specified number after this line: https://github.com/mourner/flatbush/blob/b82579a93820aba855ffadca5e672ee4515f0a9f/index.js#L241
Not sure how common this use case is though. Can you tell more about yours?