library/array.m:
When doing a binary search using a user-supplied comparison function,
do not use the builtin term comparison operation to compare elements.
Use separate loops for binary_search and approx_binary_search, since
using the loop for approx_binary_search in the implementation of
binary_search executes some unnecessary extra tests.
Improve the documentation of both binary_search and approx_binary_search.
tests/general/array_binsearch.{m,exp}:
Rewrite this test case to make it much tougher, testing the operation
of binary_search and approx_binary_search with both the builtin and
user-supplied comparison operations, and in the presence of repeated
elements, and with automatic verification of the results.
Estimated hours taken: 2
Branches: main
Add approximate as well as exact binary search to array.m. An approximate
search looks for the index of the largest element in the array that is
not greater than the value for which we are searching. This is useful for,
say, finding which line number corresponds to a particular offset into a file.
NEWS:
Mention the new additions.
library/array.m:
Added approx_binary_search and binary_search predicates.
tests/general/Mmakefile:
tests/general/array_binsearch.m:
tests/general/array_binsearch.exp:
Test case.