package core_kernel
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=66f5353964d35a994ec7fdc88fe60ae5d497ac89a8042786f3e37d9e2202ce4b
md5=ede2f6d22eaa8320f88bac67d41b5cff
doc/core_kernel.total_map/Total_map/index.html
Module Total_map
A map that includes an entry for every possible value of the key type.
This is intended to be used on 'key types where there is a full enumeration of the type. In the common use case, 'key will be a simple variant type with [@@deriving compare, enumerate]. For example:
module Arrow_key = struct
module T = struct
type t =
| Up
| Down
| Left
| Right
[@@deriving sexp, bin_io, compare, enumerate]
end
include T
module Total_map = Total_map.Make (T)
endIn such a case, a t is semantically equivalent to a pure function from 'key to 'value. The differences are that it is serializable and that mapping or changing a t will produce a t using the same amount of space as the original.
However, in theory you could also modify the comparison function and enumeration, so long as the enumeration contains at least one representative of each equivalence class determined by the comparison function.
module Enumeration : sig ... endtype ('key, 'a, 'cmp, 'enum) t = private ('key, 'a, 'cmp) Core_kernel.Map.tval to_map : ('key, 'a, 'cmp, _) t -> ('key, 'a, 'cmp) Core_kernel.Map.tMany of the functions below have types reflecting the fact that the maps are total (e.g., find does not return an option). The fact that they won't raise exceptions relies on the enumeration passed to Make being complete.
val iter_keys : ('key, _, _, _) t -> f:('key -> unit) -> unitval iter : (_, 'a, _, _) t -> f:('a -> unit) -> unitval iteri : ('key, 'a, _, _) t -> f:(key:'key -> data:'a -> unit) -> unitval fold :
('key, 'a, _, _) t ->
init:'acc ->
f:(key:'key -> data:'a -> 'acc -> 'acc) ->
'accval fold_right :
('key, 'a, _, _) t ->
init:'acc ->
f:(key:'key -> data:'a -> 'acc -> 'acc) ->
'accval fold2 :
('key, 'a, 'cmp, 'enum) t ->
('key, 'b, 'cmp, 'enum) t ->
init:'acc ->
f:(key:'key -> 'a -> 'b -> 'acc -> 'acc) ->
'accFolds over two maps side by side, like iter2.
val to_alist :
?key_order:[ `Increasing | `Decreasing ] ->
('key, 'a, _, _) t ->
('key * 'a) listval find : ('key, 'a, _, _) t -> 'key -> 'aval data : (_, 'a, _, _) t -> 'a listval for_all : (_, 'a, _, _) t -> f:('a -> bool) -> boolmodule Sequence (A : Core_kernel.Applicative) : sig ... endSequence a total map of computations in order of their keys resulting in computation of the total map of results.
The only reason that the Applicative interface isn't included here is that we don't have an Applicative.S4.
module type Key = sig ... endmodule type Key_with_witnesses = sig ... endmodule type S = sig ... endmodule Make_with_witnesses
(Key : Key_with_witnesses) :
S
with module Key = Key
with type comparator_witness = Key.comparator_witness
with type enumeration_witness = Key.enumeration_witnessmodule Stable : sig ... end