package partition_map

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type +'a t
val empty : 'a t

Empty constructor.

val is_empty : 'a t -> bool

Test whether a ascending partition map is empty.

val of_descending : eq:'a equality -> 'a Descending.t -> 'a t

Convert a descending partition map into an ascending.

val of_ascending_interval_list : eq:'a equality -> ((int * int) * 'a) list -> 'a t

of_ascending_interval_list converts ascending pairs of intervals into an ascending partition map. For example: (0,100),'a'; (101,200), 'b'.

  • raises {Invalid_argument}

    If the first value of the pair in the first position is not 0 or the intervals are not ascending, or the values between the end and successive start are not adjacent (eg. next start = previous end + 1).

val init : size:int -> 'a -> 'a t

Initialize a partition map of the given size with one value.

val to_string : 'a t -> ('a -> string) -> string

Convert to a string.

val equal : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> bool

Test for equality.

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

get t i returns the value associated with the i'th domain element.

  • raises {Not_found}

    if i is outside the range 0, (size t)).

val set : 'a t -> int -> 'a -> 'a t

Set a value.

  • raises {Invalid_argument}

    if i is outside the range 0, (size t)).

val map : 'a t -> eq:'b equality -> f:('a -> 'b) -> 'b t

Map the values, the size of the domain does not change.

val merge : 'a t -> 'b t -> eq:('c -> 'c -> bool) -> f:('a -> 'b -> 'c) -> 'c t

Merge partition maps.

One can think of this as a "map2", but please see the note for why I chose to call them merges instead.

Merge takes a specific equality predicate because it compresses new values generated by the mapping. When we compute a new value from the 2 intersecting elements, we will scan an accumulator and add it if it is not equal to the other elements in the accumulator. Specifying, a good predicate for such an operation is important as it is intended to constrain the size of the final result.

  • raises Invalid_argument

    if the partition maps do not represent domains of the same size.

val merge3 : 'a t -> 'b t -> 'c t -> eq:('d -> 'd -> bool) -> f:('a -> 'b -> 'c -> 'd) -> 'd t

Merge 3 partition maps, see merge.

val merge4 : 'a t -> 'b t -> 'c t -> 'd t -> eq:('e -> 'e -> bool) -> f:('a -> 'b -> 'c -> 'd -> 'e) -> 'e t

Merge 5 partition maps, see merge.

val fold_values : 'a t -> f:('b -> 'a -> 'b) -> init:'b -> 'b
val fold_set_and_values : 'a t -> f:('b -> Set.t -> 'a -> 'b) -> init:'b -> 'b
val fold_indices_and_values : 'a t -> f:('b -> int -> 'a -> 'b) -> init:'b -> 'b

Fold over the indices 0,size) and values.

val iter_indices_and_values : 'a t -> f:(int -> 'a -> unit) -> unit
val to_array : 'a t -> 'a array
val size : 'a t -> int
val length : 'a t -> int
val descending : 'a t -> 'a Descending.t
val cpair : f:('a -> 'a -> 'b) -> eq:('b -> 'b -> bool) -> 'a t -> 'b t
OCaml

Innovation. Community. Security.