Skip to content

Commit

Permalink
New, better algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
favonia committed Sep 25, 2018
1 parent 7e622f1 commit 8090938
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/basis/PersistentTable.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sig
val set : 'k -> 'a -> ('k, 'a) t -> ('k, 'a) t
val mem : 'k -> ('k, 'a) t -> bool
val remove : 'k -> ('k, 'a) t -> ('k, 'a) t
val set_opt : 'k -> 'a option -> ('k, 'a) t -> ('k, 'a) t
val find : 'k -> ('k, 'a) t -> 'a option
val fold : ('k-> 'a -> 'b -> 'b) -> ('k, 'a) t -> 'b -> 'b
val merge : ('k, 'a) t -> ('k, 'a) t -> ('k, 'a) t
Expand All @@ -24,7 +25,7 @@ struct
let init ~size =
ref @@ Tbl (Hashtbl.create size)

let set_opt tbl k ov =
let raw_set_opt tbl k ov =
match ov with
| None -> Hashtbl.remove tbl k
| Some v -> Hashtbl.replace tbl k v
Expand All @@ -39,7 +40,7 @@ struct
match !t' with
| Tbl a as n ->
let ov' = Hashtbl.find_opt a k in
set_opt a k ov;
raw_set_opt a k ov;
t := n;
t' := Diff (k, ov', t)
| _ ->
Expand Down Expand Up @@ -104,6 +105,11 @@ struct
| _ ->
raise Fatal

let set_opt k ov t =
match ov with
| None -> remove k t
| Some v -> set k v t

let fold f t e =
reroot t;
match !t with
Expand Down
1 change: 1 addition & 0 deletions src/basis/PersistentTable.mli
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sig
val set : 'k -> 'a -> ('k, 'a) t -> ('k, 'a) t
val mem : 'k -> ('k, 'a) t -> bool
val remove : 'k -> ('k, 'a) t -> ('k, 'a) t
val set_opt : 'k -> 'a option -> ('k, 'a) t -> ('k, 'a) t
val find : 'k -> ('k, 'a) t -> 'a option
val fold : ('k -> 'a -> 'b -> 'b) -> ('k, 'a) t -> 'b -> 'b
val merge : ('k, 'a) t -> ('k, 'a) t -> ('k, 'a) t
Expand Down
8 changes: 4 additions & 4 deletions src/core/NewRestriction.ml
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ let subst' r x h =
get_m h @@ subst r x h

let swap (x : atom) (y : atom) (h : t) =
if x == y then h else
let x', h = reserve_index_aux x h in
let y', h = reserve_index_aux y h in
{h with index = T.set y x' (T.set x y' h.index)}
match T.find x h.index, T.find y h.index with
| None, None -> h
| Some idx, Some idy when idx = idy -> h
| oidx, oidy -> {h with index = T.set_opt y oidx (T.set_opt x oidy h.index)}


let pp_cls fmt =
Expand Down

0 comments on commit 8090938

Please sign in to comment.