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
函子 Map.Make
的輸入簽章。
module type S =sig
..end
函子 Map.Make
的輸出簽章。
module Make:
函子根據完全排序的型別,建立映射結構的實作。