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.

fixed bug in Eulerian.path

+16 -10
+8 -6
src/eulerian.ml
··· 189 189 | _, 0 -> rev xy :: list_of (eulerian_cycle out x) 190 190 | 0, _ -> xy :: list_of (eulerian_cycle out y) 191 191 | _ -> 192 - (* a bit of a pity to use list concatenation here, 193 - but this does not change the complexity *) 194 - list_of (eulerian_cycle out x) @ 195 - xy :: list_of (eulerian_cycle out y) 192 + let py = eulerian_cycle out y in 193 + (* caveat: the cycle from y may exhaust edges from x *) 194 + if out_degree out x = 0 then xy :: list_of py 195 + else list_of (eulerian_cycle out x) @ xy :: list_of py 196 + (* a bit of a pity to use list concatenation here, 197 + but this does not change the complexity *) 196 198 ) else ( 197 199 (* no edge x--y => add one, build a cycle, then remove it *) 198 200 let dummy = E.label (snd (any (H.find out x))) in ··· 216 218 let directed _g = 217 219 invalid_arg "Eulerian.path (directed graphs not yet supported)" 218 220 219 - let path g = 220 - if is_directed then directed g else undirected g 221 + let path = 222 + if is_directed then directed else undirected 221 223 222 224 let cycle g = 223 225 let p, c = path g in
+8 -4
tests/test_eulerian.ml
··· 89 89 assert (List.length p = (n+1)*(2*n+1)) 90 90 done 91 91 92 - (* let () = 93 - * let g, _ = Classic.grid ~n:2 ~m:3 in 94 - * assert (exists_path g); 95 - * assert (not (exists_cycle g)) *) 92 + let () = 93 + (* +---x---+ tricky one, as the edge x-y 94 + | | | connects two vertices on a cycle 95 + +---y---+ *) 96 + let g, _ = Classic.grid ~n:2 ~m:3 in 97 + let p, c = Eulerian.path g in 98 + assert (not c); 99 + assert (List.length p = 7) 96 100