module Map:sig
..end
基於排序型別的關聯表。
此模組實作了應用式關聯表,也稱為有限映射或字典,並給定鍵的完整排序函數。所有對映射的操作都是純應用式的(無副作用)。此實作使用平衡二元樹,因此搜尋和插入所需時間與映射的大小呈對數關係。
例如
module IntPairs =
struct
type t = int * int
let compare (x0,y0) (x1,y1) =
match Stdlib.compare x0 x1 with
0 -> Stdlib.compare y0 y1
| c -> c
end
module PairsMap = Map.Make(IntPairs)
let m = PairsMap.(empty |> add (0,1) "hello" |> add (1,0) "world")
這會建立一個新的模組 PairsMap
,其具有新的型別 'a PairsMap.t
,代表從 int * int
到 'a
的映射。在這個範例中,m
包含 string
值,因此它的型別為 string PairsMap.t
。
module type OrderedType =sig
..end
函子 MoreLabels.Map.Make
的輸入簽名。
module type S =sig
..end
函子 MoreLabels.Map.Make
的輸出簽名。
module Make:
函子建構給定完全排序型別的映射結構實作。