hasCycles

hasCycles, function

def process hasCycles(src: text, dst: text): boolean

Returns true for edges (src, dst) that belong to a directed cycle.

Examples

Without grouping, cycles are detected across the full edge list.

table Edges = with
  [| as Src, as Dst |]
  [| "1", "2" |]
  [| "2", "3" |]
  [| "3", "1" |]
  [| "4", "5" |]
  [| "5", "5" |]

Edges.InCycle = hasCycles(Edges.Src, Edges.Dst)

show table "Cycles" with
  Edges.Src
  Edges.Dst
  Edges.InCycle

This produces the following table:

Src Dst InCycle
1 2 true
2 3 true
3 1 true
4 5 false
5 5 true

With by, cycles are detected independently per group.

table Edges = with
  [| as Src, as Dst, as Group |]
  [| "1", "2", "A" |]
  [| "2", "3", "A" |]
  [| "3", "1", "A" |]
  [| "4", "5", "B" |]
  [| "5", "5", "B" |]

Edges.InCycle = hasCycles(Edges.Src, Edges.Dst) by Edges.Group

show table "Cycles" with
  Edges.Group
  Edges.Src
  Edges.Dst
  Edges.InCycle

This produces the following table:

Group Src Dst InCycle
A 1 2 true
A 2 3 true
A 3 1 true
B 4 5 false
B 5 5 true

Remarks

Use by to detect cycles independently per group. Omitting by evaluates a single graph over all edges.

See also

User Contributed Notes
0 notes + add a note