util

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2016 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package util provides generic utilities used throughout the policy engine.

Index

Constants

This section is empty.

Variables

This section is empty.

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 NewJSONDecoder added in v0.3.0

func NewJSONDecoder(r io.Reader) *json.Decoder

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 added in v0.3.0

func UnmarshalJSON(bs []byte, x interface{}) (err error)

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

func NewHashMap(eq func(T, T) bool, hash func(T) int) *HashMap

NewHashMap returns a new empty HashMap.

func (*HashMap) Copy

func (h *HashMap) Copy() *HashMap

Copy returns a shallow copy of this HashMap.

func (*HashMap) Delete

func (h *HashMap) Delete(k T)

Delete removes the the key k.

func (*HashMap) Equal

func (h *HashMap) Equal(other *HashMap) bool

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

func (h *HashMap) Get(k T) (T, bool)

Get returns the value for k.

func (*HashMap) Hash

func (h *HashMap) Hash() int

Hash returns the hash code for this hash map.

func (*HashMap) Iter

func (h *HashMap) Iter(iter func(T, T) bool) bool

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

func (h *HashMap) Len() int

Len returns the current size of this HashMap.

func (*HashMap) Put

func (h *HashMap) Put(k T, v T)

Put inserts a key/value pair into this HashMap. If the key is already present, the existing value is overwritten.

func (*HashMap) String

func (h *HashMap) String() string

func (*HashMap) Update

func (h *HashMap) Update(other *HashMap) *HashMap

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL