0

Are there any built-in functions to search sorted list? Such as binary_search, lower_bound, upper_bound, etc.

3
  • 1
    I don't think so. I have used vimgrep to find something like that but came up empty.
    – 3N4N
    Commented 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.
    – dedowsdi
    Commented Apr 9, 2019 at 6:32

1 Answer 1

2

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()
1
  • 1
    I 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.