mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 11:45:31 -05:00
renamed Graph to PersistentGraph, not to collide with OCamlGraph
This commit is contained in:
parent
97451b48a9
commit
a636c73f6d
5 changed files with 17 additions and 15 deletions
|
|
@ -4,10 +4,10 @@ Gen
|
||||||
FHashtbl
|
FHashtbl
|
||||||
FQueue
|
FQueue
|
||||||
FlatHashtbl
|
FlatHashtbl
|
||||||
Graph
|
|
||||||
Hashset
|
Hashset
|
||||||
Heap
|
Heap
|
||||||
LazyGraph
|
LazyGraph
|
||||||
|
PersistentGraph
|
||||||
PersistentHashtbl
|
PersistentHashtbl
|
||||||
PHashtbl
|
PHashtbl
|
||||||
Sequence
|
Sequence
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@ Gen
|
||||||
FHashtbl
|
FHashtbl
|
||||||
FQueue
|
FQueue
|
||||||
FlatHashtbl
|
FlatHashtbl
|
||||||
Graph
|
|
||||||
Hashset
|
Hashset
|
||||||
Heap
|
Heap
|
||||||
LazyGraph
|
LazyGraph
|
||||||
|
PersistentGraph
|
||||||
PersistentHashtbl
|
PersistentHashtbl
|
||||||
PHashtbl
|
PHashtbl
|
||||||
Sequence
|
Sequence
|
||||||
|
|
|
||||||
|
|
@ -4,38 +4,40 @@
|
||||||
open OUnit
|
open OUnit
|
||||||
open Helpers
|
open Helpers
|
||||||
|
|
||||||
|
module G = PersistentGraph
|
||||||
|
|
||||||
(* build a graph from a list of pairs of ints *)
|
(* build a graph from a list of pairs of ints *)
|
||||||
let mk_graph l =
|
let mk_graph l =
|
||||||
let g = Graph.empty 5 in
|
let g = G.empty 5 in
|
||||||
Graph.add_seq g
|
G.add_seq g
|
||||||
(Sequence.map (fun (x,y) -> x,1,y)
|
(Sequence.map (fun (x,y) -> x,1,y)
|
||||||
(Sequence.of_list l));
|
(Sequence.of_list l));
|
||||||
g
|
g
|
||||||
|
|
||||||
let test_copy () =
|
let test_copy () =
|
||||||
let g = mk_graph [0,1; 1,2; 2,3; 3,0] in
|
let g = mk_graph [0,1; 1,2; 2,3; 3,0] in
|
||||||
let g' = Graph.copy g in
|
let g' = G.copy g in
|
||||||
Graph.add g 1 1 3;
|
G.add g 1 1 3;
|
||||||
Graph.add g 1 2 3;
|
G.add g 1 2 3;
|
||||||
OUnit.assert_equal ~printer:print_int_list
|
OUnit.assert_equal ~printer:print_int_list
|
||||||
[1;2] (List.sort compare (Sequence.to_list (Graph.between g 1 3)));
|
[1;2] (List.sort compare (Sequence.to_list (G.between g 1 3)));
|
||||||
OUnit.assert_bool "copy" (Sequence.is_empty (Graph.between g' 1 3));
|
OUnit.assert_bool "copy" (Sequence.is_empty (G.between g' 1 3));
|
||||||
()
|
()
|
||||||
|
|
||||||
let test_roots () =
|
let test_roots () =
|
||||||
let g = mk_graph [0,1; 1,2; 2,3; 4,1; 5,1; 6,5; 3,5] in
|
let g = mk_graph [0,1; 1,2; 2,3; 4,1; 5,1; 6,5; 3,5] in
|
||||||
let roots = Sequence.to_list (Graph.roots g) in
|
let roots = Sequence.to_list (G.roots g) in
|
||||||
OUnit.assert_equal (List.sort compare roots) [0;4;6]
|
OUnit.assert_equal (List.sort compare roots) [0;4;6]
|
||||||
|
|
||||||
let test_leaves () =
|
let test_leaves () =
|
||||||
let g = mk_graph [0,1; 1,2; 2,3; 4,1; 6,5; 3,5; 3,7] in
|
let g = mk_graph [0,1; 1,2; 2,3; 4,1; 6,5; 3,5; 3,7] in
|
||||||
let leaves = Sequence.to_list (Graph.leaves g) in
|
let leaves = Sequence.to_list (G.leaves g) in
|
||||||
OUnit.assert_equal (List.sort compare leaves) [5;7]
|
OUnit.assert_equal (List.sort compare leaves) [5;7]
|
||||||
|
|
||||||
let test_dfs () =
|
let test_dfs () =
|
||||||
let g = mk_graph [0,1; 1,2; 2,3; 3,0; 1,4; 1,5; 5,6; 4,6; 6,0] in
|
let g = mk_graph [0,1; 1,2; 2,3; 3,0; 1,4; 1,5; 5,6; 4,6; 6,0] in
|
||||||
let l = ref [] in
|
let l = ref [] in
|
||||||
Graph.dfs g 0 (fun (v,i) -> l := (v,i) :: !l);
|
G.dfs g 0 (fun (v,i) -> l := (v,i) :: !l);
|
||||||
(* get index of vertex [v] in DFS traversal *)
|
(* get index of vertex [v] in DFS traversal *)
|
||||||
let get_idx v = List.assoc v !l in
|
let get_idx v = List.assoc v !l in
|
||||||
OUnit.assert_bool "order" (get_idx 0 < get_idx 1);
|
OUnit.assert_bool "order" (get_idx 0 < get_idx 1);
|
||||||
|
|
@ -49,7 +51,7 @@ let test_dfs () =
|
||||||
let test_bfs () =
|
let test_bfs () =
|
||||||
let g = mk_graph [0,1; 1,2; 2,3; 2,4; 3,0; 1,4; 1,5; 5,6; 4,6; 6,0] in
|
let g = mk_graph [0,1; 1,2; 2,3; 2,4; 3,0; 1,4; 1,5; 5,6; 4,6; 6,0] in
|
||||||
let l = Sequence.to_list
|
let l = Sequence.to_list
|
||||||
(Sequence.mapi (fun i v -> (v,i)) (Graph.bfs_seq g 0)) in
|
(Sequence.mapi (fun i v -> (v,i)) (G.bfs_seq g 0)) in
|
||||||
(* get index of vertex [v] in DFS traversal *)
|
(* get index of vertex [v] in DFS traversal *)
|
||||||
let get_idx v = List.assoc v l in
|
let get_idx v = List.assoc v l in
|
||||||
OUnit.assert_bool "order" (get_idx 0 < get_idx 1);
|
OUnit.assert_bool "order" (get_idx 0 < get_idx 1);
|
||||||
|
|
@ -71,8 +73,8 @@ and pp_edge formatter (v1,e,v2) =
|
||||||
|
|
||||||
let test_dijkstra () =
|
let test_dijkstra () =
|
||||||
let g = mk_graph [0,1; 1,2; 2,3; 3,4; 3,0; 4,5; 1,5; 5,6; 4,6; 6,0] in
|
let g = mk_graph [0,1; 1,2; 2,3; 3,4; 3,0; 4,5; 1,5; 5,6; 4,6; 6,0] in
|
||||||
let path = Graph.min_path g ~cost:(fun x -> x) 0 6 in
|
let path = G.min_path g ~cost:(fun x -> x) 0 6 in
|
||||||
let path = Graph.rev_path path in
|
let path = G.rev_path path in
|
||||||
OUnit.assert_equal ~printer:pp_path [0,1,1; 1,1,5; 5,1,6] path;
|
OUnit.assert_equal ~printer:pp_path [0,1,1; 1,1,5; 5,1,6] path;
|
||||||
()
|
()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue