sorted-index ( obj seq -- i )
Factor handbook > The language > Collections > Sequence operations > Binary search

Prev:search ( seq quot: ( elt -- <=> ) -- i elt )
Next:sorted-member? ( obj seq -- ? )


Vocabulary
binary-search

Inputs and outputs
objan object
seqa sorted sequence
ian index, or f


Word description
Outputs the index of the element closest to elt in the sequence. See search for details.

Notes
If the sequence has at least one element, this word always outputs a valid index, because it finds the closest match, not necessarily an exact one. In this respect its behavior differs from index.

See also
index, index-from, last-index, last-index-from

Definition