interval-search provides predicate-based binary and doubling search implementations
- Free software: MIT license
- Documentation: https://interval-search.readthedocs.io.
import interval_search as inch
# inch.binary_search
list_ = [1, 10, 20, 500, 5000]
inch.binary_search(lambda x: list_[x] >= 20, 0, len(list_) - 1)
# -> 2
# inch.doubling_search
inch.doubling_search(lambda x: x >= 5) # -> 5
# with a lower bound to start searching at,
inch.doubling_search(lambda x: x >= 5, 10) # -> 10
# inch.interval_search
# uses binary search or doubling search
# depending on whether upper bound is specified
inch.interval_search(lambda x: list_[x] >= 20, 0, len(list_) - 1)
# -> 2
inch.interval_search(lambda x: x >= 5, 10) # -> 10
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.