package containers

  1. Overview
  2. Docs
A modular, clean and powerful extension of the OCaml standard library

Install

Dune Dependency

Authors

Maintainers

Sources

v2.8.1.tar.gz
md5=d84e09c5d0abc501aa17cd502e31a038
sha512=8b832f4ada6035e80d81be0cfb7bdffb695ec67d465ed6097a144019e2b8a8f909095e78019c3da2d8181cc3cd730cd48f7519e87d3162442562103b7f36aabb

doc/containers/CCArray_sliceLabels/index.html

Module CCArray_sliceLabelsSource

Array Slice

Sourcetype 'a sequence = ('a -> unit) -> unit
  • deprecated

    use 'a iter instead

Sourcetype 'a iter = ('a -> unit) -> unit

Fast internal iterator.

  • since 2.8
Sourcetype 'a klist = unit -> [ `Nil | `Cons of 'a * 'a klist ]
Sourcetype 'a gen = unit -> 'a option
Sourcetype 'a equal = 'a -> 'a -> bool
Sourcetype 'a ord = 'a -> 'a -> int
Sourcetype 'a random_gen = Random.State.t -> 'a
Sourcetype 'a printer = Format.formatter -> 'a -> unit
Sourcetype 'a t

The type for an array slice, containing elements of type 'a

Sourceval empty : 'a t

empty is the empty array slice.

Sourceval equal : 'a equal -> 'a t equal

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.

Sourceval compare : 'a ord -> 'a t ord

compare cmp as1 as2 compares the two slices as1 and as2 using the comparison function cmp, element by element.

Sourceval get : 'a t -> int -> 'a

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).

Sourceval get_safe : 'a t -> int -> 'a option

get_safe as i returns Some as.(i) if i is a valid index.

  • since 0.18
Sourceval make : 'a array -> int -> len:int -> 'a t

make a i ~len creates a slice from given offset i and length len of the given array a.

Sourceval of_slice : ('a array * int * int) -> 'a t

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.

Sourceval to_slice : 'a t -> 'a array * int * int

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.

Sourceval to_list : 'a t -> 'a list

to_list as converts the slice as directly to a list.

  • since 1.0
Sourceval full : 'a array -> 'a t

full a creates a slice that covers the full array a.

Sourceval underlying : 'a t -> 'a array

underlying as returns the underlying array (shared). Modifying this array will modify the slice as.

Sourceval copy : 'a t -> 'a array

copy as copies the slice as into a new array.

Sourceval sub : 'a t -> int -> int -> 'a t

sub as i len builds a new sub-slice that contains the given subrange specified by the index i and the length len.

Sourceval set : 'a t -> int -> 'a -> unit

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.

Sourceval length : _ t -> int

length as returns the length (number of elements) of the given slice as.

Sourceval fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a

fold f acc as computes f (... (f (f acc as.(0)) as.(1)) ...) as.(length as - 1).

Sourceval foldi : ('a -> int -> 'b -> 'a) -> 'a -> 'b t -> 'a

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.

Sourceval fold_while : ('a -> 'b -> 'a * [ `Stop | `Continue ]) -> 'a -> 'b t -> 'a

fold_while f acc as folds left on slice as until a stop condition via ('a, `Stop) is indicated by the accumulator.

  • since 0.8
Sourceval iter : ('a -> unit) -> 'a t -> unit

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); ().

Sourceval iteri : (int -> 'a -> unit) -> 'a t -> unit

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.

Sourceval blit : 'a t -> int -> 'a t -> int -> int -> unit

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.

Sourceval reverse_in_place : 'a t -> unit

reverse_in_place as reverses the slice as in place.

Sourceval sorted : ('a -> 'a -> int) -> 'a t -> 'a array

sorted cmp as makes a copy of as and sorts it with cmp.

  • since 1.0
Sourceval sort_indices : ('a -> 'a -> int) -> 'a t -> int array

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.

  • since 1.0
Sourceval sort_ranking : ('a -> 'a -> int) -> 'a t -> int array

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).

  • since 1.0
Sourceval find : ('a -> 'b option) -> 'a t -> 'b option

find f as returns Some y if there is an element x such that f x = Some y. Otherwise returns None.

Sourceval findi : (int -> 'a -> 'b option) -> 'a t -> 'b option

findi f as is like find, but the index of the element is also passed to the predicate function f.

  • since 0.3.4
Sourceval find_idx : ('a -> bool) -> 'a t -> (int * 'a) option

find_idx p as returns Some (i,x) where x is the i-th element of as, and p x holds. Otherwise returns None.

  • since 0.3.4
Sourceval lookup : cmp:'a ord -> 'a -> 'a t -> int option

lookup ~cmp x as lookups the index i of some key x in the slice as, provided as is sorted using cmp.

  • returns

    None if the key x is not present, or Some i (i the index of the key) otherwise.

Sourceval lookup_exn : cmp:'a ord -> 'a -> 'a t -> int

lookup_exn ~cmp x as is like lookup, but

  • raises Not_found

    if the key x is not present.

Sourceval 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).

  • returns
    • `At i if cmp as.(i) x = 0 (for some i).
    • `All_lower if all elements of as are lower than x.
    • `All_bigger if all elements of as are bigger than x.
    • `Just_after i if as.(i) < x < as.(i+1).
    • `Empty if the slice as is empty.
  • since 0.13
Sourceval for_all : ('a -> bool) -> 'a t -> bool

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).

Sourceval for_all2 : ('a -> 'b -> bool) -> 'a t -> 'b t -> bool

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).

  • since 0.20
Sourceval exists : ('a -> bool) -> 'a t -> bool

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).

Sourceval exists2 : ('a -> 'b -> bool) -> 'a t -> 'b t -> bool

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).

  • since 0.20
Sourceval fold2 : ('acc -> 'a -> 'b -> 'acc) -> 'acc -> 'a t -> 'b t -> 'acc

fold2 f acc as bs fold on two slices as and bs stepwise. It computes f (... (f acc as1 bs1)...) asn bsn.

  • since 0.20
Sourceval iter2 : ('a -> 'b -> unit) -> 'a t -> 'b t -> unit

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); ().

  • since 0.20
Sourceval shuffle : 'a t -> unit

shuffle as randomly shuffles the slice as, in place.

Sourceval shuffle_with : Random.State.t -> 'a t -> unit

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).

Sourceval random_choose : 'a t -> 'a random_gen

random_choose as rs randomly chooses an element of as.

  • raises Not_found

    if the array/slice is empty.

Sourceval to_iter : 'a t -> 'a iter

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.

  • since 2.8
Sourceval to_std_seq : 'a t -> 'a Seq.t

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.

  • since 2.8
Sourceval to_seq : 'a t -> 'a sequence
  • deprecated use to_iter or to_std_seq
Sourceval to_gen : 'a t -> 'a gen

to_gen as returns a gen of the elements of a slice as.

Sourceval to_klist : 'a t -> 'a klist
  • deprecated use to_std_seq

IO

Sourceval pp : ?sep:string -> 'a printer -> 'a t printer

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 ", ").

Sourceval pp_i : ?sep:string -> (int -> 'a printer) -> 'a t printer

pp_i ~sep pp_item ppf as prints the slice as on ppf. The printing function pp_item is giving both index and element. Elements are separated by sep (defaults to ", ").

OCaml

Innovation. Community. Security.

On This Page
  1. Array Slice
    1. IO