dagger
import "github.com/autom8ter/dagger/v3"
Package dagger is a collection of generic, concurrency safe datastructures including a Directed Acyclic Graph and others. Datastructures are implemented using generics in Go 1.18.
Supported Datastructures:
DAG: thread safe directed acyclic graph
Queue: unbounded thread safe fifo queue
Stack: unbounded thread safe lifo stack
BoundedQueue: bounded thread safe fifo queue with a fixed capacity
PriorityQueue: thread safe priority queue
HashMap: thread safe hashmap
Set: thread safe set
ChannelGroup: thread safe group of channels for broadcasting 1 value to N channels
MultiContext: thread safe context for coordinating the cancellation of multiple contexts
Borrower: thread safe object ownership manager
Index
- func UniqueID(prefix string) string
- type BoundedQueue
- func NewBoundedQueue[T any](maxSize int) *BoundedQueue[T]
- func (q *BoundedQueue[T]) Close()
- func (q *BoundedQueue[T]) Len() int
- func (q *BoundedQueue[T]) Pop() (T, bool)
- func (q *BoundedQueue[T]) PopContext(ctx context.Context) (T, bool)
- func (q *BoundedQueue[T]) Push(val T) bool
- func (q *BoundedQueue[T]) PushContext(ctx context.Context, val T) bool
- func (q *BoundedQueue[T]) Range(fn func(element T) bool)
- func (q *BoundedQueue[T]) RangeContext(ctx context.Context, fn func(element T) bool)
- type DAG
- func NewDAG[T Node](opts ...DagOpt) (*DAG[T], error)
- func (g *DAG[T]) Acyclic() bool
- func (g *DAG[T]) BFS(ctx context.Context, reverse bool, start *GraphNode[T], search GraphSearchFunc[T]) error
- func (g *DAG[T]) DFS(ctx context.Context, reverse bool, start *GraphNode[T], fn GraphSearchFunc[T]) error
- func (g *DAG[T]) GetEdge(id string) (*GraphEdge[T], bool)
- func (g *DAG[T]) GetEdges() []*GraphEdge[T]
- func (g *DAG[T]) GetNode(id string) (*GraphNode[T], bool)
- func (g *DAG[T]) GetNodes() []*GraphNode[T]
- func (g *DAG[T]) GraphViz() (image.Image, error)
- func (g *DAG[T]) HasEdge(id string) bool
- func (g *DAG[T]) HasNode(id string) bool
- func (g *DAG[T]) RangeEdges(fn func(e *GraphEdge[T]) bool)
- func (g *DAG[T]) RangeNodes(fn func(n *GraphNode[T]) bool)
- func (g *DAG[T]) SetNode(node Node) *GraphNode[T]
- func (g *DAG[T]) Size() (int, int)
- func (g *DAG[T]) TopologicalSort(reverse bool) ([]*GraphNode[T], error)
- type DagOpt
- func WithVizualization() DagOpt
- type GraphEdge
- func (n *GraphEdge[T]) From() *GraphNode[T]
- func (n *GraphEdge[T]) ID() string
- func (n *GraphEdge[T]) Metadata() map[string]string
- func (n *GraphEdge[T]) Relationship() string
- func (n *GraphEdge[T]) SetMetadata(metadata map[string]string)
- func (n *GraphEdge[T]) To() *GraphNode[T]
- type GraphNode
- func (n *GraphNode[T]) Ancestors(fn func(node *GraphNode[T]) bool)
- func (n *GraphNode[T]) BFS(ctx context.Context, reverse bool, fn GraphSearchFunc[T]) error
- func (n *GraphNode[T]) DFS(ctx context.Context, reverse bool, fn GraphSearchFunc[T]) error
- func (n *GraphNode[T]) Descendants(fn func(node *GraphNode[T]) bool)
- func (n *GraphNode[T]) EdgesFrom(relationship string, fn func(e *GraphEdge[T]) bool)
- func (n *GraphNode[T]) EdgesTo(relationship string, fn func(e *GraphEdge[T]) bool)
- func (n *GraphNode[T]) Graph() *DAG[T]
- func (n *GraphNode[T]) IsConnectedTo(node *GraphNode[T]) bool
- func (n *GraphNode[T]) Remove() error
- func (n *GraphNode[T]) RemoveEdge(edgeID string)
- func (n *GraphNode[T]) SetEdge(relationship string, toNode Node, metadata map[string]string) (*GraphEdge[T], error)
- type GraphSearchFunc
- type HashMap
- func NewHashMap[K comparable, V any]() *HashMap[K, V]
- func (n *HashMap[K, V]) Clear()
- func (n *HashMap[K, V]) Delete(key K)
- func (n *HashMap[K, V]) Exists(key K) bool
- func (n *HashMap[K, V]) Filter(f func(key K, value V) bool) *HashMap[K, V]
- func (n *HashMap[K, V]) Get(key K) (V, bool)
- func (n *HashMap[K, V]) Keys() []K
- func (n *HashMap[K, V]) Len() int
- func (n *HashMap[K, V]) Map() map[K]V
- func (n *HashMap[K, V]) Range(f func(key K, value V) bool)
- func (n *HashMap[K, V]) Set(key K, value V)
- func (n *HashMap[K, V]) Values() []V
- type Node
- type PriorityQueue
- func NewPriorityQueue[T any]() *PriorityQueue[T]
- func (q *PriorityQueue[T]) Len() int
- func (q *PriorityQueue[T]) Peek() (T, bool)
- func (q *PriorityQueue[T]) Pop() (T, bool)
- func (q *PriorityQueue[T]) Push(item T, weight float64)
- func (q *PriorityQueue[T]) UpdatePriority(value T, priority float64)
- type Queue
- func NewQueue[T any]() *Queue[T]
- func (s *Queue[T]) Len() int
- func (s *Queue[T]) Peek() (T, bool)
- func (s *Queue[T]) Pop() (T, bool)
- func (s *Queue[T]) Push(f T)
- func (q *Queue[T]) Range(fn func(element T) bool)
- func (q *Queue[T]) RangeUntil(fn func(element T) bool, done chan struct{})
- type Set
- func NewSet[T comparable]() *Set[T]
- func (s *Set[T]) Add(val T)
- func (s *Set[T]) Contains(val T) bool
- func (s *Set[T]) Len() int
- func (s *Set[T]) Range(fn func(element T) bool)
- func (s *Set[T]) Remove(val T)
- func (s *Set[T]) Sort(lessFunc func(i T, j T) bool) []T
- func (s *Set[T]) Values() []T
- type Stack
- func NewStack[T any]() *Stack[T]
- func (s *Stack[T]) Clear()
- func (s *Stack[T]) Len() int
- func (s *Stack[T]) Peek() (T, bool)
- func (s *Stack[T]) Pop() (T, bool)
- func (s *Stack[T]) Push(f T)
- func (s *Stack[T]) Range(fn func(element T) bool)
- func (s *Stack[T]) RangeUntil(fn func(element T) bool, done chan struct{})
- func (s *Stack[T]) Sort(lessFunc func(i T, j T) bool) []T
- func (s *Stack[T]) Values() []T
func UniqueID(prefix string) string
UniqueID returns a unique identifier with the given prefix
BoundedQueue is a basic FIFO BoundedQueue based on a buffered channel
type BoundedQueue[T any] struct {
// contains filtered or unexported fields
}
func NewBoundedQueue[T any](maxSize int) *BoundedQueue[T]
NewBoundedQueue returns a new BoundedQueue with the given max size. When the max size is reached, the queue will block until a value is removed. If maxSize is 0, the queue will always block until a value is removed. The BoundedQueue is concurrent-safe.
func (*BoundedQueue[T]) Close
func (q *BoundedQueue[T]) Close()
Close closes the BoundedQueue channel.
func (*BoundedQueue[T]) Len
func (q *BoundedQueue[T]) Len() int
Len returns the number of elements in the BoundedQueue.
func (*BoundedQueue[T]) Pop
func (q *BoundedQueue[T]) Pop() (T, bool)
Pop removes and returns an element from the beginning of the BoundedQueue.
func (*BoundedQueue[T]) PopContext
func (q *BoundedQueue[T]) PopContext(ctx context.Context) (T, bool)
PopContext removes and returns an element from the beginning of the BoundedQueue. If no element is available, it will block until an element is available or the context is cancelled.
func (*BoundedQueue[T]) Push
func (q *BoundedQueue[T]) Push(val T) bool
Push adds an element to the end of the BoundedQueue and returns a channel that will block until the element is added. If the queue is full, it will block until an element is removed.
func (*BoundedQueue[T]) PushContext
func (q *BoundedQueue[T]) PushContext(ctx context.Context, val T) bool
PushContext adds an element to the end of the BoundedQueue and returns a channel that will block until the element is added. If the queue is full, it will block until an element is removed or the context is cancelled.
func (*BoundedQueue[T]) Range
func (q *BoundedQueue[T]) Range(fn func(element T) bool)
Range executes a provided function once for each BoundedQueue element until it returns false.
func (q *BoundedQueue[T]) RangeContext(ctx context.Context, fn func(element T) bool)
RangeContext executes a provided function once for each BoundedQueue element until it returns false or a value is sent to the done channel. Use this function when you want to continuously process items from the queue until a done signal is received.
DAG is a concurrency safe, mutable, in-memory directed graph
type DAG[T Node] struct {
// contains filtered or unexported fields
}
func NewDAG[T Node](opts ...DagOpt) (*DAG[T], error)
NewDAG creates a new Directed Acyclic Graph instance
func (*DAG[T]) Acyclic
func (g *DAG[T]) Acyclic() bool
Acyclic returns true if the graph contains no cycles.
func (*DAG[T]) BFS
func (g *DAG[T]) BFS(ctx context.Context, reverse bool, start *GraphNode[T], search GraphSearchFunc[T]) error
BFS executes a depth first search on the graph starting from the current node. The reverse parameter determines whether the search is reversed or not. The fn parameter is a function that is called on each node in the graph. If the function returns false, the search is stopped.
func (*DAG[T]) DFS
func (g *DAG[T]) DFS(ctx context.Context, reverse bool, start *GraphNode[T], fn GraphSearchFunc[T]) error
DFS executes a depth first search on the graph starting from the curre