package containers
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=d84e09c5d0abc501aa17cd502e31a038
sha512=8b832f4ada6035e80d81be0cfb7bdffb695ec67d465ed6097a144019e2b8a8f909095e78019c3da2d8181cc3cd730cd48f7519e87d3162442562103b7f36aabb
doc/containers/CCArray_sliceLabels/index.html
Module CCArray_sliceLabelsSource
Array Slice
Fast internal iterator.
The type for an array slice, containing elements of type 'a
equal eq as1 as2 is true if the lengths of as1 and as2 are the same and if the corresponding elements test equal using eq.
compare cmp as1 as2 compares the two slices as1 and as2 using the comparison function cmp, element by element.
get as n returns the element number n of slice as. The first element has number 0. The last element has number length as - 1. You can also write as.(n) instead of get as n.
Raise Invalid_argument "index out of bounds" if n is outside the range 0 to (length as - 1).
get_safe as i returns Some as.(i) if i is a valid index.
make a i ~len creates a slice from given offset i and length len of the given array a.
of_slice (a, i, len) makes a slice from a triple (a, i, len) where a is the array, i the offset in a, and len the number of elements of the slice.
to_slice as converts the slice as into a triple (a, i, len) where len is the length of the sub-array of a starting at offset i.
underlying as returns the underlying array (shared). Modifying this array will modify the slice as.
sub as i len builds a new sub-slice that contains the given subrange specified by the index i and the length len.
set as n x modifies the slice as in place, replacing element number n with x. You can also write as.(n) <- x instead of set as n x.
Raise Invalid_argument "index out of bounds" if n is outside the range 0 to length as - 1.
length as returns the length (number of elements) of the given slice as.
fold f acc as computes f (... (f (f acc as.(0)) as.(1)) ...) as.(length as - 1).
foldi f acc as is just like fold but it also passes in the index of each element as the second argument to the folded function f.
fold_while f acc as folds left on slice as until a stop condition via ('a, `Stop) is indicated by the accumulator.
iter f as applies function f in turn to all elements of as. It is equivalent to f as.(0); f as.(1); ...; f as.(length as - 1); ().
iteri f as is like iter, but the function f is applied with the index of the element as first argument, and the element itself as second argument.
blit as1 o1 as2 o2 len copies len elements from slice as1, starting at element number o1, to slice as2, starting at element number o2. It works correctly even if as1 and as2 are the same slice, and the source and destination chunks overlap.
Raise Invalid_argument "CCArray_slice.blit" if o1 and len do not designate a valid subarray of as1, or if o2 and len do not designate a valid subarray of as2.
sorted cmp as makes a copy of as and sorts it with cmp.
sort_indices cmp as returns a new array b, with the same length as as, such that b.(i) is the index at which the i-th element of sorted cmp as appears in as. as is not modified.
In other words, map (fun i -> as.(i)) (sort_indices cmp as) = sorted cmp as. sort_indices yields the inverse permutation of sort_ranking.
sort_ranking cmp as returns a new array b, with the same length as as, such that b.(i) is the index at which the i-th element of as appears in sorted cmp as. as is not modified.
In other words, map (fun i -> (sorted cmp as).(i)) (sort_ranking cmp as) = as. sort_ranking yields the inverse permutation of sort_indices.
In the absence of duplicate elements in as, we also have lookup_exn as.(i) (sorted as) = (sorted_ranking as).(i).
find f as returns Some y if there is an element x such that f x = Some y. Otherwise returns None.
findi f as is like find, but the index of the element is also passed to the predicate function f.
find_idx p as returns Some (i,x) where x is the i-th element of as, and p x holds. Otherwise returns None.
lookup ~cmp x as lookups the index i of some key x in the slice as, provided as is sorted using cmp.
val bsearch :
cmp:('a -> 'a -> int) ->
'a ->
'a t ->
[ `All_lower | `All_bigger | `Just_after of int | `Empty | `At of int ]bsearch ~cmp x as finds the index of the object x in the slice as, provided as is sorted using cmp. If the slice is not sorted, the result is not specified (may raise Invalid_argument).
Complexity: O(log n) where n is the length of the slice as (dichotomic search).
for_all p [|as1; ...; asn|] checks if all elements of the slice satisfy the predicate p. That is, it returns (p as1) && (p as2) && ... && (p asn).
for_all2 p [|as1; ...; asn|] [|bs1; ...; bsn|] is true if each pair of elements asi bsi satisfies the predicate p. That is, it returns (p as1 bs1) && (p as2 bs2) && ... && (p asn bsn).
exists p [|as1; ...; asn|] is true if at least one element of the slice satisfies the predicate p. That is, it returns (p as1) || (p as2) || ... || (p asn).
exists2 p [|as1; ...; asn|] [|bs1; ...; bsn|] is true if any pair of elements asi bsi satisfies the predicate p. That is, it returns (p as1 bs1) || (p as2 bs2) || ... || (p asn bsn).
fold2 f acc as bs fold on two slices as and bs stepwise. It computes f (... (f acc as1 bs1)...) asn bsn.
iter2 f as bs iterates on the two slices as and bs stepwise. It is equivalent to f as0 bs0; ...; f as.(length as - 1) bs.(length bs - 1); ().
shuffle_with rs as randomly shuffles the slice as (like shuffle) but a specialized random state rs is used to control the random numbers being produced during shuffling (for reproducibility).
random_choose as rs randomly chooses an element of as.
to_iter a returns an iter of the elements of a slice a. The input array a is shared with the sequence and modification of it will result in modification of the iterator.
to_std_seq a returns a Seq.t of the elements of a slice a. The input array a is shared with the sequence and modification of it will result in modification of the sequence.
IO
pp ~sep pp_item ppf as formats the slice as on ppf. Each element is formatted with pp_item and elements are separated by sep (defaults to ", ").