package util
import "github.com/open-policy-agent/opa/util"
Index ¶
- func Compare(a, b interface{}) int
- type DFSTraversal
- type HashMap
- func NewHashMap(eq func(T, T) bool, hash func(T) int) *HashMap
- func (h *HashMap) Copy() *HashMap
- 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.
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) 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 graph.go hashmap.go
- Version
- v0.1.0-rc2
- Published
- Jun 7, 2016
- Platform
- js/wasm
- Imports
- 3 packages
- Last checked
- 3 minutes ago –
Tools for package owners.