Documentation
¶
Index ¶
- func GetIds(nodes []*Node) []string
- func OrderDAG(g *Graph, genesisNode *Node, k int, blueSetCache *BlueSetCache, ...) ([]*Node, []*Node, error)
- type BlueSetCache
- func (blueset *BlueSetCache) Add(n *Node, set *nodeSet)
- func (blueset *BlueSetCache) Expire(amt int)
- func (blueset *BlueSetCache) GetBlueNodes(n *Node) []*Node
- func (blueset *BlueSetCache) GetBlueSet(n *Node) *nodeSet
- func (blueset *BlueSetCache) InCache(n *Node) bool
- func (blueSet *BlueSetCache) String() string
- type ChainMap
- type Graph
- func (g *Graph) AddEdge(n1 *Node, n2 *Node) bool
- func (g *Graph) AddEdgeById(n1 string, n2 string) bool
- func (g *Graph) AddEdgesById(n1 string, parents []string) []bool
- func (g *Graph) AddNode(n *Node) bool
- func (g *Graph) AddNodeById(id string) bool
- func (g *Graph) GetAnticone(node *Node) *nodeSet
- func (g *Graph) GetAnticoneWithHorizon(node *Node, horizon int) *nodeSet
- func (g *Graph) GetMissingNodes(subtips []string) []string
- func (g *Graph) GetNodeById(nodeId string) *Node
- func (g *Graph) GetPast(node2 *Node) *Graph
- func (g *Graph) GetPastWithHorizon(node2 *Node, horizon int) *Graph
- func (g *Graph) GetSize() int
- func (g *Graph) GetTips() []*Node
- func (g *Graph) GetVirtual() *Graph
- func (g *Graph) PrintGraph() string
- func (g *Graph) RemoveTip(n1 *Node)
- func (g *Graph) RemoveTipById(nodeId string)
- type GreedyGraphMem
- func (g *GreedyGraphMem) Add(id string, parents []string) (bool, error)
- func (g *GreedyGraphMem) AddEdge(a, b string) (bool, error)
- func (g *GreedyGraphMem) AddMultiEdge(a string, parents []string) (bool, error)
- func (g *GreedyGraphMem) AddNode(id string) (bool, error)
- func (g *GreedyGraphMem) ColoringOrder() (*OrderedStringSet, error)
- func (g *GreedyGraphMem) Height(id string) (int, error)
- func (g *GreedyGraphMem) NodeExists(id string) (bool, error)
- func (g *GreedyGraphMem) Nodes() []string
- func (g *GreedyGraphMem) Order() ([]string, error)
- func (g *GreedyGraphMem) Parents(id string) ([]string, error)
- func (g *GreedyGraphMem) Past(id string) ([]string, error)
- func (g *GreedyGraphMem) RemoveEdge(a, b string) bool
- func (g *GreedyGraphMem) RemoveTip(id string) error
- func (g *GreedyGraphMem) TipDiff(subTips []string) ([]string, error)
- func (g *GreedyGraphMem) Tips() ([]string, error)
- func (g *GreedyGraphMem) ToString() (string, error)
- type Node
- type NodeGraphCache
- type NodeGraphCacheEntry
- type OrderCache
- func (oc *OrderCache) Add(height int32, tips, order []*Node) error
- func (oc *OrderCache) CanAdd(height int32) (string, bool)
- func (oc *OrderCache) Expire(amt int)
- func (oc *OrderCache) Get(height int32) (*OrderCacheEntry, bool)
- func (oc *OrderCache) Heights() []int32
- func (oc *OrderCache) MaxHeight() (int32, bool)
- func (oc *OrderCache) Size() int
- type OrderCacheEntry
- type OrderMap
- type OrderedStringSet
- func (oss *OrderedStringSet) Add(aString string)
- func (oss *OrderedStringSet) Clone() *OrderedStringSet
- func (oss *OrderedStringSet) Contains(aString string) bool
- func (oss *OrderedStringSet) Difference(setB *OrderedStringSet) *OrderedStringSet
- func (oss *OrderedStringSet) Elements() []string
- func (oss *OrderedStringSet) Intersection(setB *OrderedStringSet) *OrderedStringSet
- func (oss *OrderedStringSet) Remove(aString string)
- func (oss *OrderedStringSet) Size() int
- func (oss *OrderedStringSet) Subset(setB *OrderedStringSet) bool
- func (oss *OrderedStringSet) Union(setB *OrderedStringSet) *OrderedStringSet
- type StringSet
- func (ss *StringSet) Add(aString string)
- func (ss *StringSet) Contains(aString string) bool
- func (ss *StringSet) Difference(other *StringSet) *StringSet
- func (ss *StringSet) Elements() []string
- func (ss *StringSet) Encode() ([]byte, error)
- func (ss *StringSet) Intersection(other *StringSet) *StringSet
- func (ss *StringSet) Remove(aString string)
- func (ss *StringSet) Size() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BlueSetCache ¶
func NewBlueSetCache ¶
func NewBlueSetCache() *BlueSetCache
func (*BlueSetCache) Add ¶
func (blueset *BlueSetCache) Add(n *Node, set *nodeSet)
Add the node associated with the set to the cache
func (*BlueSetCache) Expire ¶
func (blueset *BlueSetCache) Expire(amt int)
Expire removes a number of entries from the cache
func (*BlueSetCache) GetBlueNodes ¶
func (blueset *BlueSetCache) GetBlueNodes(n *Node) []*Node
func (*BlueSetCache) GetBlueSet ¶
func (blueset *BlueSetCache) GetBlueSet(n *Node) *nodeSet
GetBlueSet returns the nodeSet associated with the node
func (*BlueSetCache) InCache ¶
func (blueset *BlueSetCache) InCache(n *Node) bool
InCache returns true if the node is in the blueset cache
func (*BlueSetCache) String ¶
func (blueSet *BlueSetCache) String() string
String returns a string representing the current cache state
type ChainMap ¶
type ChainMap struct {
// contains filtered or unexported fields
}
func NewChainMap ¶
func NewChainMap(elements ...interface{}) *ChainMap
NewChainMap returns a new ChainMap
func (*ChainMap) Contains ¶
Contains returns true when it finds that the key exists in the first matching map in the ChainMap. If the element is itself a chainmap, its members are parsed first.
func (*ChainMap) Get ¶
Get returns the first match from the sequence of members in the ChainMap. Returns true if a match was found.
func (*ChainMap) Keys ¶
func (cm *ChainMap) Keys() *OrderedStringSet
Keys returns an OrderedStringSet of keys from the ChainMap
type Graph ¶
GRAPH
func (*Graph) AddNodeById ¶
func (*Graph) GetAnticone ¶
GetAnticone returns anticone of node on g: set of all nodes of g - past(node) - future(node) - node
func (*Graph) GetAnticoneWithHorizon ¶
GetAnticoneWithHorizon returns the anticone of node on the graph, limited in the past to the depth of ancestor nodes given by horizon.
anticone of node on g: set of all nodes of g - past(node) - future(node) - node
func (*Graph) GetMissingNodes ¶
func (*Graph) GetNodeById ¶
func (*Graph) GetPastWithHorizon ¶
func (*Graph) GetVirtual ¶
GetVirtual returns a copy of the graph with a virtual node at the end, whose parents are the tips of the graph
func (*Graph) PrintGraph ¶
func (*Graph) RemoveTipById ¶
type GreedyGraphMem ¶
type GreedyGraphMem struct {
// contains filtered or unexported fields
}
GreedyGraph represents a graph of nodes, using Greedy PHANTOM colouring
func NewGreedyGraphMem ¶
func NewGreedyGraphMem(k int) (*GreedyGraphMem, error)
NewGreedyGraphMem returns a GreedyGraphMem
func (*GreedyGraphMem) Add ¶
func (g *GreedyGraphMem) Add(id string, parents []string) (bool, error)
Add adds a node to the graph with the given parents, then updates coloring and graph order
func (*GreedyGraphMem) AddEdge ¶
func (g *GreedyGraphMem) AddEdge(a, b string) (bool, error)
AddEdge adds an edge from node a to b. (b is parent of a) Returns true if the edge was added.
func (*GreedyGraphMem) AddMultiEdge ¶
func (g *GreedyGraphMem) AddMultiEdge(a string, parents []string) (bool, error)
AddMultiEdgeById adds an edge from node with id a to nodes in parents. Returns true if all edges were added.
func (*GreedyGraphMem) AddNode ¶
func (g *GreedyGraphMem) AddNode(id string) (bool, error)
AddNode adds a node to the graph Returns true if the node was added.
func (*GreedyGraphMem) ColoringOrder ¶
func (g *GreedyGraphMem) ColoringOrder() (*OrderedStringSet, error)
ColoringOrder returns the coloring order of the graph
func (*GreedyGraphMem) Height ¶
func (g *GreedyGraphMem) Height(id string) (int, error)
Height returns the min, max height of the node
func (*GreedyGraphMem) NodeExists ¶
func (g *GreedyGraphMem) NodeExists(id string) (bool, error)
NodeExists returns true if the node exists in the graph
func (*GreedyGraphMem) Nodes ¶
func (g *GreedyGraphMem) Nodes() []string
Nodes returns all nodes in the graph
func (*GreedyGraphMem) Order ¶
func (g *GreedyGraphMem) Order() ([]string, error)
Order returns the topological order of the graph
func (*GreedyGraphMem) Parents ¶
func (g *GreedyGraphMem) Parents(id string) ([]string, error)
Parents returns the parents of the node
func (*GreedyGraphMem) Past ¶
func (g *GreedyGraphMem) Past(id string) ([]string, error)
Past returns the past of the node
func (*GreedyGraphMem) RemoveEdge ¶
func (g *GreedyGraphMem) RemoveEdge(a, b string) bool
RemoveEdge removes an edge from node a to b. b is not parent of a a is not child of b Returns true if the edge was removed.
func (*GreedyGraphMem) RemoveTip ¶
func (g *GreedyGraphMem) RemoveTip(id string) error
RemoveTip removes a tip from the graph.
func (*GreedyGraphMem) TipDiff ¶
func (g *GreedyGraphMem) TipDiff(subTips []string) ([]string, error)
TipDiff returns the unioned antiPast of the given subTips; nodes from the future of those subTips to the tips of the graph, including non-adjacent nodes.
func (*GreedyGraphMem) Tips ¶
func (g *GreedyGraphMem) Tips() ([]string, error)
Tips returns the tip nodes of the graph
func (*GreedyGraphMem) ToString ¶
func (g *GreedyGraphMem) ToString() (string, error)
ToString returns a string representation of the graph
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
NODE in the BlockDAG case: parent of the node has an edge from the node to it: node -> parent child of the node has an edge from it to the node: child -> node
type NodeGraphCache ¶
func NewNodeGraphCache ¶
func NewNodeGraphCache(name string) *NodeGraphCache
NewNodeGraphCache returns a NodeGraphCache, which can be used to help reduce repetitive computation for Node connectivity.
func (*NodeGraphCache) Add ¶
func (ngc *NodeGraphCache) Add(n *Node, g *Graph)
Add adds an entry to the past cache
func (*NodeGraphCache) Delete ¶
func (ngc *NodeGraphCache) Delete(n *Node)
Delete deletes an entry from the cache
func (*NodeGraphCache) Expire ¶
func (ngc *NodeGraphCache) Expire(amt int)
Expire removes a number of least-used entries from the cache
func (*NodeGraphCache) Get ¶
func (ngc *NodeGraphCache) Get(n *Node) (*NodeGraphCacheEntry, bool)
Get returns a cache entry and bool indicating cache hit or miss. Entry is nil if not found.
type NodeGraphCacheEntry ¶
type OrderCache ¶
type OrderCache struct { // Methods use locks to ensure stable access to the cache between goroutines sync.RWMutex // contains filtered or unexported fields }
func NewOrderCache ¶
func NewOrderCache() *OrderCache
NewOrderCache returns an orderCache, which can be used to help reduce repetitive computation as dag size increases
func (*OrderCache) Add ¶
func (oc *OrderCache) Add(height int32, tips, order []*Node) error
Add adds the entry to the cache
func (*OrderCache) CanAdd ¶
func (oc *OrderCache) CanAdd(height int32) (string, bool)
canAdd returns true if it looks like it's ok to add an entry to the cache at the given height
func (*OrderCache) Expire ¶
func (oc *OrderCache) Expire(amt int)
Expire removes the lowest n entries from the cache
func (*OrderCache) Get ¶
func (oc *OrderCache) Get(height int32) (*OrderCacheEntry, bool)
Get returns a cache entry appropriate for the height, and whether a matching cache entry was found
func (*OrderCache) Heights ¶
func (oc *OrderCache) Heights() []int32
Heights returns a slice of cache heights, sorted from lowest to highest
func (*OrderCache) MaxHeight ¶
func (oc *OrderCache) MaxHeight() (int32, bool)
MaxHeight returns the height of the highest cache entry, and if there are entries
type OrderCacheEntry ¶
type OrderMap ¶
OrderMap maps a string to an int
type OrderedStringSet ¶
type OrderedStringSet struct {
// contains filtered or unexported fields
}
func NewOrderedStringSet ¶
func NewOrderedStringSet(members ...string) *OrderedStringSet
NewOrderedStringSet returns a new empty ordered string set
func (*OrderedStringSet) Add ¶
func (oss *OrderedStringSet) Add(aString string)
Add adds a member to the set if doesn't already exist
func (*OrderedStringSet) Clone ¶
func (oss *OrderedStringSet) Clone() *OrderedStringSet
Clone returns a copy of the set
func (*OrderedStringSet) Contains ¶
func (oss *OrderedStringSet) Contains(aString string) bool
Contains returns true if the member is in the set
func (*OrderedStringSet) Difference ¶
func (oss *OrderedStringSet) Difference(setB *OrderedStringSet) *OrderedStringSet
Difference returns a set with the members of this set that aren't in setB
func (*OrderedStringSet) Elements ¶
func (oss *OrderedStringSet) Elements() []string
Elements returns members of the set in the order they were added
func (*OrderedStringSet) Intersection ¶
func (oss *OrderedStringSet) Intersection(setB *OrderedStringSet) *OrderedStringSet
Intersection returns a set with the members that exist in both this set and setB
func (*OrderedStringSet) Remove ¶
func (oss *OrderedStringSet) Remove(aString string)
Remove removes a member from the set
func (*OrderedStringSet) Size ¶
func (oss *OrderedStringSet) Size() int
Size returns the number of members in the set
func (*OrderedStringSet) Subset ¶
func (oss *OrderedStringSet) Subset(setB *OrderedStringSet) bool
Subset returns true if all set members in this set exist in setB (oss ⊆ setB)
func (*OrderedStringSet) Union ¶
func (oss *OrderedStringSet) Union(setB *OrderedStringSet) *OrderedStringSet
Union returns a set with members in this set or setB
type StringSet ¶
type StringSet struct {
// contains filtered or unexported fields
}
func DecodeStringSet ¶
This decodes a slice of bytes into a new StringSet instance.
This is meant to help load a persisted blueCache entry from disk, and is the opposite of the ss.Encode() method.
func (*StringSet) Difference ¶
Difference returns set - other
func (*StringSet) Encode ¶
Encode returns bytes in gob format representing the set members. This is meant to help persist blueSet cache entries to disk.
We specify an Encode() method instead of running gob.NewEncoder().Encode() on the StringSet directly, because gob only encodes exported fields and we'd prefer to keep the set internals unexported.
For the reverse operation, use DecodeStringSet function to create a new StringSet from bytes.
func (*StringSet) Intersection ¶
Intersection returns set intersection other