The unpac monorepo manager self-hosting as a monorepo using unpac
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

improved efficiency of Path.Check

the BFS does not enqueue vertices anymore when they have been
visited already

+63 -7
+5 -5
src/path.ml
··· 327 327 (* the path is not in cache; we check it with a BFS *) 328 328 let visited = HV.create 97 in 329 329 let q = Queue.create () in 330 + (* [visited] contains exactly the vertices that have been added to [q] *) 331 + let push v = 332 + if not (HV.mem visited v) then (HV.add visited v (); Queue.add v q) in 330 333 let rec loop () = 331 334 if Queue.is_empty q then begin 332 335 HVV.add pc.cache (v1, v2) false; ··· 337 340 if G.V.compare v v2 = 0 then 338 341 true 339 342 else begin 340 - if not (HV.mem visited v) then begin 341 - HV.add visited v (); 342 - G.iter_succ (fun v' -> Queue.add v' q) pc.graph v 343 - end; 343 + G.iter_succ push pc.graph v; 344 344 loop () 345 345 end 346 346 end 347 347 in 348 - Queue.add v1 q; 348 + push v1; 349 349 loop () 350 350 351 351 end
+5
tests/dune
··· 9 9 (modules test_topsort)) 10 10 11 11 (test 12 + (name test_check_path) 13 + (libraries graph) 14 + (modules test_check_path)) 15 + 16 + (test 12 17 (name test_map_vertex) 13 18 (libraries graph) 14 19 (modules test_map_vertex))
+52
tests/test_check_path.ml
··· 1 + 2 + (* Test file for Path.Check *) 3 + 4 + open Format 5 + open Graph 6 + open Pack.Digraph 7 + 8 + let test n edges = 9 + let v = Array.init n V.create in 10 + let g = create () in 11 + let () = Array.iter (add_vertex g) v in 12 + let build (s,t) = add_edge g v.(s) v.(t) in 13 + List.iter build edges; 14 + let path = PathCheck.check_path (PathCheck.create g) in 15 + for i = 0 to n - 1 do 16 + let seen = Array.make n false in 17 + let pre v = seen.(V.label v) <- true in 18 + Dfs.prefix_component pre g v.(i); 19 + for j = 0 to n - 1 do 20 + assert (seen.(j) = path v.(i) v.(j)) 21 + done 22 + done 23 + 24 + let () = 25 + test 3 [0,1; 1,2]; 26 + test 3 []; 27 + (* 1-cycle *) 28 + test 1 [0,0]; 29 + (* 2-cycle *) 30 + test 2 [0,1; 1,0]; 31 + test 3 [0,1; 1,0]; 32 + (* 2-cycle with out edge *) 33 + test 3 [0,1; 1,0; 1,2]; 34 + test 3 [2,0; 0,2; 0,1]; 35 + test 3 [1,2; 2,1; 2,0]; 36 + (* 2 loops *) 37 + test 5 [1,2; 2,1; 2,0; 3,4; 4,3]; 38 + test 5 [1,2; 2,1; 2,0; 2,3; 3,4; 4,3]; 39 + (* 2-cycle with in edge *) 40 + test 3 [1,2; 2,1; 0,2]; 41 + test 3 [1,2; 2,1; 0,1]; 42 + (* 2 cycles connected *) 43 + test 4 [0,1; 1,0; 2,3; 3,2; 2,1]; 44 + test 4 [0,1; 1,0; 2,3; 3,2; 1,2]; 45 + test 4 [0,1; 1,0; 2,3; 3,2; 1,2; 2,1]; 46 + (* 3-cycle with in and out edges *) 47 + test 5 [0,1; 1,2; 2,0; 3,0; 2,4]; 48 + (* 3 cycles in a row *) 49 + test 7 [0,1; 1,0; 1,2; 2,3; 3,2; 3,4; 4,5; 5,6; 6,4]; 50 + (* 3 cycles with 2 cycles in a cycle *) 51 + test 7 [0,1; 1,0; 1,2; 2,3; 3,2; 3,4; 4,5; 5,6; 6,4; 5,2]; 52 + printf "test check_path: all tests succeeded.@."
+1 -2
tests/test_topsort.ml
··· 66 66 let rec pow a = function 67 67 | 0 -> 1 68 68 | 1 -> a 69 - | n -> 69 + | n -> 70 70 let b = pow a (n / 2) in 71 71 b * b * (if n mod 2 = 0 then 1 else a) 72 72 ··· 80 80 el := [n-1,0]; for i = 0 to n-2 do el := (i,i+1) :: !el done; 81 81 test ~check:false Topological.iter n !el 82 82 done 83 -