(* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. *) open! NS0 (** Hash tables *) include HashTable_intf module Make (Key : HashedType) = struct include CCHashtbl.Make (Key) let create ?(size = 0) () = create size let set tbl ~key ~data = replace tbl key data let add_multi tbl ~key ~data = update tbl ~k:key ~f:(fun _ -> function | None -> Some [data] | Some datas -> Some (data :: datas) ) let find_exn = find let find = find_opt let find_or_add tbl key ~default = let found = ref None in update tbl ~k:key ~f:(fun _ -> function | None -> let v = default () in found := Some v ; Some v | Some v -> found := Some v ; Some v ) ; Option.value_exn !found let iteri tbl ~f = iter (fun key data -> f ~key ~data) tbl let fold tbl ~init ~f = fold (fun key data acc -> f ~key ~data acc) tbl init end