update dependencies (#6267)
Signed-off-by: hongming <coder.scala@gmail.com>
This commit is contained in:
45
vendor/github.com/open-policy-agent/opa/topdown/cache.go
generated
vendored
45
vendor/github.com/open-policy-agent/opa/topdown/cache.go
generated
vendored
@@ -9,6 +9,29 @@ import (
|
||||
"github.com/open-policy-agent/opa/util"
|
||||
)
|
||||
|
||||
// VirtualCache defines the interface for a cache that stores the results of
|
||||
// evaluated virtual documents (rules).
|
||||
// The cache is a stack of frames, where each frame is a mapping from references
|
||||
// to values.
|
||||
type VirtualCache interface {
|
||||
// Push pushes a new, empty frame of value mappings onto the stack.
|
||||
Push()
|
||||
|
||||
// Pop pops the top frame of value mappings from the stack, removing all associated entries.
|
||||
Pop()
|
||||
|
||||
// Get returns the value associated with the given reference. The second return value
|
||||
// indicates whether the reference has a recorded 'undefined' result.
|
||||
Get(ref ast.Ref) (*ast.Term, bool)
|
||||
|
||||
// Put associates the given reference with the given value. If the value is nil, the reference
|
||||
// is marked as having an 'undefined' result.
|
||||
Put(ref ast.Ref, value *ast.Term)
|
||||
|
||||
// Keys returns the set of keys that have been cached for the active frame.
|
||||
Keys() []ast.Ref
|
||||
}
|
||||
|
||||
type virtualCache struct {
|
||||
stack []*virtualCacheElem
|
||||
}
|
||||
@@ -19,7 +42,7 @@ type virtualCacheElem struct {
|
||||
undefined bool
|
||||
}
|
||||
|
||||
func newVirtualCache() *virtualCache {
|
||||
func NewVirtualCache() VirtualCache {
|
||||
cache := &virtualCache{}
|
||||
cache.Push()
|
||||
return cache
|
||||
@@ -77,6 +100,26 @@ func (c *virtualCache) Put(ref ast.Ref, value *ast.Term) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *virtualCache) Keys() []ast.Ref {
|
||||
node := c.stack[len(c.stack)-1]
|
||||
return keysRecursive(nil, node)
|
||||
}
|
||||
|
||||
func keysRecursive(root ast.Ref, node *virtualCacheElem) []ast.Ref {
|
||||
var keys []ast.Ref
|
||||
node.children.Iter(func(k, v util.T) bool {
|
||||
ref := root.Append(k.(*ast.Term))
|
||||
if v.(*virtualCacheElem).value != nil {
|
||||
keys = append(keys, ref)
|
||||
}
|
||||
if v.(*virtualCacheElem).children.Len() > 0 {
|
||||
keys = append(keys, keysRecursive(ref, v.(*virtualCacheElem))...)
|
||||
}
|
||||
return false
|
||||
})
|
||||
return keys
|
||||
}
|
||||
|
||||
func newVirtualCacheElem() *virtualCacheElem {
|
||||
return &virtualCacheElem{children: newVirtualCacheHashMap()}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user