Skip to content

Commit 66c0663

Browse files
committed
Use the Heap of Alt-Ergo
1 parent 4c60d5f commit 66c0663

10 files changed

Lines changed: 98 additions & 72 deletions

File tree

alt-ergo-lib.opam

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ depends: [
3131
"odoc" {with-doc}
3232
"ppx_deriving"
3333
"stdcompat"
34-
"bheap"
3534
]
3635
conflicts: [
3736
"ppxlib" {< "0.30.0"}

alt-ergo-lib.opam.locked

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ depends: [
6262
"uutf" {= "1.0.3"}
6363
"yojson" {= "2.1.1"}
6464
"zarith" {= "1.13"}
65-
"bheap" {= "2.0.0"}
6665
]
6766
build: [
6867
["dune" "subst"] {dev}

dune-project

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ See more details on http://alt-ergo.ocamlpro.com/"
9191
(odoc :with-doc)
9292
ppx_deriving
9393
stdcompat
94-
bheap
9594
)
9695
(conflicts
9796
(ppxlib (< 0.30.0))

shell.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,5 @@ pkgs.mkShell {
4343
stdcompat
4444
landmarks
4545
landmarks-ppx
46-
bheap
4746
];
4847
}

src/lib/dune

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
alt_ergo_prelude
2626
fmt
2727
stdcompat
28-
bheap
2928
)
3029
(preprocess
3130
(pps

src/lib/frontend/typechecker.ml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2567,11 +2567,6 @@ let rec type_decl (acc, env) d assertion_stack =
25672567
| TypeDecl l ->
25682568
let not_rec, are_rec = partition_non_rec l in
25692569

2570-
let not_rec, are_rec =
2571-
if Lists.is_empty are_rec then not_rec, are_rec
2572-
else [], List.rev_append not_rec are_rec
2573-
in
2574-
25752570
(* A. Typing types that are not recursive *)
25762571
let acc, env =
25772572
List.fold_left

src/lib/reasoners/satml.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ end
143143
module MFF = FF.Map
144144
module SFF = FF.Set
145145

146-
module Vheap = Heap.Make(struct
146+
module Vheap = Heap.MakeRanked(struct
147147
type t = Atom.var
148148

149149
let index (a : t) = a.hindex
@@ -478,7 +478,7 @@ module Make (Th : Theory.S) : SAT_ML with type th = Th.t = struct
478478

479479
simpDB_props = 0;
480480

481-
order = Vheap.make 0 Atom.dummy_var; (* sera mis a jour dans solve *)
481+
order = Vheap.create 0 Atom.dummy_var; (* sera mis a jour dans solve *)
482482

483483
progress_estimate = 0.;
484484

@@ -1827,7 +1827,7 @@ module Make (Th : Theory.S) : SAT_ML with type th = Th.t = struct
18271827
env.next_split <- None;
18281828
pick_branch_aux env atom
18291829
| None ->
1830-
match Vheap.remove_min env.order with
1830+
match Vheap.pop_minimum env.order with
18311831
| v -> pick_branch_aux env v.na
18321832
| exception Not_found ->
18331833
if Options.get_cdcl_tableaux_inst () then

src/lib/util/heap.ml

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,41 +35,15 @@ module type RankedType = sig
3535
val compare : t -> t -> int
3636
end
3737

38-
module type S = sig
39-
type elt
40-
41-
type t
42-
43-
val make : int -> elt -> t
44-
45-
val in_heap : elt -> bool
46-
47-
val decrease : t -> elt -> unit
48-
49-
val increase : t -> elt -> unit
50-
51-
val size : t -> int
52-
53-
val is_empty : t -> bool
54-
55-
val insert : t -> elt -> unit
56-
57-
val grow_to_by_double : t -> int -> unit
58-
59-
val remove_min : t -> elt
60-
61-
val filter : t -> (elt -> bool) -> unit
62-
end
63-
64-
module Make(Rank : RankedType) = struct
38+
module MakeRanked(Rank : RankedType) = struct
6539
type elt = Rank.t
6640

6741
type t = { heap : elt Vec.t } [@@unboxed]
6842

6943
(* Negative value; used to indicate an element is not in the heap *)
7044
let absent = -1
7145

72-
let make sz dummy = { heap = Vec.make ~dummy sz }
46+
let create sz dummy = { heap = Vec.make ~dummy sz }
7347

7448
let[@inline] left i = (i lsl 1) + 1 (* i*2 + 1 *)
7549
let[@inline] right i = (i + 1) lsl 1 (* (i + 1) * 2*)
@@ -148,7 +122,7 @@ module Make(Rank : RankedType) = struct
148122
let[@inline] grow_to_by_double { heap } sz =
149123
Vec.grow_to_by_double heap sz
150124

151-
let remove_min ({ heap } as s) =
125+
let pop_minimum ({ heap } as s) =
152126
match Vec.size heap with
153127
| 0 -> raise Not_found
154128
| 1 ->
@@ -165,3 +139,36 @@ module Make(Rank : RankedType) = struct
165139
if Vec.size s.heap > 1 then percolate_down s y;
166140
x
167141
end
142+
143+
module type OrderedTypeDefault = sig
144+
type t
145+
146+
val compare : t -> t -> int
147+
148+
val default : t
149+
end
150+
151+
module MakeOrdered(V : OrderedTypeDefault) = struct
152+
type entry = { value : V.t ; mutable index : int }
153+
type elt = V.t
154+
155+
module H = MakeRanked
156+
(struct
157+
type t = entry
158+
159+
let index e = e.index
160+
161+
let set_index e i = e.index <- i
162+
163+
let compare x y = V.compare x.value y.value
164+
end)
165+
166+
let entry value = { value ; index = -1 }
167+
168+
type t = H.t
169+
170+
let create n = H.create n (entry V.default)
171+
let is_empty = H.is_empty
172+
let insert h v = H.insert h (entry v)
173+
let pop_minimum h = (H.pop_minimum h).value
174+
end

src/lib/util/heap.mli

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,14 @@ end
6262

6363
(** {2 Priority heaps} *)
6464

65-
module type S = sig
66-
type elt
65+
module MakeRanked(Rank : RankedType) : sig
66+
type elt = Rank.t
67+
(** The type of elements of the heap. *)
6768

6869
type t
6970
(** The type of heaps. *)
7071

71-
val make : int -> elt -> t
72+
val create : int -> elt -> t
7273
(** Create a heap with the given initial size and dummy element. *)
7374

7475
val in_heap : elt -> bool
@@ -87,13 +88,13 @@ module type S = sig
8788
(** Is the heap empty ? *)
8889

8990
val insert : t -> elt -> unit
90-
(** Inset a new element in the heap. *)
91+
(** Insert a new element in the heap. *)
9192

9293
val grow_to_by_double: t -> int -> unit
9394
(** Grow the size of the heap by multiplying it by 2
9495
until it is at least the size specified. *)
9596

96-
val remove_min : t -> elt
97+
val pop_minimum : t -> elt
9798
(** Remove the minimum element from the heap and return it.
9899
99100
@raise Not_found if the heap is empty. *)
@@ -102,4 +103,35 @@ module type S = sig
102103
(** Filter elements in the heap. *)
103104
end
104105

105-
module Make(Rank : RankedType) : S with type elt = Rank.t
106+
(** {2 Ordered priority heaps} *)
107+
108+
module type OrderedTypeDefault = sig
109+
type t
110+
111+
val compare : t -> t -> int
112+
113+
val default : t
114+
(** Dummy value used in the heap. *)
115+
end
116+
117+
module MakeOrdered(V : OrderedTypeDefault) : sig
118+
type elt = V.t
119+
(** The type of elements of the heap. *)
120+
121+
type t
122+
(** The type of heaps. *)
123+
124+
val create : int -> t
125+
(** Create a heap with the given initial size. *)
126+
127+
val is_empty : t -> bool
128+
(** Is the heap empty ? *)
129+
130+
val insert : t -> elt -> unit
131+
(** Insert a new element in the heap. *)
132+
133+
val pop_minimum : t -> elt
134+
(** Remove the minimum element from the heap and return it.
135+
136+
@raise Not_found if the heap is empty. *)
137+
end

src/lib/util/nest.ml

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,21 @@ type node = {
7474
(* Type of a hyperedge. *)
7575
and edge = node list ref
7676

77-
module Heap = struct
78-
include Binary_heap.Make
79-
(struct
80-
type t = node
81-
let compare { weight = w1; _ } { weight = w2; _ } = w1 - w2
82-
end)
83-
84-
let create =
85-
let dummy_edge : node list ref = ref [] in
86-
let dummy = {
87-
id = Term.Const.Int.int "0" (* dummy *);
88-
outgoing = dummy_edge;
89-
in_degree = -1;
90-
weight = -1;
91-
}
92-
in
93-
create ~dummy
94-
end
77+
module Hp =
78+
Heap.MakeOrdered
79+
(struct
80+
type t = node
81+
let compare { weight = w1; _ } { weight = w2; _ } = w1 - w2
82+
83+
let default =
84+
let dummy_edge : node list ref = ref [] in
85+
{
86+
id = Term.Const.Int.int "0" (* dummy *);
87+
outgoing = dummy_edge;
88+
in_degree = -1;
89+
weight = -1;
90+
}
91+
end)
9592

9693
let (let*) = Option.bind
9794

@@ -117,9 +114,9 @@ let def_of_dstr dstr =
117114
118115
@return a heap that contains all the nodes of this graph without ingoing
119116
hyperedges. *)
120-
let build_graph (defs : ty_def list) : Heap.t =
117+
let build_graph (defs : ty_def list) : Hp.t =
121118
let map : (ty_def, edge) Hashtbl.t = Hashtbl.create 17 in
122-
let hp : Heap.t = Heap.create 17 in
119+
let hp : Hp.t = Hp.create 17 in
123120
List.iter (fun d -> Hashtbl.add map d (ref [])) defs;
124121
List.iter
125122
(fun def ->
@@ -152,7 +149,7 @@ let build_graph (defs : ty_def list) : Heap.t =
152149
) 0 dstrs
153150
in
154151
node.in_degree <- in_degree;
155-
if in_degree = 0 then Heap.add hp node
152+
if in_degree = 0 then Hp.insert hp node
156153
) cases
157154
) defs;
158155
hp
@@ -182,10 +179,10 @@ let add_cstr, find_weight, reinit =
182179
Kahn's algorithm. *)
183180
let add_nest n =
184181
let hp = build_graph n in
185-
while not @@ Heap.is_empty hp do
182+
while not @@ Hp.is_empty hp do
186183
(* Loop invariant: the set of nodes in heap [hp] is exactly
187184
the set of the nodes of the graph without ingoing hyperedge. *)
188-
let { id; outgoing; in_degree; _ } = Heap.pop_minimum hp in
185+
let { id; outgoing; in_degree; _ } = Hp.pop_minimum hp in
189186
add_cstr @@ Uid.of_dolmen id;
190187
assert (in_degree = 0);
191188
outgoing :=
@@ -194,7 +191,7 @@ let add_nest n =
194191
assert (node.in_degree > 0);
195192
let node = { node with in_degree = node.in_degree - 1 } in
196193
if node.in_degree = 0 then (
197-
Heap.add hp node;
194+
Hp.insert hp node;
198195
None
199196
) else (
200197
Some node

0 commit comments

Comments
 (0)