Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple existence check #56

Open
mzrzvi opened this issue Mar 21, 2024 · 2 comments
Open

simple existence check #56

mzrzvi opened this issue Mar 21, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@mzrzvi
Copy link

mzrzvi commented Mar 21, 2024

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!

@mourner mourner added the enhancement New feature or request label Mar 22, 2024
@mourner
Copy link
Owner

mourner commented Mar 22, 2024

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:

results.push(index); // leaf item

Not sure how common this use case is though. Can you tell more about yours?

@HansBrende
Copy link

HansBrende commented Jul 16, 2024

@mourner here's a use-case: test if a polygon is simple--only need one intersection meeting certain criteria to prove otherwise!

Even better than a "maxResults" though might be a generator method... that way caller can determine when to early-exit without having to calculate how many results are needed in advance (which would be especially useful if the output is being piped through another generator method, for example.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants