package vocal

  1. Overview
  2. Docs

Additional operations on arrays

search for value v in array a, between indices fromi inclusive and toi exclusive, using comparison function cmp. Returns an index where v occurs, or raises Not_found if no such index exists.

val binary_search_left : ('a -> 'a -> int) -> 'a array -> int -> int -> 'a -> int

search for value v in array a, between indices fromi inclusive and toi exclusive, using comparison function cmp. If v occurs in a, returns an index immediately to the left of the set of occurrences of v. Otherwise, returns an index where to insert v.

val binary_search_right : ('a -> 'a -> int) -> 'a array -> int -> int -> 'a -> int

search for value v in array a, between indices fromi inclusive and toi exclusive, using comparison function cmp. If v occurs in a, returns an index immediately to the right of the set of occurrences of v. Otherwise, returns an index where to insert v.

val binary_sort : ('a -> 'a -> int) -> 'a array -> int -> int -> unit

sort array a betweens indices fromi inclusive and toi exclusive using a binary insertion sort. Time complexity is quadratic, but number of comparisons is only linearithmic.

val knuth_shuffle : 'a array -> unit
OCaml

Innovation. Community. Security.