package util
import "github.com/open-policy-agent/opa/util"
Package util provides generic utilities used throughout the policy engine.
Index ¶
- func Compare(a, b interface{}) int
- func MustMarshalJSON(x interface{}) []byte
- func MustUnmarshalJSON(bs []byte) interface{}
- func NewJSONDecoder(r io.Reader) *json.Decoder
- func UnmarshalJSON(bs []byte, x interface{}) (err error)
- type DFSTraversal
- type HashMap
- func NewHashMap(eq func(T, T) bool, hash func(T) int) *HashMap
- func (h *HashMap) Copy() *HashMap
- func (h *HashMap) Delete(k T)
- func (h *HashMap) Equal(other *HashMap) bool
- func (h *HashMap) Get(k T) (T, bool)
- func (h *HashMap) Hash() int
- func (h *HashMap) Iter(iter func(T, T) bool) bool
- func (h *HashMap) Len() int
- func (h *HashMap) Put(k T, v T)
- func (h *HashMap) String() string
- func (h *HashMap) Update(other *HashMap) *HashMap
- type T
Functions ¶
func Compare ¶
func Compare(a, b interface{}) int
Compare returns 0 if a equals b, -1 if a is less than b, and 1 if b is than a.
For comparison between values of different types, the following ordering is used: nil < bool < float64 < string < []interface{} < map[string]interface{}. Slices and maps are compared recursively. If one slice or map is a subset of the other slice or map it is considered "less than". Nil is always equal to nil.
func MustMarshalJSON ¶
func MustMarshalJSON(x interface{}) []byte
MustMarshalJSON returns the JSON encoding of x
If the data cannot be encoded, this function will panic. This function is for test purposes.
func MustUnmarshalJSON ¶
func MustUnmarshalJSON(bs []byte) interface{}
MustUnmarshalJSON parse the JSON encoded data and returns the result.
If the data cannot be decoded, this function will panic. This function is for test purposes.
func NewJSONDecoder ¶
NewJSONDecoder returns a new decoder that reads from r.
This function is intended to be used in place of the standard json.NewDecoder when json.Number is required.
func UnmarshalJSON ¶
UnmarshalJSON parses the JSON encoded data and stores the result in the value pointed to by x.
This function is intended to be used in place of the standard json.Marshal function when json.Number is required.
Types ¶
type DFSTraversal ¶
type DFSTraversal interface { // Edges should return the neighbours of node "u". Edges(u T) []T // Equals should return true if node "u" equals node "v". Equals(u T, v T) bool // Visited should return true if node "u" has already been visited in this // traversal. If the same traversal is used multiple times, the state that // tracks visited nodes should be reset. Visited(u T) bool }
DFSTraversal defines the basic interface required to perform a depth first traveral.
type HashMap ¶
type HashMap struct {
// contains filtered or unexported fields
}
HashMap represents a key/value map.
func NewHashMap ¶
NewHashMap returns a new empty HashMap.
func (*HashMap) Copy ¶
Copy returns a shallow copy of this HashMap.
func (*HashMap) Delete ¶
Delete removes the the key k.
func (*HashMap) Equal ¶
Equal returns true if this HashMap equals the other HashMap. Two hash maps are equal if they contain the same key/value pairs.
func (*HashMap) Get ¶
Get returns the value for k.
func (*HashMap) Hash ¶
Hash returns the hash code for this hash map.
func (*HashMap) Iter ¶
Iter invokes the iter function for each element in the HashMap. If the iter function returns true, iteration stops and the return value is true. If the iter function never returns true, iteration proceeds through all elements and the return value is false.
func (*HashMap) Len ¶
Len returns the current size of this HashMap.
func (*HashMap) Put ¶
Put inserts a key/value pair into this HashMap. If the key is already present, the existing value is overwritten.
func (*HashMap) String ¶
func (*HashMap) Update ¶
Update returns a new HashMap with elements from the other HashMap put into this HashMap. If the other HashMap contains elements with the same key as this HashMap, the value from the other HashMap overwrites the value from this HashMap.
type T ¶
type T interface{}
T is a concise way to refer to T.
func DFS ¶
func DFS(t DFSTraversal, a, z T) []T
DFS returns a path from node a to node z found by performing a depth first traversal. If no path is found, an empty slice is returned.
Source Files ¶
compare.go doc.go graph.go hashmap.go json.go
Directories ¶
Path | Synopsis |
---|---|
util/test |
- Version
- v0.4.2
- Published
- Feb 10, 2017
- Platform
- js/wasm
- Imports
- 7 packages
- Last checked
- 4 minutes ago –
Tools for package owners.