public async Task <List <int[]> > FindCyclesAsync(Graph graph, IProgress <int[]> progress, CancellationToken ct) { if (graph == null) { throw new ArgumentNullException(nameof(graph)); } if (progress == null) { throw new ArgumentNullException(nameof(progress)); } if (ct == null) { throw new ArgumentNullException(nameof(ct)); } return(await Task.Run(() => { var cycles = new ConcurrentHashSet <int[]>(new CycleComparer()); var iterator = new GraphIterator(graph); iterator.CycleDetected += cycle => { if (cycles.Add(cycle)) { progress.Report(cycle); } }; iterator.Iterate(ct); return cycles.ToList(); }, ct)); }
public List <int[]> FindCycles(Graph graph) { if (graph == null) { throw new ArgumentNullException(nameof(graph)); } var cycles = new HashSet <int[]>(new CycleComparer()); var iterator = new GraphIterator(graph); iterator.CycleDetected += c => cycles.Add(c); iterator.Iterate(); return(cycles.ToList()); }