Update dependencies (#5518)
This commit is contained in:
58
vendor/github.com/open-policy-agent/opa/internal/planner/rules.go
generated
vendored
58
vendor/github.com/open-policy-agent/opa/internal/planner/rules.go
generated
vendored
@@ -1,6 +1,7 @@
|
||||
package planner
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/open-policy-agent/opa/ast"
|
||||
@@ -82,7 +83,27 @@ func (t *ruletrie) Arity() int {
|
||||
|
||||
func (t *ruletrie) Rules() []*ast.Rule {
|
||||
if t != nil {
|
||||
return t.rules
|
||||
if t.rules == nil {
|
||||
return nil
|
||||
}
|
||||
rules := make([]*ast.Rule, len(t.rules), len(t.rules)+len(t.children)) // could be too little
|
||||
copy(rules, t.rules)
|
||||
|
||||
// NOTE(sr): We pull in one layer of children: the compiler ensures
|
||||
// that these are the only possible, relevant rule sources for a given
|
||||
// ref: If the trie is what we get for
|
||||
//
|
||||
// a.b.c = 1 { ... }
|
||||
// a.b[x] = 2 { ... }
|
||||
//
|
||||
// and we're retrieving a.b, we want Rules() to include the rule body
|
||||
// of a.b.c.
|
||||
for _, rs := range t.children {
|
||||
if r := rs[len(rs)-1].rules; r != nil {
|
||||
rules = append(rules, r...)
|
||||
}
|
||||
}
|
||||
return rules
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -144,6 +165,9 @@ func (t *ruletrie) LookupOrInsert(key ast.Ref) *ruletrie {
|
||||
}
|
||||
|
||||
func (t *ruletrie) Children() []ast.Value {
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
sorted := make([]ast.Value, 0, len(t.children))
|
||||
for key := range t.children {
|
||||
if t.Get(key) != nil {
|
||||
@@ -167,6 +191,38 @@ func (t *ruletrie) Get(k ast.Value) *ruletrie {
|
||||
return nodes[len(nodes)-1]
|
||||
}
|
||||
|
||||
func (t *ruletrie) DepthFirst(f func(*ruletrie) bool) {
|
||||
if f(t) {
|
||||
return
|
||||
}
|
||||
for _, rules := range t.children {
|
||||
for i := range rules {
|
||||
rules[i].DepthFirst(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *ruletrie) Depth() int {
|
||||
if len(t.Children()) == 0 {
|
||||
return 0
|
||||
}
|
||||
c := make([]int, 0, len(t.Children()))
|
||||
for _, nodes := range t.children {
|
||||
c = append(c, nodes[len(nodes)-1].Depth())
|
||||
}
|
||||
max := 0
|
||||
for i := range c {
|
||||
if max < c[i] {
|
||||
max = c[i]
|
||||
}
|
||||
}
|
||||
return max + 1
|
||||
}
|
||||
|
||||
func (t *ruletrie) String() string {
|
||||
return fmt.Sprintf("<ruletrie rules:%v children:%v>", t.rules, t.children)
|
||||
}
|
||||
|
||||
type functionMocksStack struct {
|
||||
stack []*functionMocksElem
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user