Skip to content

Commit

Permalink
Refactor: do not convert Set to Seq for folding
Browse files Browse the repository at this point in the history
  • Loading branch information
karoliineh committed May 3, 2024
1 parent ff9c282 commit 261f7b5
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/solver/sLR.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ module SLR3 =
HM.replace rho x tmp;
let w = try HM.find infl x with Not_found -> VS.empty in
let w = if wpx then VS.add x w else w in
q := Seq.fold_left (fun x y -> H.add y x) !q (VS.to_seq w);
q := VS.fold H.add w !q;
HM.replace infl x VS.empty;
Seq.iter (HM.remove stable) (VS.to_seq w)
VS.iter (HM.remove stable) w
end;
while (H.size !q <> 0) && (min_key q <= get_key x) do
solve (extract_min q)
Expand Down Expand Up @@ -107,7 +107,7 @@ module SLR3 =
HM.find rho y
and sides x =
let w = try HM.find set x with Not_found -> VS.empty in
Seq.fold_left (fun d z -> try S.Dom.join d (HPM.find rho' (z,x)) with Not_found -> d) (S.Dom.bot ()) (VS.to_seq w)
VS.fold (fun z d -> try S.Dom.join d (HPM.find rho' (z,x)) with Not_found -> d) w (S.Dom.bot ())
and side x y d =
HM.add globals y ();
if not (HM.mem rho y) then begin
Expand Down
6 changes: 3 additions & 3 deletions src/solver/sLRphased.ml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ module Make =
HM.replace rho x val_new;
let w = try HM.find infl x with Not_found -> VS.empty in
(* let w = if wpx then VS.add x w else w in *)
q := Seq.fold_left (fun x y -> H.add y x) !q (VS.to_seq w);
q := VS.fold H.add w !q;
HM.replace infl x VS.empty
end
and solve0 ?(side=false) x =
Expand Down Expand Up @@ -156,12 +156,12 @@ module Make =
HM.replace rho1 x d;
let w = VS.add x @@ try HM.find infl x with Not_found -> VS.empty in
HM.replace infl x VS.empty;
q := Seq.fold_left (fun x y -> H.add y x) !q (VS.to_seq w);
q := VS.fold H.add w !q;
iterate true prio
)
and sides x =
let w = try HM.find set x with Not_found -> VS.empty in
let v = Seq.fold_left (fun d z -> try S.Dom.join d (HPM.find rho' (z,x)) with Not_found -> d) (S.Dom.bot ()) (VS.to_seq w)
let v = VS.fold (fun z d -> try S.Dom.join d (HPM.find rho' (z,x)) with Not_found -> d) w (S.Dom.bot ())
in if tracing then trace "sol" "SIDES: Var: %a\nVal: %a" S.Var.pretty_trace x S.Dom.pretty v; v
and eq x get set =
eval_rhs_event x;
Expand Down
4 changes: 2 additions & 2 deletions src/solver/sLRterm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module SLR3term =
in
let sides x =
let w = try HM.find set x with Not_found -> VS.empty in
let v = Seq.fold_left (fun d z -> try S.Dom.join d (HPM.find rho' (z,x)) with Not_found -> d) (S.Dom.bot ()) (VS.to_seq w) in
let v = VS.fold (fun z d -> try S.Dom.join d (HPM.find rho' (z,x)) with Not_found -> d) w (S.Dom.bot ()) in
if tracing then trace "sol" "SIDES: Var: %a\nVal: %a" S.Var.pretty_trace x S.Dom.pretty v; v
in
let rec iterate b_old prio =
Expand Down Expand Up @@ -180,7 +180,7 @@ module SLR3term =
HM.replace rho x val_new;
let w = try HM.find infl x with Not_found -> VS.empty in
(* let w = if wpx then VS.add x w else w in *)
q := Seq.fold_left (fun x y -> H.add y x) !q (VS.to_seq w);
q := VS.fold H.add w !q;
HM.replace infl x VS.empty
end;
b_new
Expand Down
2 changes: 1 addition & 1 deletion src/solver/topDown.ml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ module WP =
HM.find rho y
and sides x =
let w = try HM.find set x with Not_found -> VS.empty in
let d = Seq.fold_left (fun d y -> let r = try S.Dom.join d (HPM.find rho' (y,x)) with Not_found -> d in if tracing then trace "sol2" "sides: side %a from %a: %a" S.Var.pretty_trace x S.Var.pretty_trace y S.Dom.pretty r; r) (S.Dom.bot ()) (VS.to_seq w) in
let d = VS.fold (fun y d -> let r = try S.Dom.join d (HPM.find rho' (y,x)) with Not_found -> d in if tracing then trace "sol2" "sides: side %a from %a: %a" S.Var.pretty_trace x S.Var.pretty_trace y S.Dom.pretty r; r) w (S.Dom.bot ()) in
if tracing then trace "sol2" "sides %a ## %a" S.Var.pretty_trace x S.Dom.pretty d;
d
and side x y d =
Expand Down
2 changes: 1 addition & 1 deletion src/solver/topDown_deprecated.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ module TD3 =
HM.find rho y
and sides x =
let w = try HM.find set x with Not_found -> VS.empty in
let d = Seq.fold_left (fun d z -> try S.Dom.join d (HPM.find rho' (z,x)) with Not_found -> d) (S.Dom.bot ()) (VS.to_seq w) in
let d = VS.fold (fun z d -> try S.Dom.join d (HPM.find rho' (z,x)) with Not_found -> d) w (S.Dom.bot ()) in
if tracing then trace "sol2" "sides %a ## %a" S.Var.pretty_trace x S.Dom.pretty d;
d
and side x y d =
Expand Down

0 comments on commit 261f7b5

Please sign in to comment.