let hash_unique2_mono l = letmodule StringHash = OCAMLHashtbl.Make( struct type t =string let equal (x :string)(y :string)= x = y let hash t =Hashtbl.hash t end) in let h = StringHash.create (List.length l)in letrec add acc = function | hd :: tl whennot(StringHash.mem h hd)->
StringHash.add h hd ();
add (hd :: acc) tl | _ :: tl ->
add acc tl |[]->
acc in
add [] l
even faster ...
If you specialize the hashtbl...
open ExtLib ;;
[...]
let hash_unique2_mono l =
let module StringHash = OCAMLHashtbl.Make(
struct
type t = string
let equal (x : string) (y : string) = x = y
let hash t = Hashtbl.hash t
end)
in
let h = StringHash.create (List.length l) in
let rec add acc =
function
| hd :: tl when not (StringHash.mem h hd) ->
StringHash.add h hd ();
add (hd :: acc) tl
| _ :: tl ->
add acc tl
| [] ->
acc
in
add [] l