| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
type 'a f = 'a -> int * 'a |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
module type HashconsedType = |
| 22 |
sig |
| 23 |
type t |
| 24 |
val hashcons : t f |
| 25 |
val eq : t -> t -> bool |
| 26 |
end |
| 27 |
|
| 28 |
module type HashconsedRecType = sig |
| 29 |
type t |
| 30 |
|
| 31 |
val hashcons : t f -> t f |
| 32 |
|
| 33 |
val eq : t -> t -> bool |
| 34 |
|
| 35 |
end |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
module type S = |
| 43 |
sig |
| 44 |
type t |
| 45 |
type table |
| 46 |
val generate : unit -> table |
| 47 |
val hcons : table -> t f |
| 48 |
val stats : table -> Hashset.statistics |
| 49 |
end |
| 50 |
|
| 51 |
module Make (X : HashconsedType) : (S with type t = X.t) = |
| 52 |
struct |
| 53 |
type t = X.t |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
module Htbl = Hashset.Make(X) |
| 61 |
|
| 62 |
type table = Htbl.t |
| 63 |
|
| 64 |
let generate () = |
| 65 |
let tab = Htbl.create 97 in |
| 66 |
tab |
| 67 |
|
| 68 |
let hcons tab x = |
| 69 |
let h, y = X.hashcons x in |
| 70 |
h, Htbl.repr h y tab |
| 71 |
|
| 72 |
let stats = Htbl.stats |
| 73 |
|
| 74 |
end |
| 75 |
|
| 76 |
module MakeRec (X : HashconsedRecType) : (S with type t = X.t) = |
| 77 |
struct |
| 78 |
type t = X.t |
| 79 |
|
| 80 |
module Htbl = Hashset.Make(X) |
| 81 |
|
| 82 |
type table = Htbl.t |
| 83 |
|
| 84 |
let generate () = |
| 85 |
let tab = Htbl.create 97 in |
| 86 |
tab |
| 87 |
|
| 88 |
let rec hcons tab x = |
| 89 |
let h, y = X.hashcons (hcons tab) x in |
| 90 |
h, Htbl.repr h y tab |
| 91 |
|
| 92 |
let stats = Htbl.stats |
| 93 |
|
| 94 |
end |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
let simple_hcons h f u = |
| 103 |
let table = h u in |
| 104 |
fun x -> f table x |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
module type HashedType = sig |
| 110 |
type t |
| 111 |
val hcons : t f |
| 112 |
end |
| 113 |
|
| 114 |
|
| 115 |
module Hlist (D:HashedType) : S with type t = D.t list = |
| 116 |
struct |
| 117 |
module X = |
| 118 |
struct |
| 119 |
type t = D.t list |
| 120 |
let eq l1 l2 = |
| 121 |
l1 == l2 || |
| 122 |
match l1, l2 with |
| 123 |
| [], [] -> true |
| 124 |
| x1::l1, x2::l2 -> x1==x2 && l1==l2 |
| 125 |
| _ -> false |
| 126 |
end |
| 127 |
|
| 128 |
type t = X.t |
| 129 |
|
| 130 |
module Htbl = Hashset.Make(X) |
| 131 |
|
| 132 |
type table = Htbl.t |
| 133 |
|
| 134 |
let generate () = |
| 135 |
let tab = Htbl.create 97 in |
| 136 |
tab |
| 137 |
|
| 138 |
let rec hcons tab l = |
| 139 |
let h, l = match l with |
| 140 |
| [] -> 0, [] |
| 141 |
| x :: l -> |
| 142 |
let hx, x = D.hcons x in |
| 143 |
let h, l = hcons tab l in |
| 144 |
let h = Hashset.Combine.combine hx h in |
| 145 |
h, x :: l |
| 146 |
in |
| 147 |
h, Htbl.repr h l tab |
| 148 |
|
| 149 |
let stats = Htbl.stats |
| 150 |
|
| 151 |
end |
| 152 |
|
| 153 |
let hashcons_array hcons a = |
| 154 |
CArray.Smart.fold_left_map (fun acc x -> |
| 155 |
let hx, x = hcons x in |
| 156 |
Hashset.Combine.combine acc hx, x) |
| 157 |
0 |
| 158 |
a |