Documentation ¶
Index ¶
- type Caravan
- func (c *Caravan) Connect(from, to Hasher) error
- func (c *Caravan) Ensure(hash Hash, create func() Hasher) (*Node, bool)
- func (c *Caravan) Find(hash Hash) (*Node, bool)
- func (c *Caravan) Insert(p Hasher)
- func (c *Caravan) Iter(iter func(Hash, *Node) bool)
- func (c *Caravan) Purge(pred func(Hash, *Node) bool)
- func (c *Caravan) Walk(direction WalkDirection, walker CaravanWalker)
- func (c *Caravan) WeakConnect(from, to Hasher) error
- type CaravanWalker
- type Hash
- type Hasher
- type Node
- type WalkDirection
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Caravan ¶
type Caravan struct {
// contains filtered or unexported fields
}
Caravan is a collection of independent directed acyclic graphs (DAGs). Items are inserted into a caravan, and the graph structure is constructed. The caravan exposes all items which are root level, and allows the structure to be walked. "Good dags. D'ya like dags?" "Dags?" "What?" "Yeah, dags" "Oh, dogs. Sure, I like dags. I like caravans more." -- http://www.imdb.com/character/ch0003626/quotes
func CreateCaravan ¶
func CreateCaravan() *Caravan
CreateCaravan returns an initialized caravan struct
func (*Caravan) Ensure ¶
Ensure will look up a key. If there is a match in the caravan, that node is returned. Otherwise, the create function is invoked. The results of that are put into the caravan, and the resulting node is returned. The returned bool is true if the node already existed, and false if the create method was invoked.
func (*Caravan) Iter ¶
Iter provides a channel used for iterating over all nodes. Example: c := NewCaravan() // ...
caravan.Iter(func(hash Hash, node *Node) bool { p := node.Element.(*DistinctPackage) // Do something with `p` return true })
func (*Caravan) Purge ¶
Purge cycles through all nodes, and removes them if the provided predicate function returns true
func (*Caravan) Walk ¶
func (c *Caravan) Walk(direction WalkDirection, walker CaravanWalker)
Walk will traverse the caravan structure, calling the provided `walker` function at every node. The `direction` parameter indicates whether the traversal will start at the top (roots) or at the bottom (leaves). When walking down, all ascendents of a node will be walked before that node. Conversely, when walking up, all descendents of a node will be walked before that node. Walk will visit each node exactly once.
Note that because the caravan may be disjointed, the walk function may start at a leaf or root, pass through some interior nodes, then return to a different root or leaf.
func (*Caravan) WeakConnect ¶
type CaravanWalker ¶
type CaravanWalker func(node *Node)
CaravanWalker function is the callback for the `Walk` function
type Hash ¶
type Hash uint64
func CalculateHashFromString ¶
CalculateHashFromString calculates the hash of a string
type Node ¶
type Node struct { Ascendants map[Hash]*Node Descendants map[Hash]*Node Element Hasher WeakDescendants map[Hash]*Node }
Node is an element in a caravan graph
type WalkDirection ¶
type WalkDirection int
WalkDirection provides the Walk function with a direction to traverse the caravan
const ( // WalkUp indicates that the walk function will start with leaves, and // traverse the caravan towards roots. WalkUp WalkDirection = iota // WalkDown indicates that the walk function will start with the roots, // and will traverse the caravan towards the leaves. WalkDown )