Documentation ¶
Overview ¶
Package dryad provides generic data structures.
Package dryad provides generic tree nodes.
Index ¶
- func Identity[T any](v T) T
- func IsAwaitNotFoundError(err error) bool
- func IsUnfilledError(err error) bool
- func NewFirst[T any](v T) <-chan T
- type Await
- type Final
- type Geter
- type ModSlice
- type ModSliceOfEq
- type Multiset
- type NodeOfEq
- type Set
- func (s Set[T]) Add(v T)
- func (s Set[T]) AddAll(vv ...T)
- func (s Set[T]) AddSet(set Set[T])
- func (s Set[T]) Any() T
- func (s Set[T]) Contains(v T) bool
- func (s Set[T]) ContainsAll(vv ...T) bool
- func (s Set[T]) Copy() Set[T]
- func (s Set[T]) Delete(v T)
- func (s Set[T]) DeleteAll(vv ...T)
- func (s Set[T]) Difference(set Set[T]) Set[T]
- func (s Set[T]) Elements() []T
- func (s Set[T]) Equals(set Set[T]) bool
- func (s Set[T]) Intersection(set Set[T]) Set[T]
- func (s Set[T]) Intersects(set Set[T]) bool
- func (s Set[T]) IsEmpty() bool
- func (s Set[T]) IsNotEmpty() bool
- func (s Set[T]) IsSupersetOf(set Set[T]) bool
- func (s Set[T]) Len() int
- func (s Set[T]) Sorted(less func(T, T) int) []T
- func (s Set[T]) Union(set Set[T]) Set[T]
- type SyncAwaitSeq
- func (seq *SyncAwaitSeq[T]) Advance(await Await) (Await, error)
- func (seq *SyncAwaitSeq[T]) Append(v T)
- func (seq *SyncAwaitSeq[T]) AppendAll(vv []T)
- func (seq *SyncAwaitSeq[T]) Await(await Await) (Await, error)
- func (seq *SyncAwaitSeq[T]) Close()
- func (seq *SyncAwaitSeq[T]) Delete(await Await) (T, error)
- func (seq *SyncAwaitSeq[T]) Length() int
- func (seq *SyncAwaitSeq[T]) Value(await Await) (T, error)
- func (seq *SyncAwaitSeq[T]) Values() []T
- type SyncNode
- func (nde *SyncNode[T]) AddChild(child *SyncNode[T])
- func (nde *SyncNode[T]) Children() []*SyncNode[T]
- func (nde *SyncNode[T]) Degree() int
- func (nde *SyncNode[T]) Detach()
- func (nde *SyncNode[T]) Get() T
- func (nde *SyncNode[T]) IsMe(node *SyncNode[T]) bool
- func (nde *SyncNode[T]) IsRoot() bool
- func (nde *SyncNode[T]) Parent() *SyncNode[T]
- func (nde *SyncNode[T]) Set(val T)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAwaitNotFoundError ¶
IsAwaitNotFoundError reports whether the given error indicates that an Await which was supplied as an argument was not found among the current awaits.
Perhaps the Await in question was deleted.
func IsUnfilledError ¶
IsUnfilledError reports whether the given error indicates that an Await which was supplied as an argument does not have an associated value.
Perhaps the Await is not yet closed. Or perhaps the Await is closed but is not associated with a value, as can happen for example to the final Await of a closed awaitable sequence.
func NewFirst ¶
func NewFirst[T any](v T) <-chan T
NewFirst constructs a new First channel which is a channel that is preloaded with one value.
Only the first receiver gets the value. Once the channel is emptied no further values can be added, the channel can never be closed, and any other channel read operations will block.
One possible use of a First is as a conditional 'once':
select { case <-first: default: // Perform these actions more than once for non first read operations... return } // Perform the following actions only once...
Types ¶
type Await ¶
type Await <-chan struct{}
Await something.
The waiting is finished when the Await is closed. Use the closed Await to access the something that was awaited.
type Final ¶
type Final[T any] struct { // contains filtered or unexported fields }
Final can only be set once.
func (*Final[T]) Get ¶
func (f *Final[T]) Get() T
Get the value if set else the zero value of its type.
type Geter ¶
type Geter[T any] interface { // Get the value. Get() T }
func NewFinalised ¶
NewFinalised constructs a new Finalised permanently set to the given value.
type ModSlice ¶
type ModSlice[T any] []T
ModSlice uses modular arithmetic indices.
func (ModSlice[T]) CanonShift ¶
CanonShift the slice values rightwards by n positions where n is a canonical shift value, that is, positive and less than the slice length.
A value pushed off the right (highest index) edge is inserted at the left edge.
func (ModSlice[T]) Shift ¶
Shift the slice values by n positions.
It is acceptable if the given number of positions to shift the values by is negative or larger in magnitude than the slice length. Positive shifts move the values right towards the highest index. A value pushed off an edge is inserted at the other edge.
func (ModSlice[T]) ShiftByOne ¶
ShiftByOne position.
A true value shifts values right towards the highest slice index.
func (ModSlice[T]) ShiftLeft ¶
func (vv ModSlice[T]) ShiftLeft()
ShiftLeft by one position towards slice index 0.
The first slice value is copied to the last position.
func (ModSlice[T]) ShiftRight ¶
func (vv ModSlice[T]) ShiftRight()
ShiftRight by one position towards the highest slice index.
The last slice value is copied to the first position.
type ModSliceOfEq ¶
type ModSliceOfEq[T comparable] ModSlice[T]
ModSliceOfEq uses modular arithmetic indices.
func (ModSliceOfEq[T]) StartWith ¶
func (vv ModSliceOfEq[T]) StartWith(v T)
StartWith the given value by shifting the slice values so the given value's first occurrence occupies index 0.
func (ModSliceOfEq[T]) StartWithFunc ¶
func (vv ModSliceOfEq[T]) StartWithFunc(f func(v T) bool)
StartWithFunc shifts the slice values so that the given functions first true match occupies index 0.
type Multiset ¶
type Multiset[T comparable] map[T]int
A Multiset of comparable elements.
func (Multiset[T]) Multiplicity ¶
Multiplicity of the given element.
type NodeOfEq ¶
type NodeOfEq[T comparable] struct { Cashpoint *NodeOfEq[T] Kids []*NodeOfEq[T] Content T }
NodeOfEq is a tree node with comparable node contents.
func (*NodeOfEq[T]) AddChild ¶
AddChild to detach it from its current parent, if any, and add it to the receiver's child nodes making the receiver the child's parent.
Nothing happens if the child and receiver are the same node.
type Set ¶
type Set[T comparable] map[T]struct{}
A Set of comparable elements.
func (Set[T]) ContainsAll ¶
ContainsAll the elements of the given non empty slice if true.
Special cases:
- return false if the given slice is empty. See also [.IsSuperset] for alternative behaviour for the empty set case.
func (Set[T]) DeleteAll ¶
func (s Set[T]) DeleteAll(vv ...T)
DeleteAll the given elements from the set.
func (Set[T]) Difference ¶
Difference set containing those elements of the receiver set which are absent from the argument set.
func (Set[T]) Elements ¶
func (s Set[T]) Elements() []T
Elements of the set as a newly allocated slice.
func (Set[T]) Intersection ¶
Intersection of the sets containing the elements shared by both sets.
func (Set[T]) Intersects ¶
Intersects reports whether the sets share any elements.
func (Set[T]) IsNotEmpty ¶
IsNotEmpty reports whether the set has at least one element.
func (Set[T]) IsSupersetOf ¶
IsSupersetOf reports whether the receiver set is a superset of the given set.
Special cases:
- return true if the given set is empty. See also [.ContainsAll] for alternative behaviour for the empty set case.
type SyncAwaitSeq ¶
type SyncAwaitSeq[T any] struct { // The Done channel is closed by the Close() method. Done <-chan struct{} // contains filtered or unexported fields }
A SyncAwaitSeq is a concurrency safe awaitable sequence of values.
An Await shall be closed before using it to await the next position or getting the value at that position.
func NewSyncAwaitSeq ¶
func NewSyncAwaitSeq[T any]() *SyncAwaitSeq[T]
NewSyncAwaitSeq constructs a new SyncAwaitSeq.
func (*SyncAwaitSeq[T]) Advance ¶
func (seq *SyncAwaitSeq[T]) Advance(await Await) (Await, error)
Advance to the next position in the sequence after the given Await position.
Supply a nil argument to await the first position in the sequence. Otherwise, to await a position, you need to supply the already closed Await of the preceding position.
If the returned Await is not already closed, the position of the Await is as yet unfilled.
An Await closes upon a value being appended to the sequence. An Await also closes upon closure of the sequence leaving the last unfilled position forever unfilled.
Return an error if no such Await exists or the position is not filled. You cannot advance past the unfilled last position.
func (*SyncAwaitSeq[T]) Append ¶
func (seq *SyncAwaitSeq[T]) Append(v T)
Append the given value to the end of the sequence.
func (*SyncAwaitSeq[T]) AppendAll ¶
func (seq *SyncAwaitSeq[T]) AppendAll(vv []T)
AppendAll the given values to the end of the sequence.
func (*SyncAwaitSeq[T]) Await ¶
func (seq *SyncAwaitSeq[T]) Await(await Await) (Await, error)
Await is a synonym for [Advance].
func (*SyncAwaitSeq[T]) Close ¶
func (seq *SyncAwaitSeq[T]) Close()
Close the sequence.
No more values can be added afterwards.
func (*SyncAwaitSeq[T]) Delete ¶
func (seq *SyncAwaitSeq[T]) Delete(await Await) (T, error)
Delete the position in the sequence associated with the given Await, reducing the length of the sequence by 1.
Return the value occupying that position before deletion.
Return an error if no such Await exists or the position is not filled.
func (*SyncAwaitSeq[T]) Value ¶
func (seq *SyncAwaitSeq[T]) Value(await Await) (T, error)
Value in the sequence at the given awaited position.
Return an error if no such Await exists or the position is not filled.
func (*SyncAwaitSeq[T]) Values ¶
func (seq *SyncAwaitSeq[T]) Values() []T
Values of the sequence as a new slice.
type SyncNode ¶
SyncNode is a tree node with concurrency safe methods.
Accessing fields directly by bypassing the methods is not concurrency safe.
func (*SyncNode[T]) AddChild ¶
AddChild to detach it from its current parent, if any, and add it to the receiver's child nodes making the receiver the child's parent.
Nothing happens if the child and receiver are the same node.
Adding a child is not an atomic operation: the detach is done first as a separate op.
func (*SyncNode[T]) Degree ¶
Degree is the number of edges on the tree that use the receiver node.
If the receiver node is a root node it is simply the number of child nodes, otherwise it is 1 plus the number of child nodes.
func (*SyncNode[T]) Detach ¶
func (nde *SyncNode[T]) Detach()
Detach the receiver node from its parent making it the root of its own tree.