Are there any built-in functions to search sorted list? Such as binary_search, lower_bound, upper_bound, etc.
-
1I don't think so. I have used vimgrep to find something like that but came up empty.– 3N4NCommented Apr 9, 2019 at 1:50
-
Why do you need this? Vim has functions to search lists—do you need performance for a large data set? Push the code to a different level (ie out of vimscript), unless vim can expose the binary search mechanism it uses for tagsfiles.– D. Ben Knoble ♦Commented Apr 9, 2019 at 6:14
-
Don't really need it, just curious.– dedowsdiCommented Apr 9, 2019 at 6:32
Add a comment
|
1 Answer
There is nothing built in. But you might check lh-vim-lib.
It has the following functions working on sorted lists:
lh#list#equal_range()
lh#list#lower_bound()
lh#list#upper_bound()
-
1I do indeed provide these functions, but they are quite likely to be less efficient than a naive call to
filter()
. You'll have to measure both to see what's better suited to the data you're manipulating in your plugins. Commented Apr 9, 2019 at 11:09