MCPcopy
hub / github.com/google/mangle / Stratify

Function Stratify

analysis/stratification.go:79–101  ·  view source on GitHub ↗

Stratify checks whether a program can be stratified. It returns strongly-connected components and a map from predicate to stratum in the affirmative case, an error otherwise. The result list of strata is topologically sorted. Stratification means separating a list of intensional predicate symbols wi

(program Program)

Source from the content-addressed store, hash-verified

77// into strata (layers) such that each layer only depends on the
78// evaluation of negated atoms for idb predicates in lower layers.
79func Stratify(program Program) ([]Nodeset, map[ast.PredicateSym]int, error) {
80 dep := makeDepGraph(program)
81 strata := dep.sccs()
82 predToStratum := make(map[ast.PredicateSym]int)
83 for i, c := range strata {
84 for sym := range c {
85 predToStratum[sym] = i
86 }
87 for sym := range c {
88 for dest, negated := range dep[sym] {
89 if !negated {
90 continue
91 }
92 // "Negative" dependency in same stratum indicates recursion through negation.
93 if destStratum, ok := predToStratum[dest]; ok && destStratum == i {
94 return nil, nil, fmt.Errorf("program cannot be stratified")
95 }
96 }
97 }
98 }
99 strata, predToStratum = dep.sortResult(strata, predToStratum)
100 return strata, predToStratum, nil
101}
102
103func (dep depGraph) initNode(src ast.PredicateSym) {
104 if _, ok := dep[src]; !ok {

Callers 9

EvalProgramWithStatsFunction · 0.92
TestRewriteIdempotencyFunction · 0.92
TestEvalExternalFunction · 0.92
BenchmarkJoinFunction · 0.92
EvalProgramNaiveFunction · 0.92

Calls 3

makeDepGraphFunction · 0.85
sccsMethod · 0.80
sortResultMethod · 0.80

Tested by 7

TestRewriteIdempotencyFunction · 0.74
TestEvalExternalFunction · 0.74
BenchmarkJoinFunction · 0.74