// NewTree returns a new history tree. func NewTree() (t *Tree) { t = new(Tree) t.size = 0 t.frozen = ps.NewMap() t.events = ps.NewMap() return }
// NewBlankMachine creates a new Golog machine without loading the // standard library (prelude) func NewBlankMachine() Machine { var m machine m.db = NewDatabase() m.env = NewBindings() m.disjs = ps.NewList() m.conjs = ps.NewList() for i := 0; i < smallThreshold; i++ { m.smallForeign[i] = ps.NewMap() } m.largeForeign = ps.NewMap() return (&m).DemandCutBarrier() }
func (c EdgeMetadatas) fromIntermediate(in map[string]EdgeMetadata) EdgeMetadatas { out := ps.NewMap() for k, v := range in { out = out.Set(k, v) } return EdgeMetadatas{out} }
func (m LatestMap) fromIntermediate(in map[string]LatestEntry) LatestMap { out := ps.NewMap() for k, v := range in { out = out.Set(k, v) } return LatestMap{out} }
func (c Counters) fromIntermediate(in map[string]int) Counters { out := ps.NewMap() for k, v := range in { out = out.Set(k, v) } return Counters{out} }
// Variables returns a ps.Map whose keys are human-readable variable names // and those values are *Variable used inside term t. func Variables(t Term) ps.Map { names := ps.NewMap() switch t.Type() { case AtomType, FloatType, IntegerType, ErrorType: return names case CompoundType: x := t.(*Compound) if x.Arity() == 0 { return names } // no variables in an atom for _, arg := range x.Arguments() { innerNames := Variables(arg) innerNames.ForEach(func(key string, val interface{}) { names = names.Set(key, val) }) } return names case VariableType: x := t.(*Variable) return names.Set(x.Name, x) } panic("Unexpected term implementation") }
func (s Sets) fromIntermediate(in map[string]StringSet) Sets { out := ps.NewMap() for k, v := range in { out = out.Set(k, v) } return Sets{out} }
func getBuilderMap(builder interface{}) ps.Map { b := convert(builder, Builder{}).(Builder) if b.builderMap == nil { return ps.NewMap() } return b.builderMap }
// Add adds the specs to the PluginSpecs. Add is the only valid way to grow a // PluginSpecs. Add returns the PluginSpecs to enable chaining. func (n PluginSpecs) Add(specs ...PluginSpec) PluginSpecs { result := n.psMap if result == nil { result = ps.NewMap() } for _, spec := range specs { result = result.Set(spec.ID, spec) } return PluginSpecs{result} }
// Add adds the nodes to the NodeSet. Add is the only valid way to grow a // NodeSet. Add returns the NodeSet to enable chaining. func (n NodeSet) Add(nodes ...Node) NodeSet { result := n.psMap if result == nil { result = ps.NewMap() } for _, node := range nodes { result = result.Set(node.ID, node) } return NodeSet{result} }
func (n PluginSpecs) String() string { keys := []string{} if n.psMap == nil { n = EmptyPluginSpecs } psMap := n.psMap if psMap == nil { psMap = ps.NewMap() } for _, k := range psMap.Keys() { keys = append(keys, k) } sort.Strings(keys) buf := bytes.NewBufferString("{") for _, key := range keys { val, _ := psMap.Lookup(key) fmt.Fprintf(buf, "%s: %s, ", key, spew.Sdump(val)) } fmt.Fprintf(buf, "}") return buf.String() }
"encoding/json" "fmt" "reflect" "sort" "github.com/mndrix/ps" ) // Sets is a string->set-of-strings map. // It is immutable. type Sets struct { psMap ps.Map } // EmptySets is an empty Sets. Starts with this. var EmptySets = Sets{ps.NewMap()} // MakeSets returns EmptySets func MakeSets() Sets { return EmptySets } // Keys returns the keys for this set func (s Sets) Keys() []string { if s.psMap == nil { return nil } return s.psMap.Keys() } // Add the given value to the Sets.
func NewTestEventStorage() (storage *TestEventStorage) { storage = new(TestEventStorage) storage.events = ps.NewMap() return }
) // Builder stores a set of named values. // // New types can be declared with underlying type Builder and used with the // functions in this package. See example. // // Instances of Builder should be treated as immutable. It is up to the // implementor to ensure mutable values set on a Builder are not mutated while // the Builder is in use. type Builder struct { builderMap ps.Map } var ( EmptyBuilder = Builder{ps.NewMap()} emptyBuilderValue = reflect.ValueOf(EmptyBuilder) ) func getBuilderMap(builder interface{}) ps.Map { b := convert(builder, Builder{}).(Builder) if b.builderMap == nil { return ps.NewMap() } return b.builderMap } // Set returns a copy of the given builder with a new value set for the given // name.
"encoding/gob" "fmt" "reflect" "sort" "github.com/mndrix/ps" "github.com/ugorji/go/codec" ) // Counters is a string->int map. type Counters struct { psMap ps.Map } // EmptyCounters is the set of empty counters. var EmptyCounters = Counters{ps.NewMap()} // MakeCounters returns EmptyCounters func MakeCounters() Counters { return EmptyCounters } // Copy is a noop func (c Counters) Copy() Counters { return c } // Add value to the counter 'key' func (c Counters) Add(key string, value int) Counters { if c.psMap == nil { c = EmptyCounters
// NewDatabase returns a new, empty database func NewDatabase() Database { var db mapDb db.clauseCount = 0 db.predicates = ps.NewMap() return &db }
// NewBindings returns a new, empty bindings value. func NewBindings() Bindings { var newEnv envMap newEnv.bindings = ps.NewMap() newEnv.names = ps.NewMap() return &newEnv }
// newClauses returns a new, empty list of clauses func newClauses() *clauses { var cs clauses cs.terms = ps.NewMap() // n, lowestId, highestId correctly default to 0 return &cs }
// MakeLatestMap makes an empty LatestMap func MakeLatestMap() LatestMap { return LatestMap{ps.NewMap()} }
"encoding/json" "fmt" "reflect" "sort" "github.com/mndrix/ps" ) // EdgeMetadatas collect metadata about each edge in a topology. Keys are the // remote node IDs, as in Adjacency. type EdgeMetadatas struct { psMap ps.Map } // EmptyEdgeMetadatas is the set of empty EdgeMetadatas. var EmptyEdgeMetadatas = EdgeMetadatas{ps.NewMap()} // MakeEdgeMetadatas returns EmptyEdgeMetadatas func MakeEdgeMetadatas() EdgeMetadatas { return EmptyEdgeMetadatas } // Copy is a noop func (c EdgeMetadatas) Copy() EdgeMetadatas { return c } // Add value to the counter 'key' func (c EdgeMetadatas) Add(key string, value EdgeMetadata) EdgeMetadatas { if c.psMap == nil { c = EmptyEdgeMetadatas
"github.com/davecgh/go-spew/spew" "github.com/mndrix/ps" "github.com/ugorji/go/codec" "$GITHUB_URI/test/reflect" ) // NodeSet is a set of nodes keyed on ID. Clients must use // the Add method to add nodes type NodeSet struct { psMap ps.Map } // EmptyNodeSet is the empty set of nodes. var EmptyNodeSet = NodeSet{ps.NewMap()} // MakeNodeSet makes a new NodeSet with the given nodes. func MakeNodeSet(nodes ...Node) NodeSet { return EmptyNodeSet.Add(nodes...) } // Add adds the nodes to the NodeSet. Add is the only valid way to grow a // NodeSet. Add returns the NodeSet to enable chaining. func (n NodeSet) Add(nodes ...Node) NodeSet { result := n.psMap if result == nil { result = ps.NewMap() } for _, node := range nodes { result = result.Set(node.ID, node)
// Interfaces is a list of things this plugin can be used for (e.g. "reporter") Interfaces []string `json:"interfaces"` APIVersion string `json:"api_version,omitempty"` Status string `json:"status,omitempty"` } // PluginSpecs is a set of plugin specs keyed on ID. Clients must use // the Add method to add plugin specs type PluginSpecs struct { psMap ps.Map } // EmptyPluginSpecs is the empty set of plugin specs. var EmptyPluginSpecs = PluginSpecs{ps.NewMap()} // MakePluginSpecs makes a new PluginSpecs with the given plugin specs. func MakePluginSpecs(specs ...PluginSpec) PluginSpecs { return EmptyPluginSpecs.Add(specs...) } // Add adds the specs to the PluginSpecs. Add is the only valid way to grow a // PluginSpecs. Add returns the PluginSpecs to enable chaining. func (n PluginSpecs) Add(specs ...PluginSpec) PluginSpecs { result := n.psMap if result == nil { result = ps.NewMap() } for _, spec := range specs { result = result.Set(spec.ID, spec)
type LatestEntry struct { Timestamp time.Time `json:"timestamp"` Value string `json:"value"` } func (e LatestEntry) String() string { return fmt.Sprintf("\"%s\" (%s)", e.Value, e.Timestamp.String()) } // Equal returns true if the supplied LatestEntry is equal to this one. func (e LatestEntry) Equal(e2 LatestEntry) bool { return e.Timestamp.Equal(e2.Timestamp) && e.Value == e2.Value } // EmptyLatestMap is an empty LatestMap. Start with this. var EmptyLatestMap = LatestMap{ps.NewMap()} // MakeLatestMap makes an empty LatestMap func MakeLatestMap() LatestMap { return EmptyLatestMap } // Copy is a noop, as LatestMaps are immutable. func (m LatestMap) Copy() LatestMap { return m } // Size returns the number of elements func (m LatestMap) Size() int { if m.Map == nil { return 0