函子 Weak.Make

module Make: 
functor (H : Hashtbl.HashedType-> S with type data = H.t

建構弱雜湊集合結構實作的函子。 H.equal 不能是實體相等,因為只會將集合中元素的淺複製提供給它。

參數
H : Hashtbl.HashedType

type data 

儲存在表格中的元素類型。

type t 

包含 data 類型元素的表格類型。請注意,弱雜湊集合無法使用 output_valueMarshal 模組中的函式進行序列化。

val create : int -> t

create n 建立一個新的空弱雜湊集合,初始大小為 n。表格會隨著需要而增長。

val clear : t -> unit

從表格中移除所有元素。

val merge : t -> data -> data

merge t x 會回傳在 t 中找到的 x 實例(如果有的話),否則會將 x 新增至 t 並回傳 x

val add : t -> data -> unit

add t xx 新增至 t。如果 t 中已經有 x 的實例,則後續呼叫 findmerge 會回傳哪個實例是不確定的。

val remove : t -> data -> unit

remove t xt 中移除一個 x 的實例。如果 t 中沒有 x 的實例,則不執行任何動作。

val find : t -> data -> data

find t x 會回傳在 t 中找到的 x 實例。

val find_opt : t -> data -> data option

find_opt t x 會回傳在 t 中找到的 x 實例,如果沒有此元素,則回傳 None

val find_all : t -> data -> data list

find_all t x 會回傳在 t 中找到的所有 x 實例的列表。

val mem : t -> data -> bool

mem t x 如果 t 中至少有一個 x 的實例,則回傳 true,否則回傳 false。

val iter : (data -> unit) -> t -> unit

iter f t 以某種未指定的順序,針對 t 中的每個元素呼叫 f。如果 f 嘗試更改 t 本身,則未指定會發生什麼情況。

val fold : (data -> 'acc -> 'acc) -> t -> 'acc -> 'acc

fold f t init 計算 (f d1 (... (f dN init))),其中 d1 ... dNt 中的元素,順序未指定。如果 f 嘗試更改 t 本身,則未指定會發生什麼情況。

val count : t -> int

計算表格中的元素數量。 count t 的結果與 fold (fun _ n -> n+1) t 0 相同,但不會延遲釋放無效的元素。

val stats : t -> int * int * int * int * int * int

回傳表格的統計資訊。這些數字依序為:表格長度、條目數量、儲存桶長度總和、最小儲存桶長度、中位數儲存桶長度、最大儲存桶長度。