Data and Math
vsearch
Binary search, sorted insertion, a stable sort by key and top k selection.
Released v1.0.0 · 2026-09-28use "stdlib/search.ven"
print binary_search([1, 3, 5, 7, 9], 7)
Reference (14 functions)
API reference
binary_search(sorted_items, target)
Finds target in an ascending-sorted list, or reports it is absent.
binary_search([1, 3, 5, 7, 9], 7)insertion_point_left(sorted_items, value)
Gives back the leftmost index where value could be inserted to keep sorted_items sorted.
insertion_point_left([1, 3, 3, 5], 3)insertion_point_right(sorted_items, value)
Gives back the rightmost index where value could be inserted to keep sorted_items sorted.
insertion_point_right([1, 3, 3, 5], 3)insert_sorted(sorted_items, value)
Inserts value into sorted_items, keeping the result in ascending order.
insert_sorted([1, 3, 5, 9], 4)is_sorted(items)
Tests whether items is already in ascending, non-decreasing order.
is_sorted([1, 2, 2, 5])sort_by(items, key_fn)
Sorts items in ascending order by the key key_fn computes for each one.
sort_by(["banana", "kiwi", "apple"], make(w) give length(w))quickselect(items, k)
quickselect([5, 3, 8, 1, 9], 2)merge_sort(items)
Sorts items in ascending order with a standalone, recursive merge sort.
merge_sort([5, 3, 8, 1, 9])pdqsort(items)
Sorts items in ascending order with pattern-defeating quicksort.
pdqsort([5, 3, 8, 1, 9])pdqsort_with_comparison_count(items)
pdqsort_with_comparison_count(range_list(2000))timsort(items)
Sorts items in ascending order with a from-scratch Timsort: run detection, minrun-extension by insertion sort, the balanced-merge run stack, and galloping merges.
timsort([5, 3, 8, 1, 9])timsort_stats(items)
timsort_stats(range_list(2000))radix_sort_ints(items)
Sorts items (a List of Integers) in ascending order with LSD radix sort.
radix_sort_ints([170, -45, 75, -90, 802, 24, 2, 66])radix_sort_floats(items)
Sorts items (a List of finite Numbers) in ascending order with LSD radix sort over the float-bit-flip-style key above.
radix_sort_floats([3.14, -2.5, 0.0, -100.25, 42.0])