From b798ac29c37299b2f761243ae92ab8f7c4c4d7f1 Mon Sep 17 00:00:00 2001 From: Paweł Dybiec Date: Tue, 30 Oct 2018 15:32:56 +0100 Subject: Initial commit --- source/xi_lib/hashset.ml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 source/xi_lib/hashset.ml (limited to 'source/xi_lib/hashset.ml') diff --git a/source/xi_lib/hashset.ml b/source/xi_lib/hashset.ml new file mode 100644 index 0000000..455ba81 --- /dev/null +++ b/source/xi_lib/hashset.ml @@ -0,0 +1,30 @@ + +type 'a t = ('a, unit) Hashtbl.t + +let create () : 'a t = Hashtbl.create 101 + +let clear = Hashtbl.clear + +let add t x = Hashtbl.replace t x () + +let mem = Hashtbl.mem + +let to_seq t = Hashtbl.to_seq_keys t + +let length t = Hashtbl.length t + +let remove t v = Hashtbl.remove t v + +let iter f t = + let g k _ = f k in + Hashtbl.iter g t + + +let fold f t acc = + let g k () = f k in + Hashtbl.fold g t acc + +let of_seq seq : 'a t = + let result = create () in + Seq.iter (add result) seq; + result \ No newline at end of file -- cgit 1.4.1