Source

ocamlspot / utils.ml

Diff from to

File utils.ml

 
   let timed f v = gen_timed Unix.gettimeofday (-.) f v
 
+  let dev_inode path =
+    try
+      let st = Unix.lstat path in
+      Some (st.Unix.st_dev, st.Unix.st_ino)
+    with
+    | _ -> None
+
   module Process_times = struct
     type t = process_times
     let (-) pt1 pt2 = {
-      tms_utime = pt1.tms_utime  -. pt2.tms_utime;
-      tms_stime = pt1.tms_stime  -. pt2.tms_stime;
+      tms_utime  = pt1.tms_utime -. pt2.tms_utime;
+      tms_stime  = pt1.tms_stime -. pt2.tms_stime;
       tms_cutime = pt1.tms_utime -. pt2.tms_cutime;
       tms_cstime = pt1.tms_utime -. pt2.tms_cstime;
     }
       Hashtbl.replace tbl k v) kvs;
     tbl
 end
+
+module Hashset = struct
+  (* poorman's hash set by hashtbl *)
+  type 'a t = ('a, 'a) Hashtbl.t
+  
+  let create = Hashtbl.create
+  let add set x = Hashtbl.replace set x x
+  let remove = Hashtbl.remove
+  let mem = Hashtbl.mem
+  let find = Hashtbl.find
+  let find_opt t k = try Some (Hashtbl.find t k) with Not_found -> None
+  let iter f = Hashtbl.iter (fun v _ -> f v)
+  let fold f = Hashtbl.fold (fun v _ st -> f v st)
+  let elements = Hashtbl.length
+  let clear = Hashtbl.clear
+  
+  let of_list size vs = 
+    let set = create size in
+    List.iter (add set) vs;
+    set
+  
+  let to_list set = fold (fun x y -> x::y) set []
+end
+