-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[union-find] version with persistent map instead of "persistent" Hashtbl
- simple union find with Map and primitives union, find, create, merge - track id removed by merge of typeAssignment - remove ids from functional_preds accordingly - update small test on union find accordingly - update parallel test compilation
- Loading branch information
Showing
9 changed files
with
299 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,28 @@ | ||
open Elpi_compiler.Union_find | ||
|
||
module M = Make (struct | ||
include Int | ||
|
||
let hash x = x | ||
let pp _ _ = () | ||
end) | ||
module M = Make (Elpi_util.Util.IntMap) | ||
|
||
open M | ||
|
||
let _ = | ||
(* Partition avec 9 classes (qui sont des singletons) *) | ||
let uf = create () in | ||
|
||
for i = 1 to 8 do | ||
add uf i | ||
done; | ||
(* From https://fr.wikipedia.org/wiki/Union-find#/media/Fichier:Dsu_disjoint_sets_final.svg *) | ||
let uf = ref empty in | ||
let update uf (_,act) = uf := act in | ||
let union uf a b = update uf (union !uf a b) in | ||
|
||
(* Partition avec 4 classes disjointes obtenue après | ||
Union(1, 2), Union(3, 4), Union(2, 5), Union(1, 6) et Union(2, 8). *) | ||
union uf (1, 2); | ||
union uf (3, 4); | ||
union uf (2, 5); | ||
union uf 1 2; | ||
union uf 3 4; | ||
union uf 2 5; | ||
|
||
let uf1 = do_open (do_close uf) in | ||
let uf1 = ref !uf in | ||
|
||
union uf (1, 6); | ||
union uf (2, 8); | ||
assert (roots uf |> List.length = 3); | ||
union uf 1 6; | ||
union uf 3 1; | ||
assert (roots !uf |> List.length = 1); | ||
(* The cloned table is not impacted by the modification in uf *) | ||
(* uf should be: https://fr.wikipedia.org/wiki/Union-find#/media/Fichier:Dsu_disjoint_sets_final.svg *) | ||
assert (roots uf1 |> List.length = 5); | ||
union uf1 (1, 6); | ||
assert (roots uf1 |> List.length = 4); | ||
assert (roots uf |> List.length = 3) | ||
assert (roots !uf1 |> List.length = 2); | ||
union uf1 7 8; | ||
assert (roots !uf1 |> List.length = 3); | ||
assert (roots !uf |> List.length = 1) |
Oops, something went wrong.