Binary search - Factor Documentation (original) (raw)

Binary search
Factor handbook » The language » Collections » Sequence operations

Prev: Sorting sequences
Next: Sets

The binary search algorithm allows elements to be located in sorted sequence in O(log n) time.
search ( ... seq quot: ( ... elt -- ... <=> ) -- ... i elt )

Variants of sequence words optimized for sorted sequences:

sorted-index ( obj seq -- i )

sorted-member? ( obj seq -- ? )
sorted-member-eq? ( obj seq -- ? )

See also
Ordering specifiers, Sorting sequences