collections

package
v0.0.0-...-a4bf063 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

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) Connect

func (c *Caravan) Connect(from, to Hasher) error

Connect establishes an edge between two elements

func (*Caravan) Ensure

func (c *Caravan) Ensure(hash Hash, create func() Hasher) (*Node, bool)

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) Find

func (c *Caravan) Find(hash Hash) (*Node, bool)

Find returns the element with the given key

func (*Caravan) Insert

func (c *Caravan) Insert(p Hasher)

Insert adds an element to the caravan at the root level

func (*Caravan) Iter

func (c *Caravan) Iter(iter func(Hash, *Node) bool)

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

func (c *Caravan) Purge(pred func(Hash, *Node) bool)

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

func (c *Caravan) WeakConnect(from, to Hasher) error

type CaravanWalker

type CaravanWalker func(node *Node)

CaravanWalker function is the callback for the `Walk` function

type Hash

type Hash uint64

func CalculateHashFromString

func CalculateHashFromString(s string) Hash

CalculateHashFromString calculates the hash of a string

type Hasher

type Hasher interface {
	fmt.Stringer
	Hash() Hash
}

Hasher is the interface by which an element in a graph exposes its key

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
)

Jump to

Keyboard shortcuts

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