Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open Printf
- module IntSet =
- Set.Make (
- struct
- type t = int
- let compare = compare
- end)
- module IntSetHash =
- Hashtbl.Make (
- struct
- type t = IntSet.t
- let equal = IntSet.equal
- let hash s = IntSet.fold (fun x a -> a + x) s 0
- end)
- let rec interval a b =
- if a >= b then
- []
- else
- a::(interval (a+1) b)
- let rec insert x ys =
- match ys with
- [] -> [[x]]
- | y::ys' ->
- (x::ys)::(List.map (fun rs -> y::rs) (insert x ys'))
- let rec perm xs =
- match xs with
- [] -> [[]]
- | x::xs' ->
- List.flatten (List.map (insert x) (perm xs'))
- let test create reg iter length =
- let ht = create 0 in
- List.iter
- (fun xs ->
- let s = IntSet.of_list xs in
- reg ht s true)
- (perm (interval 0 5));
- printf "----------------------------------------\n";
- printf "%d\n" (length ht);
- iter
- (fun s _ ->
- printf "{ ";
- IntSet.iter
- (fun x -> printf "%d " x)
- s;
- printf "}\n")
- ht
- let () = test Hashtbl.create Hashtbl.replace Hashtbl.iter Hashtbl.length
- let () = test IntSetHash.create IntSetHash.replace IntSetHash.iter IntSetHash.length
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement