Documentation
¶
Index ¶
- Variables
- func KeyByFields(nameValues ...interface{}) []value.Field
- type Path
- type PathElement
- type PathElementSet
- func (s *PathElementSet) Difference(s2 *PathElementSet) *PathElementSet
- func (s *PathElementSet) Equals(s2 *PathElementSet) bool
- func (s *PathElementSet) Has(pe PathElement) bool
- func (s *PathElementSet) Insert(pe PathElement)
- func (s *PathElementSet) Intersection(s2 *PathElementSet) *PathElementSet
- func (s *PathElementSet) Iterate(f func(PathElement))
- func (s *PathElementSet) Size() int
- func (s *PathElementSet) Union(s2 *PathElementSet) *PathElementSet
- type Set
- func (s *Set) Difference(s2 *Set) *Set
- func (s *Set) Empty() bool
- func (s *Set) Equals(s2 *Set) bool
- func (s *Set) Has(p Path) bool
- func (s *Set) Insert(p Path)
- func (s *Set) Intersection(s2 *Set) *Set
- func (s *Set) Iterate(f func(Path))
- func (s *Set) Size() int
- func (s *Set) String() string
- func (s *Set) Union(s2 *Set) *Set
- type SetNodeMap
- func (s *SetNodeMap) Descend(pe PathElement) *Set
- func (s *SetNodeMap) Difference(s2 *SetNodeMap) *SetNodeMap
- func (s *SetNodeMap) Empty() bool
- func (s *SetNodeMap) Equals(s2 *SetNodeMap) bool
- func (s *SetNodeMap) Get(pe PathElement) (*Set, bool)
- func (s *SetNodeMap) Intersection(s2 *SetNodeMap) *SetNodeMap
- func (s *SetNodeMap) Size() int
- func (s *SetNodeMap) Union(s2 *SetNodeMap) *SetNodeMap
Constants ¶
This section is empty.
Variables ¶
var AssociativeListCandidateFieldNames = []string{
"key",
"id",
"name",
}
AssociativeListCandidateFieldNames lists the field names which are considered keys if found in a list element.
Functions ¶
func KeyByFields ¶
KeyByFields is a helper function which constructs a key for an associative list type. `nameValues` must have an even number of entries, alternating names (type must be string) with values (type must be value.Value). If these conditions are not met, KeyByFields will panic--it's intended for static construction and shouldn't have user-produced values passed to it.
Types ¶
type Path ¶
type Path []PathElement
Path describes how to select a potentially deeply-nested child field given a containing object.
func MakePathOrDie ¶
func MakePathOrDie(parts ...interface{}) Path
MakePathOrDie panics if parts can't be turned into a path. Good for things that are known at complie time.
type PathElement ¶
type PathElement struct { // FieldName selects a single field from a map (reminder: this is also // how structs are represented). The containing object must be a map. FieldName *string // Key selects the list element which has fields matching those given. // The containing object must be an associative list with map typed // elements. Key []value.Field // Value selects the list element with the given value. The containing // object must be an associative list with a primitive typed element // (i.e., a set). Value *value.Value // Index selects a list element by its index number. The containing // object must be an atomic list. Index *int }
PathElement describes how to select a child field given a containing object.
func GuessBestListPathElement ¶
func GuessBestListPathElement(index int, item value.Value) PathElement
GuessBestListPathElement guesses whether item is an associative list element, which should be referenced by key(s), or if it is not and therefore referencing by index is acceptable. Currently this is done by checking whether item has any of the fields listed in AssociativeListCandidateFieldNames which have scalar values.
func (PathElement) String ¶
func (e PathElement) String() string
String presents the path element as a human-readable string.
type PathElementSet ¶
type PathElementSet struct {
// contains filtered or unexported fields
}
PathElementSet is a set of path elements. TODO: serialize as a list.
func (*PathElementSet) Difference ¶
func (s *PathElementSet) Difference(s2 *PathElementSet) *PathElementSet
Difference returns a set containing elements which appear in s but not in s2.
func (*PathElementSet) Equals ¶
func (s *PathElementSet) Equals(s2 *PathElementSet) bool
Equals returns true if s and s2 have exactly the same members.
func (*PathElementSet) Has ¶
func (s *PathElementSet) Has(pe PathElement) bool
Has returns true if pe is a member of the set.
func (*PathElementSet) Insert ¶
func (s *PathElementSet) Insert(pe PathElement)
Insert adds pe to the set.
func (*PathElementSet) Intersection ¶
func (s *PathElementSet) Intersection(s2 *PathElementSet) *PathElementSet
Intersection returns a set containing elements which appear in both s and s2.
func (*PathElementSet) Iterate ¶
func (s *PathElementSet) Iterate(f func(PathElement))
Iterate calls f for each PathElement in the set.
func (*PathElementSet) Size ¶
func (s *PathElementSet) Size() int
Size retuns the number of elements in the set.
func (*PathElementSet) Union ¶
func (s *PathElementSet) Union(s2 *PathElementSet) *PathElementSet
Union returns a set containing elements that appear in either s or s2.
type Set ¶
type Set struct { // Members lists fields that are part of the set. // TODO: will be serialized as a list of path elements. Members PathElementSet // Children lists child fields which themselves have children that are // members of the set. Appearance in this list does not imply membership. // Note: this is a tree, not an arbitrary graph. Children SetNodeMap }
Set identifies a set of fields.
func SetFromValue ¶
SetFromValue creates a set containing every leaf field mentioned in v.
func (*Set) Difference ¶
Difference returns a Set containing elements which appear in s but not in s2.
func (*Set) Empty ¶
Empty returns true if there are no members of the set. It is a separate function from Size since it's common to check whether size > 0, and potentially much faster to return as soon as a single element is found.
func (*Set) Insert ¶
Insert adds the field identified by `p` to the set. Important: parent fields are NOT added to the set; if that is desired, they must be added separately.
func (*Set) Intersection ¶
Intersection returns a Set containing elements which appear in both s and s2.
type SetNodeMap ¶
type SetNodeMap struct {
// contains filtered or unexported fields
}
SetNodeMap is a map of PathElement to subset.
func (*SetNodeMap) Descend ¶
func (s *SetNodeMap) Descend(pe PathElement) *Set
Descend adds pe to the set if necessary, returning the associated subset.
func (*SetNodeMap) Difference ¶
func (s *SetNodeMap) Difference(s2 *SetNodeMap) *SetNodeMap
Difference returns a SetNodeMap with members that appear in s but not in s2.
func (*SetNodeMap) Empty ¶
func (s *SetNodeMap) Empty() bool
Empty returns false if there's at least one member in some child set.
func (*SetNodeMap) Equals ¶
func (s *SetNodeMap) Equals(s2 *SetNodeMap) bool
Equals returns true if s and s2 have the same structure (same nested child sets).
func (*SetNodeMap) Get ¶
func (s *SetNodeMap) Get(pe PathElement) (*Set, bool)
Get returns (the associated set, true) or (nil, false) if there is none.
func (*SetNodeMap) Intersection ¶
func (s *SetNodeMap) Intersection(s2 *SetNodeMap) *SetNodeMap
Intersection returns a SetNodeMap with members that appear in both s and s2.
func (*SetNodeMap) Size ¶
func (s *SetNodeMap) Size() int
Size returns the sum of the number of members of all subsets.
func (*SetNodeMap) Union ¶
func (s *SetNodeMap) Union(s2 *SetNodeMap) *SetNodeMap
Union returns a SetNodeMap with members that appear in either s or s2.