package containers

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Extension to the standard Hashtbl

  • since 0.4
type 'a sequence = ('a -> unit) -> unit
type 'a eq = 'a -> 'a -> bool
type 'a hash = 'a -> int
type 'a printer = Format.formatter -> 'a -> unit

Polymorphic tables

val get : ('a, 'b) Hashtbl.t -> 'a -> 'b option

Safe version of Hashtbl.find

val keys : ('a, 'b) Hashtbl.t -> 'a sequence

Iterate on keys (similar order as Hashtbl.iter)

val values : ('a, 'b) Hashtbl.t -> 'b sequence

Iterate on values in the table

val keys_list : ('a, 'b) Hashtbl.t -> 'a list

keys_list t is the list of keys in t.

  • since 0.8
val values_list : ('a, 'b) Hashtbl.t -> 'b list

values_list t is the list of values in t.

  • since 0.8
val map_list : ('a -> 'b -> 'c) -> ('a, 'b) Hashtbl.t -> 'c list

Map on a hashtable's items, collect into a list

val to_seq : ('a, 'b) Hashtbl.t -> ('a * 'b) sequence

Iterate on bindings in the table

val of_seq : ('a * 'b) sequence -> ('a, 'b) Hashtbl.t

From the given bindings, added in order

val to_list : ('a, 'b) Hashtbl.t -> ('a * 'b) list

List of bindings (order unspecified)

val of_list : ('a * 'b) list -> ('a, 'b) Hashtbl.t

From the given list of bindings, added in order

val update : ('a, 'b) Hashtbl.t -> f:('a -> 'b option -> 'b option) -> k:'a -> unit

update tbl ~f ~k updates key k by calling f k (Some v) if k was mapped to v, or f k None otherwise; if the call returns None then k is removed/stays removed, if the call returns Some v' then the binding k -> v' is inserted using Hashtbl.replace

  • since 0.14
val print : 'a printer -> 'b printer -> ('a, 'b) Hashtbl.t printer

Printer for table

  • since 0.13

Functor

module type S = sig ... end
module Make (X : Hashtbl.HashedType) : S with type key = X.t and type 'a t = 'a Hashtbl.Make(X).t

Default Table

A table with a default element for keys that were never added.

module type DEFAULT = sig ... end
module MakeDefault (X : Hashtbl.HashedType) : DEFAULT with type key = X.t

Count occurrences using a Hashtbl

module type COUNTER = sig ... end
module MakeCounter (X : Hashtbl.HashedType) : COUNTER with type elt = X.t and type t = int Hashtbl.Make(X).t

Create a new counter type The type t is exposed

OCaml

Innovation. Community. Security.