containers

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

This package holds the concrete implementations of the containers.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapDisjointKeyedUnion

func MapDisjointKeyedUnion[K any, V any](
	l dynamicContainers.Map[K, V],
	r dynamicContainers.Map[K, V],
) error

MapKeyedUnion takes all of the keys value pairs in r and places them in l. The key set of l must be fully disjoint from the key set of r, otherwise a containerTypes.Duplicate error will be returned. The state of l will not be known if duplicate keys are found.

func MapKeyedUnion

func MapKeyedUnion[K any, V any](
	l dynamicContainers.Map[K, V],
	r dynamicContainers.Map[K, V],
)

MapKeyedUnion takes all of the keys value pairs in r and places them in l. It keys are present in both l and r, the value from r will be the value that is present in the final map.

func SlidingWindow

func SlidingWindow[T any](
	i iter.Iter[T],
	q interface {
		staticContainers.Queue[T]
		staticContainers.Vector[T]
	},
	allowPartials bool,
) iter.Iter[staticContainers.Vector[T]]

This function is a producer.

SlidingWindow will take the parent iterator and return a window of it's cached values of length equal to the allowed capacity of the supplied queue (q). Window values will overlap, as shown in the example below.

  • Iteration 1: 1,2,3,4
  • Iteration 2: 2,3,4,5

If allowPartials is true then windows that are not full will be returned. Setting allowPartials to false will enforce all returned windows to have length equal to the allowed capacity of the supplied queue. An error will stop iteration.

func SteppingWindow

func SteppingWindow[T any](
	i iter.Iter[T],
	q interface {
		staticContainers.Queue[T]
		staticContainers.Vector[T]
	},
) iter.Iter[staticContainers.Vector[T]]

This function is a producer.

SteppingWindow will take the parent iterator and return a window of it's cached values of length equal to the allowed capacity of the supplied queue (q). Window values will not overlap, as shown in the example below. No partial queues will be returned, meaning any leftover values that do not make a full queue at the end of iteration will not be returned.

  • Iteration 1: 1,2,3,4
  • Iteration 2: 5,6,7,8

An error will stop iteration.

func Unique

func Unique[T any](
	i iter.Iter[T],
	s dynamicContainers.Set[T],
	errOnDuplicate bool,
) error

This function is a consumer.

Unique will consume all values from it's parent iterator and will collect all unique values into a set. The errOnDuplicate argument determines whether or not an error will be returned if a duplicate value is found. Iteration will stop if errOnDuplicate is set to true and a duplicate value is found.

Types

type CircularBuffer

type CircularBuffer[T any, U widgets.BaseInterface[T]] struct {
	// contains filtered or unexported fields
}

A container that holds a fixed number of values in such a way that makes stack and queue operations extremely efficient. Because the length of the container is fixed (it will not dynamically expand to add more elements as needed) the values in the underlying array will 'rotate' around the array as operations are performed making it so no allocations are ever performed beyond the initial creation of the underlying array.

func CirularBufferValInit

func CirularBufferValInit[T any, U widgets.BaseInterface[T]](
	vals ...T,
) CircularBuffer[T, U]

Creates a new circular buffer and populates it with the supplied values. The circular buffer will have len(vals) capacity.

func NewCircularBuffer

func NewCircularBuffer[T any, U widgets.BaseInterface[T]](
	size int,
) (CircularBuffer[T, U], error)

Creates a new CircularBuffer initialized with size zero valued elements. Size must be greater than 0, an error will be returned if it is not.

func (*CircularBuffer[T, U]) Append

func (c *CircularBuffer[T, U]) Append(vals ...T) error

Description: Appends the supplied values to the circular buffer. This function will never return an error.

Time Complexity: Best case O(m), where m=len(vals).

func (*CircularBuffer[T, U]) AppendUnique

func (c *CircularBuffer[T, U]) AppendUnique(vals ...T) error

Description: AppendUnique will append the supplied values to the circular buffer if they are not already present in the circular buffer (unique). Non-unique values will not be appended. This function will never return an error.

Time Complexity: Best case O(m), where m=len(vals).

func (*CircularBuffer[T, U]) Capacity

func (c *CircularBuffer[T, U]) Capacity() int

Description: Returns the capacity of the circular buffer.

Time Complexity: O(1)

func (*CircularBuffer[T, U]) Clear

func (c *CircularBuffer[T, U]) Clear()

Description: Clears all values from the circular buffer.

Time Complexity: O(n) (Because of zeroing)

func (*CircularBuffer[T, U]) Contains

func (c *CircularBuffer[T, U]) Contains(val T) bool

Description: Contains will return true if the supplied value is in the circular buffer, false otherwise. All equality comparisons are performed by the generic U widget type that the circular buffer was initialized with.

Time Complexity: O(n) (linear search)

func (*CircularBuffer[T, U]) ContainsPntr

func (c *CircularBuffer[T, U]) ContainsPntr(val *T) bool

Description: ContainsPntr will return true if the supplied value is in the circular buffer, false otherwise. All equality comparisons are performed by the generic U widget type that the circular buffer was initialized with.

Time Complexity: O(n) (linear search)

func (*CircularBuffer[T, U]) Delete

func (c *CircularBuffer[T, U]) Delete(idx int) error

Description: Deletes the value at the specified index. Returns an error if the index is >= the length of the circular buffer.

Time Complexity: O(n)

func (*CircularBuffer[T, U]) DeleteSequential

func (c *CircularBuffer[T, U]) DeleteSequential(start int, end int) error

Description: Deletes the values in the index range [start,end). Returns an error if the start index is < 0, the end index is >= the length of the circular buffer, or the end index is < the start index.

Time Complexity: O(n)

func (*CircularBuffer[T, U]) Difference

Description: Populates the circular buffer with the result of taking the difference of r from l. This circular buffer will be cleared before storing the result. When clearing, the new resulting circular buffer will be initialized with zero capacity and enough backing memory to store the length of l.

Time Complexity: Dependent on the time complexity of the implementation of the ContainsPntr method on l and r. In big-O it might look something like this, O(O(r.ContainsPntr)*O(l.ContainsPntr)), where O(r.ContainsPntr) represents the time complexity of the containsPntr method on r and O(l.ContainsPntr) represents the time complexity of the containsPntr method on l.

func (*CircularBuffer[T, U]) Eq

func (_ *CircularBuffer[T, U]) Eq(
	l *CircularBuffer[T, U],
	r *CircularBuffer[T, U],
) bool

An equality function that implements the [algo.widget.WidgetInterface] interface. Internally this is equivalent to CircularBuffer.KeyedEq. Returns true if l==r, false otherwise.

func (*CircularBuffer[T, U]) ForcePushBack

func (c *CircularBuffer[T, U]) ForcePushBack(v ...T)

Description: Pushes an element to the back of the circular buffer. Equivalent to appending a single value to the end of the circular buffer.

Time Complexity: O(m), where m=len(vals)

func (*CircularBuffer[T, U]) ForcePushFront

func (c *CircularBuffer[T, U]) ForcePushFront(v ...T)

Description: Pushes an element to the back of the circular buffer, poping an element from the front of the buffer if necessary to make room for the new element. If the circular buffer is full then this is equavilent to poping and then pushing, but more efficient.

Time Complexity: O(n+m), where m=len(vals)

func (CircularBuffer[T, U]) Format

func (c CircularBuffer[T, U]) Format(f fmt.State, verb rune)

Implements the fmt.Formatter interface.

func (*CircularBuffer[T, U]) Full

func (c *CircularBuffer[T, U]) Full() bool

Description: Returns true if the circular buffer has reached its capacity, false otherwise.

Time Complexity: O(1)

func (*CircularBuffer[T, U]) Get

func (c *CircularBuffer[T, U]) Get(idx int) (T, error)

Description: Gets the value at the specified index. Returns an error if the index is >= the length of the circular buffer.

Time Complexity: O(1)

func (*CircularBuffer[T, U]) GetPntr

func (c *CircularBuffer[T, U]) GetPntr(idx int) (*T, error)

Description: Gets a pointer to the value at the specified index. Returns an error if the index is >= the length of the circular buffer.

Time Complexity: O(1)

func (*CircularBuffer[T, U]) GetUnique

func (c *CircularBuffer[T, U]) GetUnique(v *T) error

Description: Populates the supplied value with the value that is in the container. This is useful when storing structs and the structs identity as defined by the U widget only depends on a subset of the structs fields. This function allows for getting the entire value based on just the part of the struct that defines it's identity. Returns a value error if the value is not found in the circular buffer.

Time complexity: O(n)

func (*CircularBuffer[T, U]) Hash

func (_ *CircularBuffer[T, U]) Hash(other *CircularBuffer[T, U]) hash.Hash

A function that returns a hash of a circular buffer to implement the [algo.widget.WidgetInterface]. To do this all of the individual hashes that are produced from the elements of the circular buffer are combined in a way that maintains identity, making it so the hash will represent the same equality operation that CircularBuffer.KeyedEq and CircularBuffer.Eq provide.

func (*CircularBuffer[T, U]) Insert

func (c *CircularBuffer[T, U]) Insert(vals ...basic.Pair[int, T]) error

Description: Insert will insert the supplied values into the circular buffer. The values will be inserted in the order that they are given.

Time Complexity: O(n*m), where m=len(vals)

func (*CircularBuffer[T, U]) InsertSequential

func (c *CircularBuffer[T, U]) InsertSequential(idx int, vals ...T) error

Description: Inserts the supplied values at the given index. Returns an error if the index is >= the length of the circular buffer.

Time Complexity: O(n+m), where m=len(vals)

func (*CircularBuffer[T, U]) Intersection

Description: Populates the circular buffer with the intersection of values from the l and r containers. This circular buffer will be cleared before storing the result. When clearing, the new resulting circular buffer will be initialized with length equivalent to l.Length()+r.Length(). This is necessary to guarintee that all values will fit in the resulting statically allocated circular buffer.

Time Complexity: Dependent on the time complexity of the implementation of the ContainsPntr method on l and r. In big-O it might look something like this, O(O(r.ContainsPntr)*O(l.ContainsPntr)), where O(r.ContainsPntr) represents the time complexity of the containsPntr method on r and O(l.ContainsPntr) represents the time complexity of the containsPntr method on l.

func (*CircularBuffer[T, U]) IsAddressable

func (c *CircularBuffer[T, U]) IsAddressable() bool

Returns true, a circular biffer is addressable.

func (*CircularBuffer[T, U]) IsSubset

func (c *CircularBuffer[T, U]) IsSubset(
	other containerTypes.ComparisonsOtherConstraint[T],
) bool

Description: Returns true if this circular buffer is a subset to other.

Time Complexity: Dependent on the ContainsPntr method of other. In big-O terms it may look somwthing like this: O(n*O(other.ContainsPntr)), where n is the number of elements in the current circular buffer and other.ContainsPntr represents the time complexity of the containsPntr method on other.

func (*CircularBuffer[T, U]) IsSuperset

func (c *CircularBuffer[T, U]) IsSuperset(
	other containerTypes.ComparisonsOtherConstraint[T],
) bool

Description: Returns true if this circular buffer is a superset to other.

Time Complexity: O(n*m), where n is the number of values in this circular buffer and m is the number of values in other.

func (*CircularBuffer[T, U]) IsSynced

func (c *CircularBuffer[T, U]) IsSynced() bool

Returns false, a circular buffer is not synced.

func (*CircularBuffer[T, U]) KeyOf

func (c *CircularBuffer[T, U]) KeyOf(val T) (int, bool)

Description: KeyOf will return the index of the first occurrence of the supplied value in the circular buffer. If the value is not found then the returned index will be -1 and the boolean flag will be set to false. If the value is found then the boolean flag will be set to true. All equality comparisons are performed by the generic U widget type that the circular buffer was initialized with.

Time Complexity: O(n) (linear search)

func (*CircularBuffer[T, U]) KeyOfPntr

func (c *CircularBuffer[T, U]) KeyOfPntr(val *T) (int, bool)

Description: KeyOfPntr will return the index of the first occurrence of the supplied value in the circular buffer. If the value is not found then the returned index will be -1 and the boolean flag will be set to false. If the value is found then the boolean flag will be set to true. All equality comparisons are performed by the generic U widget type that the circular buffer was initialized with.

Time Complexity: O(n) (linear search)

func (*CircularBuffer[T, U]) KeyedEq

func (c *CircularBuffer[T, U]) KeyedEq(
	other containerTypes.KeyedComparisonsOtherConstraint[int, T],
) bool

Description: Returns true if all the key value pairs in v are all contained in other and the key value pairs in other are all contained in v. Returns false otherwise.

Time Complexity: Dependent on the time complexity of the implementation of the Get/GetPntr method on other. In big-O it might look something like this, O(n*O(other.GetPntr))), where n is the number of elements in c and O(other.ContainsPntr) represents the time complexity of the containsPntr method on other.

func (*CircularBuffer[T, U]) Keys

func (c *CircularBuffer[T, U]) Keys() iter.Iter[int]

Description: Returns an iterator that iterates over the keys (indexes) of the circular buffer. The circular buffer will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator starts to be consumed.

Time Complexity: O(n)

func (*CircularBuffer[T, U]) Length

func (c *CircularBuffer[T, U]) Length() int

Description: Returns the length of the circular buffer.

Time Complexity: O(1)

func (*CircularBuffer[T, U]) Lock

func (c *CircularBuffer[T, U]) Lock()

A empty pass through function that performs no action. Needed for the containerTypes.Comparisons interface.

func (*CircularBuffer[T, U]) PeekBack

func (c *CircularBuffer[T, U]) PeekBack() (T, error)

Description: Returns the value at index len(v)-1 if one is present. If the circular buffer has no elements then an error is returned.

Time Complexity: O(1)

func (*CircularBuffer[T, U]) PeekFront

func (c *CircularBuffer[T, U]) PeekFront() (T, error)

Description: Returns the value at index 0 if one is present. If the circular buffer has no elements then an error is returned.

Time Complexity: O(1)

func (*CircularBuffer[T, U]) PeekPntrBack

func (c *CircularBuffer[T, U]) PeekPntrBack() (*T, error)

Description: Returns a pointer to the value at index len(v)-1 if one is present. If the circular buffer has no elements then an error is returned.

Time Complexity: O(1)

func (*CircularBuffer[T, U]) PeekPntrFront

func (c *CircularBuffer[T, U]) PeekPntrFront() (*T, error)

Description: Returns a pointer to the value at index 0 if one is present. If the circular buffer has no elements then an error is returned.

Time Complexity: O(1)

func (*CircularBuffer[T, U]) Pop

func (c *CircularBuffer[T, U]) Pop(val T) int

Description: Pop will remove all occurrences of val in the circular buffer. All equality comparisons are performed by the generic U widget type that the circular buffer was initialized with.

Time Complexity: O(n)

func (*CircularBuffer[T, U]) PopBack

func (c *CircularBuffer[T, U]) PopBack() (T, error)

Description: Returns and removes the element at the back of the circular buffer. Returns an error if the circular buffer has no elements.

Time Complexity: O(1)

func (*CircularBuffer[T, U]) PopFront

func (c *CircularBuffer[T, U]) PopFront() (T, error)

Description: Returns and removes the element at the front of the circular buffer. Returns an error if the circular buffer has no elements.

Time Complexity: O(n)

func (*CircularBuffer[T, U]) PopPntr

func (c *CircularBuffer[T, U]) PopPntr(val *T) int

Description: PopPntr will remove all occurrences of val in the circular buffer. All equality comparisons are performed by the generic U widget type that the circular buffer was initialized with.

Time Complexity: O(n)

func (*CircularBuffer[T, U]) PopSequential

func (c *CircularBuffer[T, U]) PopSequential(val T, num int) int

Description: PopSequential will remove the first num occurrences of val in the circular buffer. All equality comparisons are performed by the generic U widget type that the circular buffer was initialized with. If num is <=0 then no values will be poped and the circular buffer will not change.

Time Complexity: O(n)

func (*CircularBuffer[T, U]) PushBack

func (c *CircularBuffer[T, U]) PushBack(v ...T) error

Description: Pushes an element to the back of the circular buffer. Equivalent to appending values to the end of the circular buffer. Values will be pushed back in the order that they are given. For example, calling push back on [0,1,2] with vals of [3,4] will result in [0,1,2,3,4].

Time Complexity: best case O(m), where m=len(vals)

func (*CircularBuffer[T, U]) PushFront

func (c *CircularBuffer[T, U]) PushFront(v ...T) error

Description: Pushes an element to the front of the circular buffer. Equivalent to inserting a single value at the front of the circular buffer. Values will be pushed to the front in the order that they are given. For example, calling push front on [0,1,2] with vals of [3,4] will result in [3,4,0,1,2].

Time Complexity: O(n+m), where m=len(vals)

func (*CircularBuffer[T, U]) RLock

func (c *CircularBuffer[T, U]) RLock()

A empty pass through function that performs no action. Needed for the containerTypes.Comparisons interface.

func (*CircularBuffer[T, U]) RUnlock

func (c *CircularBuffer[T, U]) RUnlock()

A empty pass through function that performs no action. Needed for the containerTypes.Comparisons interface.

func (*CircularBuffer[T, U]) Set

func (c *CircularBuffer[T, U]) Set(vals ...basic.Pair[int, T]) error

Description: Sets the values at the specified indexes. Returns an error if the index is >= the length of the circular buffer. Stops setting values as soon as an error is encountered.

Time Complexity: O(m), where m=len(vals)

func (*CircularBuffer[T, U]) SetSequential

func (c *CircularBuffer[T, U]) SetSequential(idx int, vals ...T) error

Description: Sets the supplied values sequentially starting at the supplied index and continuing sequentailly after that. Returns and error if any index that is attempted to be set is >= the length of the circular buffer. If an error occurs, all values will be set up until the value that caused the error.

Time Complexity: O(m), where m=len(vals)

func (*CircularBuffer[T, U]) String

func (c *CircularBuffer[T, U]) String() string

Implements the fmt.Stringer interface.

func (*CircularBuffer[T, U]) ToSynced

func (c *CircularBuffer[T, U]) ToSynced() SyncedCircularBuffer[T, U]

Converts the supplied map to a syncronized map. Beware: The original non-synced circular buffer will remain useable.

func (*CircularBuffer[T, U]) Union

Description: Populates the circular buffer with the union of values from the l and r containers. This circular buffer will be cleared before storing the result. When clearing, the new resulting circular buffer will be initialized with length equivalent to l.Length()+r.Length(). This is necessary to guarintee that all values will fit in the resulting statically allocated circular buffer.

Time Complexity: O((n+m)*(n+m)), where n is the number of values in l and m is the number of values in r.

func (*CircularBuffer[T, U]) Unlock

func (c *CircularBuffer[T, U]) Unlock()

A empty pass through function that performs no action. Needed for the containerTypes.Comparisons interface.

func (*CircularBuffer[T, U]) UnorderedEq

func (c *CircularBuffer[T, U]) UnorderedEq(
	other containerTypes.ComparisonsOtherConstraint[T],
) bool

Description: Returns true if the elements in v are all contained in other and the elements of other are all contained in v, regardless of position. Returns false otherwise.

Time Complexity: Dependent on the time complexity of the implementation of the ContainsPntr method on other. In big-O it might look something like this, O(n*O(other.ContainsPntr))), where O(other.ContainsPntr) represents the time complexity of the ContainsPntr method on other with m values.

func (*CircularBuffer[T, U]) UpdateUnique

func (c *CircularBuffer[T, U]) UpdateUnique(
	orig T,
	updateOp func(orig *T),
) error

Description: updates the supplied value in the underlying circular buffer set, assuming that it is present in the circular buffer already. The hash must not change from the update and the updated value must compare equal to the original value. If these rules are broken then an update violation error will be returned. This method is useful when you are storing struct values and want to update a field that is not utilized when calculating the hash and is also ignored when comparing for equality. This assumes congruency is present between the hash and equality methods defined in the U widget. If the value is not found then a key error will be returned.

Time Complexity: O(n)

func (*CircularBuffer[T, U]) ValPntrs

func (c *CircularBuffer[T, U]) ValPntrs() iter.Iter[*T]

Description: Returns an iterator that iterates over the pointers to the values in the circular buffer. The circular buffer will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator is consumed.

Time Complexity: O(n)

func (*CircularBuffer[T, U]) Vals

func (c *CircularBuffer[T, U]) Vals() iter.Iter[T]

Description: Returns an iterator that iterates over the values in the circular buffer.

Time Complexity: O(n)

func (*CircularBuffer[T, U]) Zero

func (_ *CircularBuffer[T, U]) Zero(other *CircularBuffer[T, U])

An zero function that implements the [algo.widget.WidgetInterface] interface. Internally this is equivalent to CircularBuffer.Clear.

type HashGraph

type HashGraph[
	V any,
	E any,
	VI widgets.BaseInterface[V],
	EI widgets.BaseInterface[E],
] struct {
	// contains filtered or unexported fields
}

A type to represent an arbitrary directed graph with the specified vertex and edge types. The graph will maintain a set of vertices and edges that are linked together to make a graph. The type constraints on the generics define the logic for for how specific operations, such as equality comparisons, will be handled. The graph will grow as edges and vertices are added.

func NewHashGraph

func NewHashGraph[
	V any,
	E any,
	VI widgets.BaseInterface[V],
	EI widgets.BaseInterface[E],
](numVertices int, numEdges int) (HashGraph[V, E, VI, EI], error)

Creates a new hash graph initialized with enough memory to hold the specified amount of vertices and edges. Both numVertices and numEdges must be >=0, an error will be returned if either one violates that rule. If either size is 0 then the associated map will be initialized with 0 elements.

func (HashGraph) AddEdges

func (g HashGraph) AddEdges(e ...E) error

Description: Adds edges to the graph without connecting them to any vertices. Duplicate edges will be ignored. This method will never return an error.

Time Complexity: O(n), where n=len(e)

func (HashGraph) AddVertices

func (g HashGraph) AddVertices(v ...V) error

Description: Adds a vertex to the graph, if it does not already exist according to the hash and equals method on the vertex widget interface. Non- unique vertices will not be added. This function will never return an error.

Time Complexity: O(n), where n=len(v)

func (HashGraph) Clear

func (g HashGraph) Clear()

Description: Removes all edges, vertices, and links.

Time Complexity: O(n+m), where n=num vertices and m=num edges

func (HashGraph) ContainsEdge

func (g HashGraph) ContainsEdge(e E) bool

Description: Returns true if the supplied edge is contained within the graph. All equality comparisons are performed by the generic EI widget type that the hash graph was initialized with.

Time Complexity: O(1)

func (HashGraph) ContainsEdgePntr

func (g HashGraph) ContainsEdgePntr(e *E) bool

Description: ContainsEdgePntr will return true if the supplied edge is in the hash graph, false otherwise. All equality comparisons are performed by the generic EI widget type that the hash graph was initialized with.

Time Complexity: O(1)

func (g HashGraph) ContainsLink(from V, to V, e E) bool

Description: Returns true if the supplied edge links the supplied vertices.

Time Complexity: O(n), where n=num outgoing edges from the starting vertex.

func (HashGraph) ContainsLinkPntr

func (g HashGraph) ContainsLinkPntr(from *V, to *V, e *E) bool

Description: Returns true if the supplied edge links the supplied vertices.

Time Complexity: O(n), where n=num outgoing edges from the starting vertex.

func (HashGraph) ContainsVertex

func (g HashGraph) ContainsVertex(v V) bool

Description: Returns true if the supplied vertex is contained within the graph. All equality comparisons are performed by the generic VI widget type that the hash graph was initialized with.

Time Complexity: O(1)

func (HashGraph) ContainsVertexPntr

func (g HashGraph) ContainsVertexPntr(v *V) bool

Description: ContainsVertexPntr will return true if the supplied vertex is in the hash graph, false otherwise. All equality comparisons are performed by the generic VI widget type that the hash graph was initialized with.

Time Complexity: O(1)

func (HashGraph) DeleteEdge

func (g HashGraph) DeleteEdge(e E) error

Description: Deletes an edge from the graph, removing any links that previously used the vertex. No vertices will be deleted, meaning this operation may result in orphaned vertices.

Time Complexity: O(n), where n=num of links in the graph

func (HashGraph) DeleteEdgePntr

func (g HashGraph) DeleteEdgePntr(e *E) error

Description: Deletes an edge from the graph, removing any links that previously used the vertex. No vertices will be deleted, meaning this operation may result in orphaned vertices.

Time Complexity: O(n), where n=num of links in the graph

func (g HashGraph) DeleteLink(from V, to V, e E) error

Description: Removes a link within the graph without removing the underlying vertices or edge. This may leave vertices with no links, and edges that don't correspond to any links. An error will be returned if either vertice does not exist in the graph or if the supplied edge does not exist in the graph.

Time Complexity: O(n), where n=num of outgoing edges on the from vertex

func (HashGraph) DeleteLinkPntr

func (g HashGraph) DeleteLinkPntr(from *V, to *V, e *E) error

Description: Removes a link within the graph without removing the underlying vertices or edge. This may leave vertices with no links, and edges that don't correspond to any links. An error will be returned if either vertice does not exist in the graph or if the supplied edge does not exist in the graph.

Time Complexity: O(n), where n=num of outgoing edges on the from vertex

func (g HashGraph) DeleteLinks(from V, to V) error

Description: Removes all links starting at from and ending at to without removing the underlying vertices or edges. This may leave vertices with no links, and edges that don't correspond to any links. An error will be returned if either vertex does not exist in the graph.

Time Complexity: O(n), where n=num of outgoing edges on the from vertex

func (HashGraph) DeleteLinksPntr

func (g HashGraph) DeleteLinksPntr(from *V, to *V) error

Description: Removes all links starting at from and ending at to without removing the underlying vertices or edges. This may leave vertices with no links, and edges that don't correspond to any links. An error will be returned if either vertex does not exist in the graph.

Time Complexity: O(n), where n=num of outgoing edges on the from vertex

func (HashGraph) DeleteVertex

func (g HashGraph) DeleteVertex(v V) error

Description: Deletes a vertex from the graph, removing any links that previously used the vertex. No edges will be deleted, meaning this operation may result in orphaned edges.

Time Complexity: O(n), where n=num of links in the graph

func (HashGraph) DeleteVertexPntr

func (g HashGraph) DeleteVertexPntr(v *V) error

Description: Deletes a vertex from the graph, removing any links that previously used the vertex. No edges will be deleted, meaning this operation may result in orphaned edges.

Time Complexity: O(n), where n=num of links in the graph

func (HashGraph) Difference

func (g HashGraph) Difference(
	l containerTypes.GraphComparisonsConstraint[V, E],
	r containerTypes.GraphComparisonsConstraint[V, E],
)

Description: Takes the difference of l and r and puts the result in this graph. All values from this graph will be cleared before storing the new result. Vertices and edges are compared using the supplied VI and EI widgets.

Time Complexity: Dependent on the time complexity of the implementation of the ContainsLinkPntr method on other. In big-O it might look something like this, O((n+m)*O(other.ContainsLinkPntr))), where n is the number of links in r and m is the number of links in l. O(other.ContainsLinkPntr) represents the time complexity of the ContainsLinkPntr method on other.

func (HashGraph) EdgePntrs

func (g HashGraph) EdgePntrs() iter.Iter[*E]

Panics, hash graphs are not addressable.

func (HashGraph) Edges

func (g HashGraph) Edges() iter.Iter[E]

Description: Returns an iterator that iterates over the edges in the graph.

Time Complexity: O(n), where n=num edges

func (HashGraph) EdgesBetween

func (g HashGraph) EdgesBetween(from V, to V) iter.Iter[E]

Description: Returns the list of edges that exist between the supplied vertices. Any returned edges will follow the direction specified by the arguments.

Time Complexity: O(n), where n=the number of outgoing edges on the from vertex

func (HashGraph) EdgesBetweenPntr

func (g HashGraph) EdgesBetweenPntr(from *V, to *V) iter.Iter[*E]

Panics, hash graphs are non-addressable.

func (*HashGraph[V, E, VI, EI]) Eq

func (_ *HashGraph[V, E, VI, EI]) Eq(
	l *HashGraph[V, E, VI, EI],
	r *HashGraph[V, E, VI, EI],
) bool

An equality function that implements the [algo.widget.WidgetInterface] interface. Internally this is equivalent to HashGraph.KeyedEq. Returns true if l==r, false otherwise.

func (HashGraph) GetEdge

func (g HashGraph) GetEdge(e *E) error

Description: Populates the supplied value with the edge value that is in the graph. This is useful when storing structs and the structs identity as defined by the EI widget only depends on a subset of the structs fields. This function allows for getting the entire value based on just the part of the struct that defines it's identity. Returns a value error if the value is not found in the graph.

Time complexity: O(1)

func (HashGraph) GetVertex

func (g HashGraph) GetVertex(v *V) error

Description: Populates the supplied value with the vertex value that is in the graph. This is useful when storing structs and the structs identity as defined by the VI widget only depends on a subset of the structs fields. This function allows for getting the entire value based on just the part of the struct that defines it's identity. Returns a value error if the value is not found in the graph.

Time complexity: O(1)

func (*HashGraph[V, E, VI, EI]) Hash

func (_ *HashGraph[V, E, VI, EI]) Hash(
	other *HashGraph[V, E, VI, EI],
) hash.Hash

A function that returns a hash of a hash graph. To do this all of the individual hashes that are produced from the elements of the hash graph are combined in a way that maintains identity, making it so the hash will represent the same equality operation that HashGraph.KeyedEq and HashGraph.Eq provide.

func (HashGraph) Intersection

func (g HashGraph) Intersection(
	l containerTypes.GraphComparisonsConstraint[V, E],
	r containerTypes.GraphComparisonsConstraint[V, E],
)

Description: Takes the intersection of l and r and puts the result in this graph. All values from this graph will be cleared before storing the new result. Vertices and edges are compared using the supplied VI and EI widgets.

Time Complexity: Dependent on the time complexity of the implementation of the ContainsLinkPntr method on other. In big-O it might look something like this, O(n*O(other.ContainsLinkPntr))), where n is the number of links in r and O(other.ContainsLinkPntr) represents the time complexity of the ContainsLinkPntr method on other.

func (HashGraph) IsAddressable

func (g HashGraph) IsAddressable() bool

Returns false, hash graphs are not addressable. (Due to being built out of maps.)

func (HashGraph) IsSubset

func (g HashGraph) IsSubset(
	other containerTypes.GraphComparisonsConstraint[V, E],
) bool

Description: Returns true if this graph is a subset of other. In order for this graph to be a subset of other, other must have all of this graphs vertices, edges, and links. Other may have other vertices, edges, or links that are not in this graph. All of the corresponding vertices and edges must be equal as defined by the Eq method of the supplied VI and EI widgets.

Time Complexity: Dependent on the time complexity of the implementation of the methods on other. In big-O it might look something like this, O(n*O(other.ContainsLink) + m*O(other.ContainsVertexPntr) + p*O(other.ContainsEdgePntr)) where:

  • n is the number of links in this graph
  • m is the number of vertices in this graph
  • p is the number of edges in this graph
  • O(other.ContainsLink) represents the time complexity of the ContainsLink method on other
  • O(other.ContainsVertexPntr) represents the time complexity of the ContainsVertexPntr method on other
  • O(other.ContainsEdgePntr) represents the time complexity of the ContainsEdgePntr method on other

func (HashGraph) IsSuperset

func (g HashGraph) IsSuperset(
	other containerTypes.GraphComparisonsConstraint[V, E],
) bool

Description: Returns true if this graph is a superset of other. In order for this graph to be a superset of other, it must have all of others vertices, edges, and links. It may have other vertices, edges, or links that are not in other. All of the corresponding vertices and edges must be equal as defined by the Eq method of the supplied VI and EI widgets.

Time Complexity: Dependent on the time complexity of the implementation of the methods on other. In big-O it might look something like this, O(n*O(other.ContainsLink) + m*O(other.ContainsVertexPntr) + p*O(other.ContainsEdgePntr)) where:

  • n is the number of links in this graph
  • m is the number of vertices in this graph
  • p is the number of edges in this graph
  • O(other.ContainsLink) represents the time complexity of the ContainsLink method on other
  • O(other.ContainsVertexPntr) represents the time complexity of the ContainsVertexPntr method on other
  • O(other.ContainsEdgePntr) represents the time complexity of the ContainsEdgePntr method on other

func (HashGraph) IsSynced

func (g HashGraph) IsSynced() bool

Returns false, a hash graph is not synced.

func (HashGraph) KeyedEq

func (g HashGraph) KeyedEq(
	other containerTypes.GraphComparisonsConstraint[V, E],
) bool

Description: Returns true if the two supplied graphs are considered equal. In order for two graphs to be equal they must have the same structure and all of the corresponding vertices and edges must be equal as defined by the Eq method of the supplied VI and EI widgets.

Time Complexity: Dependent on the time complexity of the implementation of the methods on other. In big-O it might look something like this, O(n*O(other.ContainsLink) + m*O(other.ContainsVertexPntr) + p*O(other.ContainsEdgePntr)) where:

  • n is the number of links in this graph
  • m is the number of vertices in this graph
  • p is the number of edges in this graph
  • O(other.ContainsLink) represents the time complexity of the ContainsLink method on other
  • O(other.ContainsVertexPntr) represents the time complexity of the ContainsVertexPntr method on other
  • O(other.ContainsEdgePntr) represents the time complexity of the ContainsEdgePntr method on other
func (g HashGraph) Link(from V, to V, e E) error

Description: Adds a link between an existing edge and vertices in the graph. The edge and vertices must have been added to the graph prior to calling this function or an error will be returned. If a link already exists between the provided vertices with the provided edge then no action will be taken and no error will be returned.

Time Complexity: O(n), where n=num of outgoing edges from the start vertex

func (HashGraph) LinkPntr

func (g HashGraph) LinkPntr(from *V, to *V, e *E) error

Description: Adds a link between an existing edge and vertices in the graph. The edge and vertices must have been added to the graph prior to calling this function or an error will be returned. If a link already exists between the provided vertices with the provided edge then no action will be taken and no error will be returned.

Time Complexity: O(n), where n=num of outgoing edges from the start vertex

func (HashGraph) Lock

func (g HashGraph) Lock()

A empty pass through function that performs no action. Needed for the dynamicContainers.Comparisons interface.

func (HashGraph) NumEdges

func (g HashGraph) NumEdges() int

Description: NumEdges will return the number of edges in the graph. This will include any unconnected edges.

Time Complexity: O(1)

func (g HashGraph) NumLinks() int

Description: NumLinks will return the number of links in the graph. This is different from the number of edges, as the number of links will not include any orphaned edges.

Time Complexity: O(1)

func (g HashGraph) NumOutLinks(v V) int

Description: Returns the number of outgoing edges from the supplied vertex

Time Complexity: O(1)

func (HashGraph) NumOutLinksPntr

func (g HashGraph) NumOutLinksPntr(v *V) int

Description: Returns the number of outgoing edges from the supplied vertex

Time Complexity: O(1)

func (HashGraph) NumVertices

func (g HashGraph) NumVertices() int

Description: NumVertices will return the number of edges in the graph. This will include any unconnected vertices.

Time Complexity: O(1)

func (HashGraph) OutEdgePntrs

func (g HashGraph) OutEdgePntrs(v *V) iter.Iter[*E]

Panics, hash graphs are non-addressable.

func (HashGraph) OutEdges

func (g HashGraph) OutEdges(v V) iter.Iter[E]

Description: Returns an iterator that supplies all of the outgoing edges from the supplied vertex. Duplicate edges will not be filtered out, meaning a single edge may be returned multiple times by the iterator.

Time Complexity: O(n), where n=num of outgoing edges

func (HashGraph) OutEdgesAndVerticePntrs

func (g HashGraph) OutEdgesAndVerticePntrs(
	v *V,
) iter.Iter[basic.Pair[*E, *V]]

Panics, hash graphs are non-addressable.

func (HashGraph) OutEdgesAndVertices

func (g HashGraph) OutEdgesAndVertices(
	v V,
) iter.Iter[basic.Pair[E, V]]

Description: Returns an iterator that supplies all of the outgoing edges paired with there associated vertices.

Time Complexity: O(n), where n=num of outgoing edges

func (HashGraph) OutVerticePntrs

func (g HashGraph) OutVerticePntrs(v *V) iter.Iter[*V]

Panics, hash graphs are non-addressable

func (HashGraph) OutVertices

func (g HashGraph) OutVertices(v V) iter.Iter[V]

Description: Returns an iterator that supplies all of the outgoing vertices from the supplied vertex. Duplicate vertices will not be filtered out, meaning a single vertex may be returned multiple times by the iterator.

Time Complexity: O(n), where n=num of outgoing edges

func (HashGraph) RLock

func (g HashGraph) RLock()

A empty pass through function that performs no action. Needed for the dynamicContainers.Comparisons interface.

func (HashGraph) RUnlock

func (g HashGraph) RUnlock()

A empty pass through function that performs no action. Needed for the dynamicContainers.Comparisons interface.

func (HashGraph) ToSynced

func (g HashGraph) ToSynced() SyncedHashGraph[V, E, VI, EI]

Converts the supplied graph to a synchronized graph. Beware: The original non-synced map will remain useable.

func (HashGraph) Union

Description: Takes the union of l and r and puts the result in this graph. All values from this graph will be cleared before storing the new result. Vertices and edges are compared using the supplied VI and EI widgets.

Time Complexity: Dependent on the time complexity of the implementation of the ContainsLinkPntr method on other. In big-O it might look something like this, O((n+m)*O(other.ContainsLinkPntr))), where n is the number of links in r and m is the number of links in l. O(other.ContainsLinkPntr) represents the time complexity of the ContainsLinkPntr method on other.

func (HashGraph) Unlock

func (g HashGraph) Unlock()

A empty pass through function that performs no action. Needed for the dynamicContainers.Comparisons interface.

func (HashGraph) UnorderedEq

func (g HashGraph) UnorderedEq(
	other containerTypes.GraphComparisonsConstraint[V, E],
) bool

TODO: Isomorphic equality

func (HashGraph) UpdateEdge

func (g HashGraph) UpdateEdge(
	e E,
	updateOp func(e *E),
) error

Description: Updates the supplied edge using the supplied operation. All uniqueness constraints that are imposed on a set are imposed here as well. This means that the updated value must compare equal to the original value according to the EI widget and produce the same hash as the original value.

Time Complexity: O(1)

func (HashGraph) UpdateVertex

func (g HashGraph) UpdateVertex(
	v V,
	updateOp func(orig *V),
) error

Description: Updates the supplied vertex using the supplied operation. All uniqueness constraints that are imposed on a set are imposed here as well. This means that the updated value must compare equal to the original value according to the VI widget and produce the same hash as the original value.

Time Complexity: O(1)

func (HashGraph) VerticePntrs

func (g HashGraph) VerticePntrs() iter.Iter[*V]

Panics, hash graphs are not addressable.

func (HashGraph) Vertices

func (g HashGraph) Vertices() iter.Iter[V]

Description: Returns an iterator that iterates over the vertices in the graph.

Time Complexity: O(n), where n=num edges

func (*HashGraph[V, E, VI, EI]) Zero

func (_ *HashGraph[V, E, VI, EI]) Zero(other *HashGraph[V, E, VI, EI])

An zero function that implements the [algo.widget.WidgetInterface] interface. Internally this is equivalent to HashGraph.Clear.

type HashMap

type HashMap[
	K any,
	V any,
	KI widgets.BaseInterface[K],
	VI widgets.BaseInterface[V],
] struct {
	// contains filtered or unexported fields
}

A type to represent a map that dynamically grows as key value pairs are added. The set will maintain uniqueness and is internally implemented with a hashing method. The type constraints on the generics define the logic for how value specific operations, such as equality comparisons, will be handled.

func HashMapValInit

func HashMapValInit[
	K any,
	V any,
	KI widgets.BaseInterface[K],
	VI widgets.BaseInterface[V],
](vals []basic.Pair[K, V]) HashMap[K, V, KI, VI]

Creates a new hash map and populates it with the supplied values. If there are duplicated keys in the supplied slice the last key-value pair will be what is in the returned map.

func NewHashMap

func NewHashMap[
	K any,
	V any,
	KI widgets.BaseInterface[K],
	VI widgets.BaseInterface[V],
](size int) (HashMap[K, V, KI, VI], error)

Creates a new map initialized with enough memory to hold size elements. Size must be >= 0, an error will be returned if it is not. If size is 0 the map will be initialized with 0 elements.

func (*HashMap[K, V, KI, VI]) Clear

func (m *HashMap[K, V, KI, VI]) Clear()

Description: Clears all values from the map. Equivalent to making a new hash map and setting it equal to the current one.

Time Complexity: O(1)

func (*HashMap[K, V, KI, VI]) Contains

func (m *HashMap[K, V, KI, VI]) Contains(v V) bool

Description: Contains will return true if the supplied value is in the map, false otherwise. All equality comparisons are performed by the generic VI widget type that the hash map was initialized with.

Time Complexity: O(n) (linear search)

func (*HashMap[K, V, KI, VI]) ContainsPntr

func (m *HashMap[K, V, KI, VI]) ContainsPntr(v *V) bool

Description: ContainsPntr will return true if the supplied value is in the map, false otherwise. All equality comparisons are performed by the generic VI widget type that the map was initialized with.

Time Complexity: O(n) (linear search)

func (*HashMap[K, V, KI, VI]) Delete

func (m *HashMap[K, V, KI, VI]) Delete(k K) error

Description: Deletes the key value pair that has the specified key. Returns an error if the key is not found in the hash map.

Time Complexity: O(1)

func (*HashMap[K, V, KI, VI]) Emplace

func (m *HashMap[K, V, KI, VI]) Emplace(vals ...basic.Pair[K, V]) error

Description: Emplace will insert the supplied values into the hash map if they do not exist and will set they keys value if it already exists in the hash map. The values will be inserted in the order that they are given.

Time Complexity: O(m), where m=len(vals)

func (*HashMap[K, V, KI, VI]) Eq

func (_ *HashMap[K, V, KI, VI]) Eq(
	l *HashMap[K, V, KI, VI],
	r *HashMap[K, V, KI, VI],
) bool

An equality function that implements the [algo.widget.WidgetInterface] interface. Internally this is equivalent to HashMap.KeyedEq. Returns true if l==r, false otherwise.

func (HashMap[K, V, KI, VI]) Format

func (m HashMap[K, V, KI, VI]) Format(f fmt.State, verb rune)

Implements the fmt.Formatter interface.

func (*HashMap[K, V, KI, VI]) Get

func (m *HashMap[K, V, KI, VI]) Get(k K) (V, error)

Description: Gets the value at the specified key. Returns a containerTypes.KeyError if the key is not found in the hash map.

Time Complexity: O(1)

func (*HashMap[K, V, KI, VI]) GetPntr

func (m *HashMap[K, V, KI, VI]) GetPntr(k K) (*V, error)

Panics, hash maps are not addressable.

func (*HashMap[K, V, KI, VI]) Hash

func (_ *HashMap[K, V, KI, VI]) Hash(other *HashMap[K, V, KI, VI]) hash.Hash

A function that returns a hash of a hash map. To do this all of the individual hashes that are produced from the elements of the hash map are combined in a way that maintains identity, making it so the hash will represent the same equality operation that HashMap.KeyedEq and HashMap.Eq provide.

func (*HashMap[K, V, KI, VI]) IsAddressable

func (m *HashMap[K, V, KI, VI]) IsAddressable() bool

Returns false, maps are not addressable.

func (*HashMap[K, V, KI, VI]) IsSynced

func (m *HashMap[K, V, KI, VI]) IsSynced() bool

Returns false, a map is not synced.

func (*HashMap[K, V, KI, VI]) KeyOf

func (m *HashMap[K, V, KI, VI]) KeyOf(v V) (K, bool)

Description: KeyOf will return the key of the first occurrence of the supplied value in the map. If the value is not found then the returned key will be a zero initialized key value and the boolean flag will be set to false. If the value is found then the boolean flag will be set to true. All equality comparisons are performed by the generic VI widget type that the map was initialized with.

Time Complexity: O(n) (linear search)

func (*HashMap[K, V, KI, VI]) KeyOfPntr

func (m *HashMap[K, V, KI, VI]) KeyOfPntr(v *V) (K, bool)

Description: KeyOfPntr will return the key of the first occurrence of the supplied value in the map. If the value is not found then the returned key will be a zero initialized key value and the boolean flag will be set to false. If the value is found then the boolean flag will be set to true. All equality comparisons are performed by the generic VI widget type that the map was initialized with.

Time Complexity: O(n) (linear search)

func (*HashMap[K, V, KI, VI]) KeyedEq

func (m *HashMap[K, V, KI, VI]) KeyedEq(
	other containerTypes.KeyedComparisonsOtherConstraint[K, V],
) bool

Description: Returns true if all the key value pairs in v are all contained in other and the key value pairs in other are all contained in v. Returns false otherwise.

Time Complexity: Dependent on the time complexity of the implementation of the Get/GetPntr method on other. In big-O it might look something like this, O(n*O(other.GetPntr))), where n is the number of elements in v and O(other.ContainsPntr) represents the time complexity of the containsPntr method on other.

func (*HashMap[K, V, KI, VI]) Keys

func (m *HashMap[K, V, KI, VI]) Keys() iter.Iter[K]

Description: Returns an iterator that iterates over the keys of the hash map. The hash map will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator starts to be consumed.

Time Complexity: O(n)

func (*HashMap[K, V, KI, VI]) Length

func (m *HashMap[K, V, KI, VI]) Length() int

Description: Returns the number of elements in the hash map.

Time Complexity: O(1)

func (*HashMap[K, V, KI, VI]) Lock

func (m *HashMap[K, V, KI, VI]) Lock()

A empty pass through function that performs no action. Needed for the containerTypes.Comparisons interface.

func (*HashMap[K, V, KI, VI]) Pop

func (m *HashMap[K, V, KI, VI]) Pop(v V) int

Description: Pop will remove all occurrences of val in the map. All equality comparisons are performed by the generic VI widget type that the map was initialized with.

Time Complexity: O(1)

func (*HashMap[K, V, KI, VI]) PopPntr

func (m *HashMap[K, V, KI, VI]) PopPntr(v *V) int

Description: PopPntr will remove all occurrences of val in the map. All equality comparisons are performed by the generic VI widget type that the map was initialized with.

Time Complexity: O(1)

func (*HashMap[K, V, KI, VI]) RLock

func (m *HashMap[K, V, KI, VI]) RLock()

A empty pass through function that performs no action. Needed for the containerTypes.Comparisons interface.

func (*HashMap[K, V, KI, VI]) RUnlock

func (m *HashMap[K, V, KI, VI]) RUnlock()

A empty pass through function that performs no action. Needed for the containerTypes.Comparisons interface.

func (*HashMap[K, V, KI, VI]) Set

func (m *HashMap[K, V, KI, VI]) Set(kvPairs ...basic.Pair[K, V]) error

Description: Sets the values at the specified keys. Returns an error if the key is not in the map. Stops setting values as soon as an error is encountered.

Time Complexity: O(m), where m=len(vals)

func (*HashMap[K, V, KI, VI]) String

func (m *HashMap[K, V, KI, VI]) String() string

Implements the fmt.Stringer interface.

func (*HashMap[K, V, KI, VI]) ToSynced

func (m *HashMap[K, V, KI, VI]) ToSynced() SyncedHashMap[K, V, KI, VI]

Converts the supplied map to a synchronized map. Beware: The original non-synced map will remain useable.

func (*HashMap[K, V, KI, VI]) Unlock

func (m *HashMap[K, V, KI, VI]) Unlock()

A empty pass through function that performs no action. Needed for the containerTypes.Comparisons interface.

func (*HashMap[K, V, KI, VI]) ValPntrs

func (m *HashMap[K, V, KI, VI]) ValPntrs() iter.Iter[*V]

Panics, a hash set is not addressable.

func (*HashMap[K, V, KI, VI]) Vals

func (m *HashMap[K, V, KI, VI]) Vals() iter.Iter[V]

Description: Returns an iterator that iterates over the values in the hash map.

Time Complexity: O(n)

func (*HashMap[K, V, KI, VI]) Zero

func (_ *HashMap[K, V, KI, VI]) Zero(other *HashMap[K, V, KI, VI])

An zero function that implements the [algo.widget.WidgetInterface] interface. Internally this is equivalent to HashMap.Clear.

type HashSet

type HashSet[T any, U widgets.BaseInterface[T]] struct {
	// contains filtered or unexported fields
}

A type to represent a set that dynamically grows as elements are added. The set will maintain uniqueness and is internally implemented with a hashing method. The type constraints on the generics define the logic for how value specific operations, such as equality comparisons, will be handled.

func HashSetValInit

func HashSetValInit[T any, U widgets.BaseInterface[T]](
	vals ...T,
) HashSet[T, U]

Creates a new hash set and populates it with the supplied values. Duplicated values will be ignored.

func NewHashSet

func NewHashSet[
	T any,
	U widgets.BaseInterface[T],
](size int) (HashSet[T, U], error)

Creates a new hash set initialized with enough memory to hold size elements. Size must be >= 0, an error will be returned if it is not. If size is 0 the hash set will be initialized with 0 elements.

func (*HashSet[T, U]) AppendUnique

func (h *HashSet[T, U]) AppendUnique(vals ...T) error

Description: AppendUnique will append the supplied values to the hash set if they are not already present in the hash set (unique). Non-unique values will not be appended. This function will never return an error.

Time Complexity: Best case O(m) (no reallocation), worst case O(n+m) (reallocation), where m=len(vals).

func (*HashSet[T, U]) Clear

func (h *HashSet[T, U]) Clear()

Description: Clears all values from the hash set. Equivalent to making a new hash set and setting it equal to the current one.

Time Complexity: O(1)

func (*HashSet[T, U]) Contains

func (h *HashSet[T, U]) Contains(v T) bool

Description: Contains will return true if the supplied value is in the hash set, false otherwise. All equality comparisons are performed by the generic U widget type that the hash set was initialized with.

Time Complexity: O(1).

func (*HashSet[T, U]) ContainsPntr

func (h *HashSet[T, U]) ContainsPntr(v *T) bool

Description: ContainsPntr will return true if the supplied value is in the hash set, false otherwise. All equality comparisons are performed by the generic U widget type that the hash set was initialized with.

Time Complexity: O(1)

func (*HashSet[T, U]) Difference

func (h *HashSet[T, U]) Difference(
	l containerTypes.ComparisonsOtherConstraint[T],
	r containerTypes.ComparisonsOtherConstraint[T],
)

Description: Populates the hash set with the result of taking the difference of r from l. This hash set will be cleared before storing the result. When clearing, the new resulting hash set will be initialized with zero capacity and enough backing memory to store half the length of l. This means that there should be at most 1 reallocation beyond this initial allocation, and that additional allocation should only occur when the length of the difference is greater than half the length of l. This logic is predicated on the fact that differences will likely be much smaller than the original hash set.

Time Complexity: Dependent on the time complexity of the implementation of the ContainsPntr method on l and r. In big-O it might look something like this, O(O(r.ContainsPntr)*O(l.ContainsPntr)), where O(r.ContainsPntr) represents the time complexity of the containsPntr method on r and O(l.ContainsPntr) represents the time complexity of the containsPntr method on l.

func (*HashSet[T, U]) Eq

func (_ *HashSet[T, U]) Eq(l *HashSet[T, U], r *HashSet[T, U]) bool

An equality function that implements the [algo.widget.WidgetInterface] interface. Internally this is equivalent to HashSet.UnorderedEq. Returns true if l==r, false otherwise.

func (HashSet[T, U]) Format

func (h HashSet[T, U]) Format(f fmt.State, verb rune)

Implements the fmt.Formatter interface.

func (*HashSet[T, U]) GetUnique

func (h *HashSet[T, U]) GetUnique(v *T) error

Description: Populates the supplied value with the value that is in the container. This is useful when storing structs and the structs identity as defined by the U widget only depends on a subset of the structs fields. This function allows for getting the entire value based on just the part of the struct that defines it's identity. Returns a value error if the value is not found in the set.

Time complexity: O(1)

func (*HashSet[T, U]) Hash

func (_ *HashSet[T, U]) Hash(other *HashSet[T, U]) hash.Hash

A function that returns a hash of a hash set. To do this all of the individual hashes that are produced from the elements of the hash set are combined in a way that maintains identity, making it so the hash will represent the same equality operation that [HashSet.KeyedEq] and HashSet.Eq provide.

func (*HashSet[T, U]) Intersection

func (h *HashSet[T, U]) Intersection(
	l containerTypes.ComparisonsOtherConstraint[T],
	r containerTypes.ComparisonsOtherConstraint[T],
)

Description: Populates the hash set with the intersection of values from the l and r containers. This hash set will be cleared before storing the result. When clearing, the new resulting hash set will be initialized with zero length and enough backing capacity to store (l.Length()+r.Length())/2 elements before reallocating. This means that there should be at most 1 reallocation beyond this initial allocation, and that additional allocation should only occur when the length of the intersection is greater than the average length of the l and r hash sets. This logic is predicated on the fact that intersections will likely be much smaller than the original hash sets.

Time Complexity: Dependent on the time complexity of the implementation of the ContainsPntr method on l and r. In big-O it might look something like this, O(O(r.ContainsPntr)*O(l.ContainsPntr)), where O(r.ContainsPntr) represents the time complexity of the containsPntr method on r and O(l.ContainsPntr) represents the time complexity of the containsPntr method on l.

func (*HashSet[T, U]) IsAddressable

func (h *HashSet[T, U]) IsAddressable() bool

Returns false, hash sets are not addressable.

func (*HashSet[T, U]) IsSubset

func (h *HashSet[T, U]) IsSubset(
	other containerTypes.ComparisonsOtherConstraint[T],
) bool

Description: Returns true if this hash set is a subset to other.

Time Complexity: Dependent on the ContainsPntr method of other. In big-O terms it may look somwthing like this: O(n*O(other.ContainsPntr)), where n is the number of elements in the current hash set and other.ContainsPntr represents the time complexity of the containsPntr method on other.

func (*HashSet[T, U]) IsSuperset

func (h *HashSet[T, U]) IsSuperset(
	other containerTypes.ComparisonsOtherConstraint[T],
) bool

Description: Returns true if this hash set is a superset to other.

Time Complexity: O(m), where m is the numbe rof values in other.

func (*HashSet[T, U]) IsSynced

func (h *HashSet[T, U]) IsSynced() bool

Returns false, a hash set is not synced.

func (*HashSet[T, U]) Length

func (h *HashSet[T, U]) Length() int

Description: Returns the number of values in the hash set.

Time Complexity: O(1)

func (*HashSet[T, U]) Lock

func (h *HashSet[T, U]) Lock()

A empty pass through function that performs no action. Needed for the containerTypes.Comparisons interface.

func (*HashSet[T, U]) Pop

func (h *HashSet[T, U]) Pop(v T) int

Description: Pop will remove all occurrences of val in the hash set. All equality comparisons are performed by the generic U widget type that the hash set was initialized with.

Time Complexity: O(1)

func (*HashSet[T, U]) PopPntr

func (h *HashSet[T, U]) PopPntr(v *T) int

Description: PopPntr will remove all occurrences of val in the hash set. All equality comparisons are performed by the generic U widget type that the hash set was initialized with.

Time Complexity: O(1)

func (*HashSet[T, U]) RLock

func (h *HashSet[T, U]) RLock()

A empty pass through function that performs no action. Needed for the containerTypes.Comparisons interface.

func (*HashSet[T, U]) RUnlock

func (h *HashSet[T, U]) RUnlock()

A empty pass through function that performs no action. Needed for the containerTypes.Comparisons interface.

func (*HashSet[T, U]) String

func (h *HashSet[T, U]) String() string

Implements the fmt.Stringer interface.

func (*HashSet[T, U]) ToSynced

func (v *HashSet[T, U]) ToSynced() SyncedHashSet[T, U]

Converts the supplied hash set to a syncronized hash set. Beware: The original non-synced hash set will remain useable.

func (*HashSet[T, U]) Union

Description: Populates the hash set with the union of values from the l and r containers. This hash set will be cleared before storing the result. When clearing, the new resulting hash set will be initialized with zero capacity and enough backing memory to store the average of the maximum and minimum possible union sizes before reallocating. This means that there should be at most 1 reallocation beyond this initial allocation, and that additional allocation should only occur when the length of the union is greater than the average length of the minumum and maximum possible union sizes. This logic is predicated on the fact that unions will likely be much smaller than the original hash sets.

Time Complexity: O((n+m)*(n+m)), where n is the number of values in l and m is the number of values in r.

func (*HashSet[T, U]) Unlock

func (h *HashSet[T, U]) Unlock()

A empty pass through function that performs no action. Needed for the containerTypes.Comparisons interface.

func (*HashSet[T, U]) UnorderedEq

func (h *HashSet[T, U]) UnorderedEq(
	other containerTypes.ComparisonsOtherConstraint[T],
) bool

Description: Returns true if the elements in h are all contained in other and the elements of other are all contained in h, regardless of position. Returns false otherwise.

Time Complexity: Dependent on the time complexity of the implementation of the ContainsPntr method on other. In big-O it might look something like this, O(n*O(other.ContainsPntr))), where O(other.ContainsPntr) represents the time complexity of the ContainsPntr method on other with m values.

func (*HashSet[T, U]) UpdateUnique

func (h *HashSet[T, U]) UpdateUnique(orig T, updateOp func(orig *T)) error

Description: updates the supplied value in the underlying hash set, assuming that it is present in the hash set already. The hash must not change from the update and the updated value must compare equal to the original value. If these rules are broken then an update violation error will be returned. This method is useful when you are storing struct values and want to update a field that is not utilized when calculating the hash and is also ignored when comparing for equality. This assumes congruency is present between the hash and equality methods defined in the U widget. If the value is not found then a key error will be returned.

Time Complexity: O(1)

func (*HashSet[T, U]) ValPntrs

func (h *HashSet[T, U]) ValPntrs() iter.Iter[*T]

Panics, hash sets are not addressable.

func (*HashSet[T, U]) Vals

func (h *HashSet[T, U]) Vals() iter.Iter[T]

Description: Returns an iterator that iterates over the values in the hash set.

Time Complexity: O(n)

func (*HashSet[T, U]) Zero

func (_ *HashSet[T, U]) Zero(other *HashSet[T, U])

An zero function that implements the [algo.widget.WidgetInterface] interface. Internally this is equivalent to HashSet.Clear.

type HashSetHash

type HashSetHash hash.Hash

func (*HashSetHash) Eq

func (_ *HashSetHash) Eq(l *HashSetHash, r *HashSetHash) bool

Returns true if l equals r. Uses the Eq operator provided by the widgets.BuiltinHash widget internally.

func (*HashSetHash) Hash

func (_ *HashSetHash) Hash(other *HashSetHash) hash.Hash

Returns a hash to represent other. The hash that is returned will be supplied by the widgets.BuiltinHash widget internally.

func (*HashSetHash) Zero

func (_ *HashSetHash) Zero(other *HashSetHash)

Zeros the supplied value. The operation that is performed will be determined by the widgets.BuiltinHash widget internally.

type HashSetHooks

type HashSetHooks interface {
	// contains filtered or unexported methods
}

An interface defining the operations that can be performed with a hooked hash set. These functions are call backs that the hooked hash set will call as values are modified.

type HookedHashSet

type HookedHashSet[T any, U widgets.BaseInterface[T]] struct {
	HashSet[T, U]
	// contains filtered or unexported fields
}

A type that represents a hash set with call backs to notify a given value of any changes to the set. Several functions are also added that allow the internal state of the hash set to be viewed, including the hash values that the set uses internally. All of the implementation logic is provided by the HashSet type. The type constraints on the generics define the logic for how value specific operations, such as equality comparisons, will be handled.

func NewHookedHashSet

func NewHookedHashSet[T any, U widgets.BaseInterface[T]](
	hooks HashSetHooks,
	size int,
) (HookedHashSet[T, U], error)

Creates a new hooked hash set with enough memory to store size number of elements. Size must be >=0, an error will be returned if it is not. If size is 0 the hooked hash set will be initialized with 0 elements.

func (*HookedHashSet[T, U]) AppendUnique

func (h *HookedHashSet[T, U]) AppendUnique(vals ...T) error

Description: Appends the values to the underlying hash set, calling the addOp hook each time a value is successfully added to the set.

Time Complexity: O(n), where n=len(vals)

func (*HookedHashSet[T, U]) Clear

func (h *HookedHashSet[T, U]) Clear()

Description: Calls the clearOp hook before clearing all values from the underlying hash set.

Time Complexity: O(n)

func (*HookedHashSet[T, U]) Eq

func (_ *HookedHashSet[T, U]) Eq(
	l *HookedHashSet[T, U],
	r *HookedHashSet[T, U],
) bool

An equality function that implements the [algo.widget.WidgetInterface] interface. Returns true if l==r, false otherwise.

func (*HookedHashSet[T, U]) GetFromHash

func (h *HookedHashSet[T, U]) GetFromHash(internalHash HashSetHash) (T, error)

Description: Gets the value from the supplied hash, returning an error if the supplied hash is not present in the set.

Time Complexity: O(1)

func (*HookedHashSet[T, U]) GetHashPosition

func (h *HookedHashSet[T, U]) GetHashPosition(v *T) (HashSetHash, bool)

Description: Gets the underlying hash position for the supplied value. The boolean flag indicates if the value was found or not.

Time Complexity: O(1)

func (*HookedHashSet[T, U]) Hash

func (_ *HookedHashSet[T, U]) Hash(other *HookedHashSet[T, U]) hash.Hash

A function that returns a hash of a vector to implement the [algo.widget.WidgetInterface]. To do this all of the individual hashes that are produced from the elements of the set are combined in a way that maintains identity, making it so the hash will represent the same equality operation that [HookedHashSet.KeyedEq] and HookedHashSet.Eq provide.

func (*HookedHashSet[T, U]) Pop

func (h *HookedHashSet[T, U]) Pop(v T) int

Description: Removes the supplied element from the set if it is present. No action is performed if the value is not in the set. The deleteOp hook is called only if a value was removed from the set.

Time Complexity: O(1)

func (*HookedHashSet[T, U]) PopPntr

func (h *HookedHashSet[T, U]) PopPntr(v *T) int

Description: Removes the supplied element from the set if it is present. No action is performed if the value is not in the set. The deleteOp hook is called only if a value was removed from the set.

Time Complexity: O(1)

func (*HookedHashSet[T, U]) ToSynced

func (h *HookedHashSet[T, U]) ToSynced() SyncedHookedHashSet[T, U]

Converts the supplied hooked hash set to a synchronized hash set. Beware: The original non-synced hash set will remain useable.

func (*HookedHashSet[T, U]) Zero

func (_ *HookedHashSet[T, U]) Zero(other *HookedHashSet[T, U])

An zero function that implements the [algo.widget.WidgetInterface] interface. Internally this is equivalent to HookedHashSet.Clear.

type NewHashSetHash

type NewHashSetHash HashSetHash

type OldHashSetHash

type OldHashSetHash HashSetHash

type SyncedCircularBuffer

type SyncedCircularBuffer[T any, U widgets.BaseInterface[T]] struct {
	*sync.RWMutex
	CircularBuffer[T, U]
}

A synchronized version of CircularBuffer. All operations will be wrapped in the appropriate calls the embedded RWMutex. A pointer to a RWMutex is embedded rather than a value to avoid copying the lock value.

func NewSyncedCircularBuffer

func NewSyncedCircularBuffer[T any, U widgets.BaseInterface[T]](
	size int,
) (SyncedCircularBuffer[T, U], error)

Creates a new synced CircularBuffer initialized with size zero valued elements. Size must be greater than 0, an error will be returned if it is not. The underlying RWMutex value will be fully unlocked upon initialization.

func SyncedCirularBufferValInit

func SyncedCirularBufferValInit[T any, U widgets.BaseInterface[T]](
	vals ...T,
) SyncedCircularBuffer[T, U]

Creates a new synced circular buffer and populates it with the supplied values. The circular buffer will have len(vals) capacity.

func (*SyncedCircularBuffer[T, U]) Append

func (c *SyncedCircularBuffer[T, U]) Append(vals ...T) error

Description: Places a write lock on the underlying circular buffer and then calls the underlying circular buffers CircularBuffer.Append implementation method. The CircularBuffer.Append method is not called directly to avoid copying the vals varargs twice, which could be expensive with a large type for the T generic or a large number of values.

Lock Type: Write

Time Complexity: Best case O(m), where m=len(vals).

func (*SyncedCircularBuffer[T, U]) AppendUnique

func (c *SyncedCircularBuffer[T, U]) AppendUnique(vals ...T) error

Description: Places a write lock on the underlying circular buffer and then calls the underlying circular buffer CircularBuffer.AppendUnique implementaion method. The CircularBuffer.AppendUnique method is not called directly to avoid copying the vals varargs twice, which could be expensive with a large type for the T generic or a large number of values.

Lock Type: Write

Time Complexity: Best case O(m), where m=len(vals).

func (*SyncedCircularBuffer[T, U]) Capacity

func (c *SyncedCircularBuffer[T, U]) Capacity() int

Description: Returns the capacity of the underlying circular buffer.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedCircularBuffer[T, U]) Clear

func (c *SyncedCircularBuffer[T, U]) Clear()

Description: Places a write lock on the underlying circular buffer and then calls the underlying circular buffers CircularBuffer.Clear method.

Lock Type: Write

Time Complexity: O(n)

func (*SyncedCircularBuffer[T, U]) Contains

func (c *SyncedCircularBuffer[T, U]) Contains(val T) bool

Description: Places a read lock on the underlying circular buffer and then calls the underlying circular buffers CircularBuffer.ContainsPntr method.

Lock Type: Read

Time Complexity: O(n) (linear search)

func (*SyncedCircularBuffer[T, U]) ContainsPntr

func (c *SyncedCircularBuffer[T, U]) ContainsPntr(val *T) bool

Description: Places a read lock on the underlying circular buffer and then calls the underlying circular buffer CircularBuffer.ContainsPntr method.

Lock Type: Read

Time Complexity: O(n) (linear search)

func (*SyncedCircularBuffer[T, U]) Delete

func (c *SyncedCircularBuffer[T, U]) Delete(idx int) error

Description: Places a write lock on the underlying circular buffer and then calls the underlying circular buffers CircularBuffer.Delete method.

Lock Type: Write

Time Complexity: O(n)

func (*SyncedCircularBuffer[T, U]) DeleteSequential

func (c *SyncedCircularBuffer[T, U]) DeleteSequential(start int, end int) error

Description: Places a write lock on the underlying circular buffer and then calls the underlying circular buffer CircularBuffer.DeleteSequential method.

Lock Type: Write

Time Complexity: O(n)

func (*SyncedCircularBuffer[T, U]) Difference

func (c *SyncedCircularBuffer[T, U]) Difference(
	l containerTypes.ComparisonsOtherConstraint[T],
	r containerTypes.ComparisonsOtherConstraint[T],
)

Description: Places a write lock on the underlying circular buffer and then calls the underlying circular buffer CircularBuffer.Difference method. Attempts to place a read lock on l and r but whether or not that happens is implementation dependent.

Lock Type: Write on this circular buffer, read on l and r

Time Complexity: Dependent on the time complexity of the implementation of the ContainsPntr method on l and r. In big-O it might look something like this, O(O(r.ContainsPntr)*O(l.ContainsPntr)), where O(r.ContainsPntr) represents the time complexity of the containsPntr method on r and O(l.ContainsPntr) represents the time complexity of the containsPntr method on l.

func (*SyncedCircularBuffer[T, U]) Eq

func (_ *SyncedCircularBuffer[T, U]) Eq(
	l *SyncedCircularBuffer[T, U],
	r *SyncedCircularBuffer[T, U],
) bool

An equality function that implements the [algo.widget.WidgetInterface] interface. Internally this is equivalent to SyncedCircularBuffer.KeyedEq. Returns true if l==r, false otherwise.

func (*SyncedCircularBuffer[T, U]) ForcePushBack

func (c *SyncedCircularBuffer[T, U]) ForcePushBack(v ...T)

Description: Places a write lock on the underlying circular buffer and then pushes values to the front of the circular buffer. Exhibits the same behavior as CircularBuffer.ForcePushBack. The underlying CircularBuffer.ForcePushBack method is not called to avoid copying the list of values twice, which could be inefficient with a large type for the T generic or many values.

Lock Type: Write

Time Complexity: O(m), where m=len(vals)

func (*SyncedCircularBuffer[T, U]) ForcePushFront

func (c *SyncedCircularBuffer[T, U]) ForcePushFront(v ...T)

Description: Places a write lock on the underlying circular buffer and then pushes values to the front of the circular buffer. Exhibits the same behavior as CircularBuffer.ForcePushFront. The underlying CircularBuffer.ForcePushFront method is not called to avoid copying the list of values twice, which could be inefficient with a large type for the T generic or many values.

Lock Type: Write

Time Complexity: O(n+m), where m=len(vals)

func (*SyncedCircularBuffer[T, U]) Full

func (c *SyncedCircularBuffer[T, U]) Full() bool

Description: Places a read lock on the underlying circular buffer and then calls the underlying circular buffers CircularBuffer.Length method.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedCircularBuffer[T, U]) Get

func (c *SyncedCircularBuffer[T, U]) Get(idx int) (T, error)

Description: Places a read lock on the underlying circular buffer and then gets the value at the specified index. Exhibits the same behavior as the CircularBuffer.Get method. The underlying CircularBuffer.Get method is not called to avoid copying the return value twice, which could be inefficient with a large value for the T generic.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedCircularBuffer[T, U]) GetPntr

func (c *SyncedCircularBuffer[T, U]) GetPntr(idx int) (*T, error)

Description: Places a read lock on the underlying circular buffer and then calls the underlying circular buffer CircularBuffer.GetPntr method.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedCircularBuffer[T, U]) GetUnique

func (c *SyncedCircularBuffer[T, U]) GetUnique(v *T) error

Description: Places a read lock on the underlying circular buffer and then calls the underlying circular buffer CircularBuffer.GetUnique method.

Lock Type: Read

Time Complexity: O(n)

func (*SyncedCircularBuffer[T, U]) Hash

func (_ *SyncedCircularBuffer[T, U]) Hash(
	other *SyncedCircularBuffer[T, U],
) hash.Hash

Places a read lock on the underlying circular buffer of other and then calls others underlying circular buffer CircularBuffer.IsSubset method. Implements the [algo.widget.WidgetInterface].

func (*SyncedCircularBuffer[T, U]) Insert

func (c *SyncedCircularBuffer[T, U]) Insert(vals ...basic.Pair[int, T]) error

Description: Places a write lock on the underlying circular buffer and then calls the underlying circular buffer CircularBuffer.Insert implementation method. The CircularBuffer.Insert method is not called directly to avoid copying the vals varargs twice, which could be expensive with a large type for the T generic or a large number of values.

Lock Type: Write

Time Complexity: O(n*m), where m=len(vals)

func (*SyncedCircularBuffer[T, U]) InsertSequential

func (c *SyncedCircularBuffer[T, U]) InsertSequential(idx int, vals ...T) error

Description: Places a write lock on the underlying circular buffer and then calls the underlying circular buffer CircularBuffer.InsertSequential implementation method. The CircularBuffer.InsertSequential method is not called directly to avoid copying the vals varargs twice, which could be expensive with a large type for the T generic or a large number of values.

Lock Type: Write

Time Complexity: O(n+m), where m=len(vals)

func (*SyncedCircularBuffer[T, U]) Intersection

func (c *SyncedCircularBuffer[T, U]) Intersection(
	l containerTypes.ComparisonsOtherConstraint[T],
	r containerTypes.ComparisonsOtherConstraint[T],
)

Description: Places a write lock on the underlying circular buffer and then calls the underlying circular buffer CircularBuffer.Intersection method. Attempts to place a read lock on l and r but whether or not that happens is implementation dependent.

Lock Type: Write on this circular buffer, read on l and r

Time Complexity: Dependent on the time complexity of the implementation of the ContainsPntr method on l and r. In big-O it might look something like this, O(O(r.ContainsPntr)*O(l.ContainsPntr)), where O(r.ContainsPntr) represents the time complexity of the containsPntr method on r and O(l.ContainsPntr) represents the time complexity of the containsPntr method on l.

func (*SyncedCircularBuffer[T, U]) IsSubset

func (c *SyncedCircularBuffer[T, U]) IsSubset(
	other containerTypes.ComparisonsOtherConstraint[T],
) bool

Description: Places a read lock on the underlying circular buffer and then calls the underlying circular buffer CircularBuffer.IsSubset method. Attempts to place a read lock on other but whether or not that happens is implementation dependent.

Lock Type: Read on this circular buffer, read on other

Time Complexity: Dependent on the ContainsPntr method of other. In big-O terms it may look somwthing like this: O(n*O(other.ContainsPntr)), where n is the number of elements in the current circular buffer and other.ContainsPntr represents the time complexity of the containsPntr method on other.

func (*SyncedCircularBuffer[T, U]) IsSuperset

func (c *SyncedCircularBuffer[T, U]) IsSuperset(
	other containerTypes.ComparisonsOtherConstraint[T],
) bool

Description: Places a read lock on the underlying circular buffer and then calls the underlying circular buffer CircularBuffer.IsSuperset method. Attempts to place a read lock on other but whether or not that happens is implementation dependent.

Lock Type: Read on this circular buffer, read on other

Time Complexity: O(n*m), where n is the number of values in this circular buffer and m is the number of values in other.

func (*SyncedCircularBuffer[T, U]) IsSynced

func (c *SyncedCircularBuffer[T, U]) IsSynced() bool

Returns true, a synced circular buffer is synced.

func (*SyncedCircularBuffer[T, U]) KeyOf

func (c *SyncedCircularBuffer[T, U]) KeyOf(val T) (int, bool)

Description: Places a read lock on the underlying circular buffer and then calls the underlying circular buffers CircularBuffer.KeyOfPntr method.

Lock Type: Read

Time Complexity: O(n) (linear search)

func (*SyncedCircularBuffer[T, U]) KeyOfPntr

func (c *SyncedCircularBuffer[T, U]) KeyOfPntr(val *T) (int, bool)

Description: Places a read lock on the underlying circular buffer and then calls the underlying circular buffers CircularBuffer.KeyOfPntr method.

Lock Type: Read

Time Complexity: O(n) (linear search)

func (*SyncedCircularBuffer[T, U]) KeyedEq

func (c *SyncedCircularBuffer[T, U]) KeyedEq(
	other containerTypes.KeyedComparisonsOtherConstraint[int, T],
) bool

Description: Places a read lock on the underlying circular buffer and then calls the underlying circular buffers CircularBuffer.KeyedEq method. Attempts to place a read lock on other but whether or not that happens is implementation dependent.

Lock Type: Read on this circular buffer, read on other

Time Complexity: Dependent on the time complexity of the implementation of the GetPntr method on other. In big-O it might look something like this, O(n*O(other.GetPntr))), where n is the number of elements in c and O(other.ContainsPntr) represents the time complexity of the containsPntr method on other.

func (*SyncedCircularBuffer[T, U]) Keys

func (c *SyncedCircularBuffer[T, U]) Keys() iter.Iter[int]

Description: Modifies the iterator chain returned by the unerlying CircularBuffer.Keys method such that a read lock will be placed on the underlying circular buffer when iterator is consumed. The circular buffer will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator starts to be consumed.

Lock Type: Read

Time Complexity: O(n)

func (*SyncedCircularBuffer[T, U]) Length

func (c *SyncedCircularBuffer[T, U]) Length() int

Description: Returns the length of the underlying circular buffer.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedCircularBuffer[T, U]) Lock

func (c *SyncedCircularBuffer[T, U]) Lock()

The SyncedCircularBuffer method to override the HashMap pass through function and actually apply the mutex operation.

func (*SyncedCircularBuffer[T, U]) PeekBack

func (c *SyncedCircularBuffer[T, U]) PeekBack() (T, error)

Description: Places a read lock on the underlying circular buffer and then attempts to return the value at index len(v)-1 if one is present. Exhibits the same behavior as the [circular buffer.PeekBack] method. The underlying [circular buffer.PeekBack] method is not called to avoid copying the value twice, which could be inefficient with a large type for the T generic.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedCircularBuffer[T, U]) PeekFront

func (c *SyncedCircularBuffer[T, U]) PeekFront() (T, error)

Description: Places a read lock on the underlying circular buffer and then attempts to return the value at index 0 if one is present. Exhibits the same behavior as the CircularBuffer.PeekFront method. The underlying CircularBuffer.PeekFront method is not called to avoid copying the value twice, which could be inefficient with a large type for the T generic.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedCircularBuffer[T, U]) PeekPntrBack

func (c *SyncedCircularBuffer[T, U]) PeekPntrBack() (*T, error)

Description: Places a read lock on the underlying circular buffer and then calls the underlying circular buffer CircularBuffer.PeekPntrBack method.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedCircularBuffer[T, U]) PeekPntrFront

func (c *SyncedCircularBuffer[T, U]) PeekPntrFront() (*T, error)

Description: Places a read lock on the underlying circular buffer and then calls the underlying circular buffers CircularBuffer.PeekPntrFront method.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedCircularBuffer[T, U]) Pop

func (c *SyncedCircularBuffer[T, U]) Pop(val T) int

Description: Places a write lock on the underlying circular buffer and then calls the underlying circular buffers CircularBuffer.Pop implementation method. The CircularBuffer.Pop method is not called directly to avoid copying the value twice, which could be expensive with a large type for the T generic or a large number of values.

Lock Type: Write

Time Complexity: O(n)

func (*SyncedCircularBuffer[T, U]) PopBack

func (c *SyncedCircularBuffer[T, U]) PopBack() (T, error)

Description: Places a write lock on the underlying circular buffer and then calls the underlying circular buffers CircularBuffer.PopFront implementation method. The CircularBuffer.PopBack method is not called directly to avoid copying the return value twice, which could be expensive with a large type for the T generic.

Lock Type: Write

Time Complexity: O(1)

func (*SyncedCircularBuffer[T, U]) PopFront

func (c *SyncedCircularBuffer[T, U]) PopFront() (T, error)

Description: Places a write lock on the underlying circular buffer and then calls the underlying circular buffer CircularBuffer.PopFront implementation method. The CircularBuffer.PopFront method is not called directly to avoid copying the return value twice, which could be expensive with a large type for the T generic.

Lock Type: Write

Time Complexity: O(n)

func (*SyncedCircularBuffer[T, U]) PopPntr

func (c *SyncedCircularBuffer[T, U]) PopPntr(val *T) int

Description: Places a write lock on the underlying circular buffer and then calls the underlying circular buffers CircularBuffer.PopPntr implementation method. The CircularBuffer.PopPntr method is not called directly to avoid copying the value twice, which could be expensive with a large type for the T generic or a large number of values.

Lock Type: Write

Time Complexity: O(n)

func (*SyncedCircularBuffer[T, U]) PopSequential

func (c *SyncedCircularBuffer[T, U]) PopSequential(val T, num int) int

Description: Places a write lock on the underlying circular buffer and then calls the underlying circular buffers CircularBuffer.PopSequential implementation method. The CircularBuffer.PopSequential method is not called directly to avoid copying the value twice, which could be expensive with a large type for the T generic or a large number of values.

Lock Type: Write

Time Complexity: O(n)

func (*SyncedCircularBuffer[T, U]) PushBack

func (c *SyncedCircularBuffer[T, U]) PushBack(v ...T) error

Description: Places a write lock on the underlying circular buffer and then appends values to the end of the circular buffer. Exhibits the same behavior as CircularBuffer.PushBack. The underlying CircularBuffer.PushBack method is not called to avoid copying the list of values twice, which could be inefficient with a large type for the T generic or many values.

Lock Type: Write

Time Complexity: best case O(m), where m=len(vals)

func (*SyncedCircularBuffer[T, U]) PushFront

func (c *SyncedCircularBuffer[T, U]) PushFront(v ...T) error

Description: Places a write lock on the underlying circular buffer and then pushes values to the front of the circular buffer. Exhibits the same behavior as [CircularBuffer.PusFront]. The underlying CircularBuffer.PushFront method is not called to avoid copying the list of values twice, which could be inefficient with a large type for the T generic or many values.

Lock Type: Write

Time Complexity: O(n+m), where m=len(vals)

func (*SyncedCircularBuffer[T, U]) RLock

func (c *SyncedCircularBuffer[T, U]) RLock()

The SyncedCircularBuffer method to override the HashMap pass through function and actually apply the mutex operation.

func (*SyncedCircularBuffer[T, U]) RUnlock

func (c *SyncedCircularBuffer[T, U]) RUnlock()

The SyncedCircularBuffer method to override the HashMap pass through function and actually apply the mutex operation.

func (*SyncedCircularBuffer[T, U]) Set

func (c *SyncedCircularBuffer[T, U]) Set(vals ...basic.Pair[int, T]) error

Description: Places a write lock on the underlying circular buffer and then calls the underlying circular buffers CircularBuffer.Set implementaiton method. The CircularBuffer.Set method is not called directly to avoid copying the vals varargs twice, which could be expensive with a large type for the T generic or a large number of values.

Lock Type: Write

Time Complexity: O(m), where m=len(vals)

func (*SyncedCircularBuffer[T, U]) SetSequential

func (c *SyncedCircularBuffer[T, U]) SetSequential(idx int, vals ...T) error

Description: Places a write lock on the underlying circular buffer and then calls the underlying circular buffers CircularBuffer.SetSequential implementation method. The [circular buffer.SetSequential] method is not called directly to avoid copying the vals varargs twice, which could be expensive with a large type for the T generic or a large number of values.

Lock Type: Write

Time Complexity: O(m), where m=len(vals)

func (*SyncedCircularBuffer[T, U]) Union

func (c *SyncedCircularBuffer[T, U]) Union(
	l containerTypes.ComparisonsOtherConstraint[T],
	r containerTypes.ComparisonsOtherConstraint[T],
)

Description: Places a write lock on the underlying cirular buffer and then calls the underlying cirular buffer CircularBuffer.Union method. Attempts to place a read lock on l and r but whether or not that happens is implementation dependent.

Lock Type: Write on this circular buffer, read on l and r

Time Complexity: O((n+m)*(n+m)), where n is the number of values in l and m is the number of values in r.

func (*SyncedCircularBuffer[T, U]) Unlock

func (c *SyncedCircularBuffer[T, U]) Unlock()

The SyncedCircularBuffer method to override the HashMap pass through function and actually apply the mutex operation.

func (*SyncedCircularBuffer[T, U]) UnorderedEq

func (c *SyncedCircularBuffer[T, U]) UnorderedEq(
	other containerTypes.ComparisonsOtherConstraint[T],
) bool

Description: Places a read lock on the underlying circular buffer and then calls the underlying circular buffer CircularBuffer.UnorderedEq method. Attempts to place a read lock on other but whether or not that happens is implementation dependent.

Lock Type: Read on this circular buffer, read on other

Time Complexity: Dependent on the time complexity of the implementation of the ContainsPntr method on other. In big-O it might look something like this, O(n*O(other.ContainsPntr))), where O(other.ContainsPntr) represents the time complexity of the ContainsPntr method on other with m values.

func (*SyncedCircularBuffer[T, U]) UpdateUnique

func (c *SyncedCircularBuffer[T, U]) UpdateUnique(
	orig T,
	updateOp func(orig *T),
) error

Description: Places a write lock on the underlying circular buffer and then calls the underlying circular buffers CircularBuffer.UpdateUnique implementation method. The CircularBuffer.UpdateUnique method is not called directly to avoid copying the supplied value, which could be expensive with a large type for the T generic.

Lock Type: Write

Time Complexity: O(n)

func (*SyncedCircularBuffer[T, U]) ValPntrs

func (c *SyncedCircularBuffer[T, U]) ValPntrs() iter.Iter[*T]

Description: Modifies the iterator chain returned by the unerlying CircularBuffer.ValPntrs method such that a read lock will be placed on the underlying circular buffer when the iterator is consumed. The circular buffer will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator starts to be consumed.

Lock Type: Read

Time Complexity: O(n)

func (*SyncedCircularBuffer[T, U]) Vals

func (c *SyncedCircularBuffer[T, U]) Vals() iter.Iter[T]

Description: Modifies the iterator chain returned by the unerlying CircularBuffer.Vals method such that a read lock will be placed on the underlying circular buffer when the iterator is consumed. The circular buffer will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator starts to be consumed.

Lock Type: Read

Time Complexity: O(n)

func (*SyncedCircularBuffer[T, U]) Zero

func (_ *SyncedCircularBuffer[T, U]) Zero(other *SyncedCircularBuffer[T, U])

An zero function that implements the [algo.widget.WidgetInterface] interface. Internally this is equivalent to SyncedCircularBuffer.Clear.

type SyncedHashGraph

type SyncedHashGraph[
	V any,
	E any,
	VI widgets.BaseInterface[V],
	EI widgets.BaseInterface[E],
] struct {
	*sync.RWMutex
	HashGraph[V, E, VI, EI]
}

A synchronized version of HashGraph. All operations will be wrapped in the appropriate calls to the embedded RWMutex. A pointer to a RWMutex is embedded rather than a value to avoid copying the lock value.

func NewSyncedHashGraph

func NewSyncedHashGraph[
	V any,
	E any,
	VI widgets.BaseInterface[V],
	EI widgets.BaseInterface[E],
](numVertices int, numEdges int) (SyncedHashGraph[V, E, VI, EI], error)

Creates a new hash graph initialized with enough memory to hold the specified amount of vertices and edges. Both numVertices and numEdges must be >=0, an error will be returned if either one violates that rule. If either size is 0 then the associated map will be initialized with 0 elements. The underlying RWMutex value will be fully unlocked upon initialization.

func (*SyncedHashGraph[V, E, VI, EI]) AddEdges

func (g *SyncedHashGraph[V, E, VI, EI]) AddEdges(e ...E) error

Description: Places a write lock on the underlying hash graph before calling the underlying hash graphs HashGraph.AddEdges method.

Lock Type: Write

Time Complexity: O(n), where n=len(e)

func (*SyncedHashGraph[V, E, VI, EI]) AddVertices

func (g *SyncedHashGraph[V, E, VI, EI]) AddVertices(v ...V) error

Description: Places a write lock on the underlying hash graph and then adds the vertices to the underlying.graph. Exhibits the same behavior as the non-synced HashGraph.AddVertices method.

Lock Type: Write

Time Complexity: O(n), where n=len(v)

func (*SyncedHashGraph[V, E, VI, EI]) Clear

func (g *SyncedHashGraph[V, E, VI, EI]) Clear()

Description: Places a write lock on the underlying hash graph before calling the underlying HashGraph.Clear method.

Lock Type: Write

Time Complexity: O(n+m), where n=num vertices and m=num edges

func (*SyncedHashGraph[V, E, VI, EI]) ContainsEdge

func (g *SyncedHashGraph[V, E, VI, EI]) ContainsEdge(e E) bool

Description: Places a read lock on the underlying.graph before checking if the supplied edge is contained in the graph, returning true if it is. All equality comparisons are performed by the generic EI widget type that the hash graph was initialized with.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedHashGraph[V, E, VI, EI]) ContainsEdgePntr

func (g *SyncedHashGraph[V, E, VI, EI]) ContainsEdgePntr(e *E) bool

Description: Places a read lock on the underlying hash graph and then calls the underlying hash graph HashGraph.ContainsEdgePntr method.

Lock Type: Read

Time Complexity: O(1)

func (g *SyncedHashGraph[V, E, VI, EI]) ContainsLink(from V, to V, e E) bool

Description: Places a read lock on the underlying hash graph and then calls the underlying hash graph HashGraph.ContainsLinkPntr method. The pntr variant is called to avoid copying the V and E generic arguments twice, which could be expensive with large generic types.

Lock Type: Read

Time Complexity: O(n), where n=num outgoing edges from the starting vertex.

func (*SyncedHashGraph[V, E, VI, EI]) ContainsLinkPntr

func (g *SyncedHashGraph[V, E, VI, EI]) ContainsLinkPntr(from *V, to *V, e *E) bool

Description: Places a read lock on the underlying hash graph and then calls the underlying hash graph HashGraph.ContainsLinkPntr method.

Lock Type: Read

Time Complexity: O(n), where n=num outgoing edges from the starting vertex.

func (*SyncedHashGraph[V, E, VI, EI]) ContainsVertex

func (g *SyncedHashGraph[V, E, VI, EI]) ContainsVertex(v V) bool

Description: Places a read lock on the underlying.graph before checking if the supplied vertex is contained in the graph, returning true if it is. All equality comparisons are performed by the generic VI widget type that the hash graph was initialized with.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedHashGraph[V, E, VI, EI]) ContainsVertexPntr

func (g *SyncedHashGraph[V, E, VI, EI]) ContainsVertexPntr(v *V) bool

Description: Places a read lock on the underlying hash graph and then calls the underlying hash graph HashGraph.ContainsVertexPntr method.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedHashGraph[V, E, VI, EI]) DeleteEdge

func (g *SyncedHashGraph[V, E, VI, EI]) DeleteEdge(e E) error

Description: Places a write lock on the underlying hash graph and then removes the edge from the graph. Exhibits the same behavior as the non-synced HashGraph.DeleteEdgePntr method.

Lock Type: Write

Time Complexity: O(n), where n=num of links in the graph

func (*SyncedHashGraph[V, E, VI, EI]) DeleteEdgePntr

func (g *SyncedHashGraph[V, E, VI, EI]) DeleteEdgePntr(e *E) error

Description: Places a write lock on the underlying hash graph and then removes the edge from the graph. Exhibits the same behavior as the non-synced HashGraph.DeleteEdgePntr method.

Lock Type: Write

Time Complexity: O(n), where n=num of links in the graph

func (g *SyncedHashGraph[V, E, VI, EI]) DeleteLink(from V, to V, e E) error

Description: Places a write lock on the underlying hash graph before calling the underlying hash graphs HashGraph.DeleteLinkPntr method.

Lock Type: Write

Time Complexity: O(n), where n=num of outgoing edges on the from vertex

func (*SyncedHashGraph[V, E, VI, EI]) DeleteLinkPntr

func (g *SyncedHashGraph[V, E, VI, EI]) DeleteLinkPntr(
	from *V,
	to *V,
	e *E,
) error

Description: Places a write lock on the underlying hash graph before calling the underlying hash graphs HashGraph.DeleteLinkPntr method.

Lock Type: Write

Time Complexity: O(n), where n=num of outgoing edges on the from vertex

func (g *SyncedHashGraph[V, E, VI, EI]) DeleteLinks(from V, to V) error

Description: Places a write lock on the underlying hash graph before calling the underlying hash graphs HashGraph.DeleteLinksPntr method.

Lock Type: Write

Time Complexity: O(n), where n=num of outgoing edges on the from vertex

func (*SyncedHashGraph[V, E, VI, EI]) DeleteLinksPntr

func (g *SyncedHashGraph[V, E, VI, EI]) DeleteLinksPntr(from *V, to *V) error

Description: Places a write lock on the underlying hash graph before calling the underlying hash graphs HashGraph.DeleteLinksPntr method.

Lock Type: Write

Time Complexity: O(n), where n=num of outgoing edges on the from vertex

func (*SyncedHashGraph[V, E, VI, EI]) DeleteVertex

func (g *SyncedHashGraph[V, E, VI, EI]) DeleteVertex(v V) error

Description: Places a write lock on the underlying hash graph and then removes the vertex from the graph. Exhibits the same behavior as the non-synced HashGraph.DeleteVertexPntr method.

Lock Type: Write

Time Complexity: O(n), where n=num of links in the graph

func (*SyncedHashGraph[V, E, VI, EI]) DeleteVertexPntr

func (g *SyncedHashGraph[V, E, VI, EI]) DeleteVertexPntr(v *V) error

Description: Places a write lock on the underlying hash graph and then removes the vertex from the graph. Exhibits the same behavior as the non-synced HashGraph.DeleteVertexPntr method.

Lock Type: Write

Time Complexity: O(n), where n=num of links in the graph

func (*SyncedHashGraph[V, E, VI, EI]) Difference

func (g *SyncedHashGraph[V, E, VI, EI]) Difference(
	l containerTypes.GraphComparisonsConstraint[V, E],
	r containerTypes.GraphComparisonsConstraint[V, E],
)

Description: Places a write lock on the underlying hash graph and then calls the underlying hash graph HashGraph.Difference method. Attempts to place a read lock on l and r but whether or not that happens is implementation dependent.

Lock Type: Write on this vector, read on l and r

Time Complexity: Dependent on the time complexity of the implementation of the ContainsLinkPntr method on other. In big-O it might look something like this, O((n+m)*O(other.ContainsLinkPntr))), where n is the number of links in r and m is the number of links in l. O(other.ContainsLinkPntr) represents the time complexity of the ContainsLinkPntr method on other.

func (SyncedHashGraph) EdgePntrs

func (g SyncedHashGraph) EdgePntrs() iter.Iter[*E]

Panics, hash graphs are not addressable.

func (*SyncedHashGraph[V, E, VI, EI]) Edges

func (g *SyncedHashGraph[V, E, VI, EI]) Edges() iter.Iter[E]

Description: Modifies the iterator chain returned by the underlying HashGraph.Edges method such that a read lock will be placed on the underlying hash graph when the iterator is consumed. The hash graph will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator starts to be consumed.

Lock Type: Read

Time Complexity: O(n), where n=num edges

func (*SyncedHashGraph[V, E, VI, EI]) EdgesBetween

func (g *SyncedHashGraph[V, E, VI, EI]) EdgesBetween(from V, to V) iter.Iter[E]

Description: Modifies the iterator chain returned by the underlying HashGraph.EdgesBetween method such that a read lock will be placed on the underlying hash graph when the iterator is consumed. The hash graph will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator chain starts to be consumed.

Lock Type: Read

Time Complexity: O(n), where n=the number of outgoing edges on the from vertex

func (SyncedHashGraph) EdgesBetweenPntr

func (g SyncedHashGraph) EdgesBetweenPntr(from *V, to *V) iter.Iter[*E]

Panics, hash graphs are non-addressable.

func (*SyncedHashGraph[V, E, VI, EI]) Eq

func (_ *SyncedHashGraph[V, E, VI, EI]) Eq(
	l *SyncedHashGraph[V, E, VI, EI],
	r *SyncedHashGraph[V, E, VI, EI],
) bool

An equality function that implements the [algo.widget.WidgetInterface] interface. Internally this is equivalent to SyncedHashGraph.KeyedEq. Returns true if l==r, false otherwise.

func (*SyncedHashGraph[V, E, VI, EI]) GetEdge

func (g *SyncedHashGraph[V, E, VI, EI]) GetEdge(e *E) error

Description: Places a read lock on the underlying hash graph and then calls the underlying hash graph HashGraph.GetEdge method.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedHashGraph[V, E, VI, EI]) GetVertex

func (g *SyncedHashGraph[V, E, VI, EI]) GetVertex(v *V) error

Description: Places a read lock on the underlying hash graph and then calls the underlying hash graph HashGraph.GetVertex method.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedHashGraph[V, E, VI, EI]) Hash

func (_ *SyncedHashGraph[V, E, VI, EI]) Hash(
	other *SyncedHashGraph[V, E, VI, EI],
) hash.Hash

Places a read lock on the underlying hash graph of other and then calls others underlying hash maps HashGraph.Hash method.

func (*SyncedHashGraph[V, E, VI, EI]) Intersection

func (g *SyncedHashGraph[V, E, VI, EI]) Intersection(
	l containerTypes.GraphComparisonsConstraint[V, E],
	r containerTypes.GraphComparisonsConstraint[V, E],
)

Description: Places a write lock on the underlying hash graph and then calls the underlying hash graph HashGraph.Intersection method. Attempts to place a read lock on l and r but whether or not that happens is implementation dependent.

Lock Type: Write on this vector, read on l and r

Time Complexity: Dependent on the time complexity of the implementation of the ContainsLinkPntr method on other. In big-O it might look something like this, O(n*O(other.ContainsLinkPntr))), where n is the number of links in r and O(other.ContainsLinkPntr) represents the time complexity of the ContainsLinkPntr method on other.

func (SyncedHashGraph) IsAddressable

func (g SyncedHashGraph) IsAddressable() bool

Returns false, hash graphs are not addressable. (Due to being built out of maps.)

func (*SyncedHashGraph[V, E, VI, EI]) IsSubset

func (g *SyncedHashGraph[V, E, VI, EI]) IsSubset(
	other containerTypes.GraphComparisonsConstraint[V, E],
) bool

Description: Places a read lock on the underlying hash graph and then calls the underlying hash graph HashGraph.IsSubset method. Attempts to place a read lock on other but whether or not that happens is implementation dependent.

Lock Type: Read on this hash graph, read on other

Time Complexity: Dependent on the time complexity of the implementation of the methods in other. In big-O it might look something like this, O(n*O(other.ContainsLink) + m*O(other.ContainsVertexPntr) + p*O(other.ContainsEdgePntr)) where:

  • n is the number of links in this graph
  • m is the number of vertices in this graph
  • p is the number of edges in this graph
  • O(other.ContainsLink) represents the time complexity of the ContainsLink method on other
  • O(other.ContainsVertexPntr) represents the time complexity of the ContainsVertexPntr method on other
  • O(other.ContainsEdgePntr) represents the time complexity of the ContainsEdgePntr method on other

func (*SyncedHashGraph[V, E, VI, EI]) IsSuperSet

func (g *SyncedHashGraph[V, E, VI, EI]) IsSuperSet(
	other containerTypes.GraphComparisonsConstraint[V, E],
) bool

Description: Places a read lock on the underlying hash graph and then calls the underlying hash graph [HashGraph.IsSuperSet] method. Attempts to place a read lock on other but whether or not that happens is implementation dependent.

Lock Type: Read on this hash graph, read on other

Time Complexity: Dependent on the time complexity of the implementation of the methods in other. In big-O it might look something like this, O(n*O(other.ContainsLink) + m*O(other.ContainsVertexPntr) + p*O(other.ContainsEdgePntr)) where:

  • n is the number of links in this graph
  • m is the number of vertices in this graph
  • p is the number of edges in this graph
  • O(other.ContainsLink) represents the time complexity of the ContainsLink method on other
  • O(other.ContainsVertexPntr) represents the time complexity of the ContainsVertexPntr method on other
  • O(other.ContainsEdgePntr) represents the time complexity of the ContainsEdgePntr method on other

func (SyncedHashGraph) IsSuperset

func (g SyncedHashGraph) IsSuperset(
	other containerTypes.GraphComparisonsConstraint[V, E],
) bool

Description: Returns true if this graph is a superset of other. In order for this graph to be a superset of other, it must have all of others vertices, edges, and links. It may have other vertices, edges, or links that are not in other. All of the corresponding vertices and edges must be equal as defined by the Eq method of the supplied VI and EI widgets.

Time Complexity: Dependent on the time complexity of the implementation of the methods on other. In big-O it might look something like this, O(n*O(other.ContainsLink) + m*O(other.ContainsVertexPntr) + p*O(other.ContainsEdgePntr)) where:

  • n is the number of links in this graph
  • m is the number of vertices in this graph
  • p is the number of edges in this graph
  • O(other.ContainsLink) represents the time complexity of the ContainsLink method on other
  • O(other.ContainsVertexPntr) represents the time complexity of the ContainsVertexPntr method on other
  • O(other.ContainsEdgePntr) represents the time complexity of the ContainsEdgePntr method on other

func (*SyncedHashGraph[V, E, VI, EI]) IsSynced

func (g *SyncedHashGraph[V, E, VI, EI]) IsSynced() bool

Returns true, a synced hash graph is synced.

func (*SyncedHashGraph[V, E, VI, EI]) KeyedEq

func (g *SyncedHashGraph[V, E, VI, EI]) KeyedEq(
	other containerTypes.GraphComparisonsConstraint[V, E],
) bool

Description: Places a read lock on the underlying hash graph and then calls the underlying hash graph HashGraph.KeyedEq method. Attempts to place a read lock on other but whether or not that happens is implementation dependent.

Lock Type: Read on this hash graph, read on other

Time Complexity: Dependent on the time complexity of the implementation of the methods on other. In big-O it might look something like this, O(n*O(other.ContainsLink) + m*O(other.ContainsVertexPntr) + p*O(other.ContainsEdgePntr)) where:

  • n is the number of links in this graph
  • m is the number of vertices in this graph
  • p is the number of edges in this graph
  • O(other.ContainsLink) represents the time complexity of the ContainsLink method on other
  • O(other.ContainsVertexPntr) represents the time complexity of the ContainsVertexPntr method on other
  • O(other.ContainsEdgePntr) represents the time complexity of the ContainsEdgePntr method on other
func (g *SyncedHashGraph[V, E, VI, EI]) Link(from V, to V, e E) error

Description: Places a write lock on the underlying hash graph and then adds the link to the graph. Exhibits the same behavior as the non-synced HashGraph.Link method.

Lock Type: Write

Time Complexity: O(n), where n=num of outgoing edges from the start vertex

func (*SyncedHashGraph[V, E, VI, EI]) LinkPntr

func (g *SyncedHashGraph[V, E, VI, EI]) LinkPntr(from *V, to *V, e *E) error

Description: Places a write lock on the underlying hash graph and then adds the link to the graph. Exhibits the same behavior as the non-synced HashGraph.LinkPntr method.

Lock Type: Write

Time Complexity: O(n), where n=num of outgoing edges on the from vertex

func (*SyncedHashGraph[V, E, VI, EI]) Lock

func (g *SyncedHashGraph[V, E, VI, EI]) Lock()

The SyncedHashGraph method to override the HashGraph pass through function and actually apply the mutex operation.

func (*SyncedHashGraph[V, E, VI, EI]) NumEdges

func (g *SyncedHashGraph[V, E, VI, EI]) NumEdges() int

Description: NumEdges will return the number of edges in the graph. This will include any unconnected edges.

Lock Type: Read

Time Complexity: O(1)

func (g *SyncedHashGraph[V, E, VI, EI]) NumLinks() int

Description: NumLinks will return the number of links in the graph. This is different from the number of edges, as the number of links will not include any orphaned edges.

Lock Type: Read

Time Complexity: O(1)

func (g *SyncedHashGraph[V, E, VI, EI]) NumOutLinks(v V) int

Description: Places a read lock on the underlying hash graph and then calls the underlying hash graph HashGraph.NumOutLinksPntr method.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedHashGraph[V, E, VI, EI]) NumOutLinksPntr

func (g *SyncedHashGraph[V, E, VI, EI]) NumOutLinksPntr(v *V) int

Description: Places a read lock on the underlying hash graph and then calls the underlying hash graph HashGraph.NumOutLinksPntr method.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedHashGraph[V, E, VI, EI]) NumVertices

func (g *SyncedHashGraph[V, E, VI, EI]) NumVertices() int

Description: NumVertices will return the number of edges in the graph. This will include any unconnected vertices.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedHashGraph[V, E, VI, EI]) OutEdgeAndVertices

func (g *SyncedHashGraph[V, E, VI, EI]) OutEdgeAndVertices(
	v V,
) iter.Iter[basic.Pair[E, V]]

Description: Modifies the iterator chain returned by the underlying HashGraph.OutEdgesAndVertices method such that a read lock will be placed on the underlying hash graph when the iterator is consumed. The hash graph will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator chain starts to be consumed.

Lock Type: Read

Time Complexity: O(n), where n=num of outgoing edges

func (SyncedHashGraph) OutEdgePntrs

func (g SyncedHashGraph) OutEdgePntrs(v *V) iter.Iter[*E]

Panics, hash graphs are non-addressable.

func (*SyncedHashGraph[V, E, VI, EI]) OutEdges

func (g *SyncedHashGraph[V, E, VI, EI]) OutEdges(v V) iter.Iter[E]

Description: Modifies the iterator chain returned by the underlying HashGraph.OutEdges method such that a read lock will be placed on the underlying hash graph when the iterator is consumed. The hash graph will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator chain starts to be consumed.

Lock Type: Read

Time Complexity: O(n), where n=num of outgoing edges

func (SyncedHashGraph) OutEdgesAndVerticePntrs

func (g SyncedHashGraph) OutEdgesAndVerticePntrs(
	v *V,
) iter.Iter[basic.Pair[*E, *V]]

Panics, hash graphs are non-addressable.

func (SyncedHashGraph) OutEdgesAndVertices

func (g SyncedHashGraph) OutEdgesAndVertices(
	v V,
) iter.Iter[basic.Pair[E, V]]

Description: Returns an iterator that supplies all of the outgoing edges paired with there associated vertices.

Time Complexity: O(n), where n=num of outgoing edges

func (SyncedHashGraph) OutVerticePntrs

func (g SyncedHashGraph) OutVerticePntrs(v *V) iter.Iter[*V]

Panics, hash graphs are non-addressable

func (*SyncedHashGraph[V, E, VI, EI]) OutVertices

func (g *SyncedHashGraph[V, E, VI, EI]) OutVertices(v V) iter.Iter[V]

Description: Modifies the iterator chain returned by the underlying HashGraph.OutVertices method such that a read lock will be placed on the underlying hash graph when the iterator is consumed. The hash graph will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator chain starts to be consumed.

Lock Type: Read

Time Complexity: O(n), where n=num of outgoing edges

func (*SyncedHashGraph[V, E, VI, EI]) RLock

func (g *SyncedHashGraph[V, E, VI, EI]) RLock()

The SyncedHashGraph method to override the HashGraph pass through function and actually apply the mutex operation.

func (*SyncedHashGraph[V, E, VI, EI]) RUnlock

func (g *SyncedHashGraph[V, E, VI, EI]) RUnlock()

The SyncedHashGraph method to override the HashGraph pass through function and actually apply the mutex operation.

func (SyncedHashGraph) ToSynced

func (g SyncedHashGraph) ToSynced() SyncedHashGraph[V, E, VI, EI]

Converts the supplied graph to a synchronized graph. Beware: The original non-synced map will remain useable.

func (*SyncedHashGraph[V, E, VI, EI]) Union

func (g *SyncedHashGraph[V, E, VI, EI]) Union(
	l containerTypes.GraphComparisonsConstraint[V, E],
	r containerTypes.GraphComparisonsConstraint[V, E],
)

Description: Places a write lock on the underlying hash graph and then calls the underlying hash graph HashGraph.Union method. Attempts to place a read lock on l and r but whether or not that happens is implementation dependent.

Lock Type: Write on this vector, read on l and r

Time Complexity: Dependent on the time complexity of the implementation of the ContainsLinkPntr method on other. In big-O it might look something like this, O((n+m)*O(other.ContainsLinkPntr))), where n is the number of links in r and m is the number of links in l. O(other.ContainsLinkPntr) represents the time complexity of the ContainsLinkPntr method on other.

func (*SyncedHashGraph[V, E, VI, EI]) Unlock

func (g *SyncedHashGraph[V, E, VI, EI]) Unlock()

The SyncedHashGraph method to override the HashGraph pass through function and actually apply the mutex operation.

func (SyncedHashGraph) UnorderedEq

func (g SyncedHashGraph) UnorderedEq(
	other containerTypes.GraphComparisonsConstraint[V, E],
) bool

TODO: Isomorphic equality

func (SyncedHashGraph) UpdateEdge

func (g SyncedHashGraph) UpdateEdge(
	e E,
	updateOp func(e *E),
) error

Description: Updates the supplied edge using the supplied operation. All uniqueness constraints that are imposed on a set are imposed here as well. This means that the updated value must compare equal to the original value according to the EI widget and produce the same hash as the original value.

Time Complexity: O(1)

func (SyncedHashGraph) UpdateVertex

func (g SyncedHashGraph) UpdateVertex(
	v V,
	updateOp func(orig *V),
) error

Description: Updates the supplied vertex using the supplied operation. All uniqueness constraints that are imposed on a set are imposed here as well. This means that the updated value must compare equal to the original value according to the VI widget and produce the same hash as the original value.

Time Complexity: O(1)

func (SyncedHashGraph) VerticePntrs

func (g SyncedHashGraph) VerticePntrs() iter.Iter[*V]

Panics, hash graphs are not addressable.

func (*SyncedHashGraph[V, E, VI, EI]) Vertices

func (g *SyncedHashGraph[V, E, VI, EI]) Vertices() iter.Iter[V]

Description: Modifies the iterator chain returned by the underlying HashGraph.Vertices method such that a read lock will be placed on the underlying hash graph when the iterator is consumed. The hash graph will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator starts to be consumed.

Lock Type: Read

Time Complexity: O(n), where n=num vertices

func (*SyncedHashGraph[V, E, VI, EI]) Zero

func (_ *SyncedHashGraph[V, E, VI, EI]) Zero(other *SyncedHashGraph[V, E, VI, EI])

An zero function that implements the [algo.widget.WidgetInterface] interface. Internally this is equivalent to SyncedHashGraph.Clear.

type SyncedHashMap

type SyncedHashMap[
	K any,
	V any,
	KI widgets.BaseInterface[K],
	VI widgets.BaseInterface[V],
] struct {
	*sync.RWMutex
	HashMap[K, V, KI, VI]
}

A synchronized version of HashMap. All operations will be wrapped in the appropriate calls to the embedded RWMutex. A pointer to a RWMutex is embedded rather than a value to avoid copying the lock value.

func NewSyncedHashMap

func NewSyncedHashMap[
	K any,
	V any,
	KI widgets.BaseInterface[K],
	VI widgets.BaseInterface[V],
](size int) (SyncedHashMap[K, V, KI, VI], error)

Creates a new synced map initialized with enough memory to hold size elements. Size must be >= 0, an error will be returned if it is not. If size is 0 the map will be initialized with 0 elements. The underlying RWMutex value will be fully unlocked upon initialization.

func SyncedHashMapValInit

func SyncedHashMapValInit[
	K any,
	V any,
	KI widgets.BaseInterface[K],
	VI widgets.BaseInterface[V],
](vals []basic.Pair[K, V]) SyncedHashMap[K, V, KI, VI]

Creates a new synced hash map and populates it with the supplied values. If there are duplicated keys in the supplied slice the last key-value pair will be what is in the returned map.

func (*SyncedHashMap[K, V, KI, VI]) Clear

func (m *SyncedHashMap[K, V, KI, VI]) Clear()

Description: Places a write lock on the underlying hash map and then calls the underlying hash maps HashMap.Clear method.

Lock Type: Write

Time Complexity: O(1)

func (*SyncedHashMap[K, V, KI, VI]) Contains

func (m *SyncedHashMap[K, V, KI, VI]) Contains(v V) bool

Description: Places a read lock on the underlying map and then calls the underlying map [Map.ContainsPntr] method.

Lock Type: Read

Time Complexity: O(n) (linear search)

func (*SyncedHashMap[K, V, KI, VI]) ContainsPntr

func (m *SyncedHashMap[K, V, KI, VI]) ContainsPntr(v *V) bool

Description: Places a read lock on the underlying map and then calls the underlying maps [Map.ContainsPntr] method.

Lock Type: Read

Time Complexity: O(n) (linear search)

func (*SyncedHashMap[K, V, KI, VI]) Delete

func (m *SyncedHashMap[K, V, KI, VI]) Delete(k K) error

Description: Places a write lock on the underlying hash map and then calls the underlying hash maps HashMap.Delete method.

Lock Type: Write

Time Complexity: O(1)

func (*SyncedHashMap[K, V, KI, VI]) Emplace

func (m *SyncedHashMap[K, V, KI, VI]) Emplace(vals ...basic.Pair[K, V]) error

Description: Places a write lock on the underlying hash map and then calls the underlying hash maps [HashMap.Insert] method.

Lock Type: Write

Time Complexity: O(n*m), where m=len(vals)

func (*SyncedHashMap[K, V, KI, VI]) Eq

func (_ *SyncedHashMap[K, V, KI, VI]) Eq(
	l *SyncedHashMap[K, V, KI, VI],
	r *SyncedHashMap[K, V, KI, VI],
) bool

An equality function that implements the [algo.widget.WidgetInterface] interface. Internally this is equivalent to SyncedHashMap.KeyedEq. Returns true if l==r, false otherwise.

func (*SyncedHashMap[K, V, KI, VI]) Get

func (m *SyncedHashMap[K, V, KI, VI]) Get(k K) (V, error)

Description: Places a read lock on the underlying hash map and then gets the value at the specified key. Exhibits the same behavior as the HashMap.Get method. The underlying HashMap.Get method is not called to avoid copying the return value twice, which could be inefficient with a large value for the K generic.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedHashMap[K, V, KI, VI]) Hash

func (_ *SyncedHashMap[K, V, KI, VI]) Hash(
	other *SyncedHashMap[K, V, KI, VI],
) hash.Hash

Places a read lock on the underlying hash map of other and then calls others underlying hash maps HashMap.Hash method.

func (*SyncedHashMap[K, V, KI, VI]) IsSynced

func (m *SyncedHashMap[K, V, KI, VI]) IsSynced() bool

Returns true, a synced map is synced.

func (*SyncedHashMap[K, V, KI, VI]) KeyOf

func (m *SyncedHashMap[K, V, KI, VI]) KeyOf(v V) (K, bool)

Description: Places a read lock on the underlying hash map and then calls the underlying hash map HashMap.KeyOf implementation method. The HashMap.KeyOf method is not called directly to avoid copying the val variable twice, which could be expensive with a large type for the V generic.

Lock Type: Read

Time Complexity: O(n) (linear search)

func (*SyncedHashMap[K, V, KI, VI]) KeyOfPntr

func (m *SyncedHashMap[K, V, KI, VI]) KeyOfPntr(v *V) (K, bool)

Description: Places a read lock on the underlying hash map and then calls the underlying hash map HashMap.KeyOfPntr implementation method. The HashMap.KeyOfPntr method is not called directly to avoid copying the val variable twice, which could be expensive with a large type for the V generic.

Lock Type: Read

Time Complexity: O(n) (linear search)

func (*SyncedHashMap[K, V, KI, VI]) KeyedEq

func (m *SyncedHashMap[K, V, KI, VI]) KeyedEq(
	other containerTypes.KeyedComparisonsOtherConstraint[K, V],
) bool

Description: Places a read lock on the underlying hash map and then calls the underlying hash map HashMap.KeyedEq method. Attempts to place a read lock on other but whether or not that happens is implementation dependent.

Lock Type: Read on this hash map, read on other

Time Complexity: Dependent on the time complexity of the implementation of the GetPntr method on other. In big-O it might look something like this, O(n*O(other.GetPntr))), where n is the number of elements in v and O(other.ContainsPntr) represents the time complexity of the containsPntr method on other.

func (*SyncedHashMap[K, V, KI, VI]) Keys

func (m *SyncedHashMap[K, V, KI, VI]) Keys() iter.Iter[K]

Description: Modifies the iterator chain returned by the unerlying HashMap.Keys method such that a read lock will be placed on the underlying hash map when the iterator is consumed. The hash map will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator starts to be consumed.

Lock Type: Read

Time Complexity: O(n)

func (*SyncedHashMap[K, V, KI, VI]) Length

func (m *SyncedHashMap[K, V, KI, VI]) Length() int

Description: Places a read lock on the underlying hash map and then calls the underlying hash map HashMap.Length method.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedHashMap[K, V, KI, VI]) Lock

func (m *SyncedHashMap[K, V, KI, VI]) Lock()

The SyncedHashMap method to override the HashMap pass through function and actually apply the mutex operation.

func (*SyncedHashMap[K, V, KI, VI]) Pop

func (m *SyncedHashMap[K, V, KI, VI]) Pop(v V) int

Description: Places a write lock on the underlying map and then calls the underlying map [Map.Pop] implementation method. The HashMap.Pop method is not called directly to avoid copying the v argument twice, which could be expensive with a large type for the T generic.

Lock Type: Write

Time Complexity: O(1)

func (*SyncedHashMap[K, V, KI, VI]) PopPntr

func (m *SyncedHashMap[K, V, KI, VI]) PopPntr(v *V) int

Description: Places a write lock on the underlying map and then calls the underlying map [Map.PopPntr] implementation method. The HashMap.Pop method is not called directly to avoid copying the v argument twice, which could be expensive with a large type for the T generic.

Lock Type: Write

Time Complexity: O(1)

func (*SyncedHashMap[K, V, KI, VI]) RLock

func (m *SyncedHashMap[K, V, KI, VI]) RLock()

The SyncedHashMap method to override the HashMap pass through function and actually apply the mutex operation.

func (*SyncedHashMap[K, V, KI, VI]) RUnlock

func (m *SyncedHashMap[K, V, KI, VI]) RUnlock()

The SyncedHashMap method to override the HashMap pass through function and actually apply the mutex operation.

func (*SyncedHashMap[K, V, KI, VI]) Set

func (m *SyncedHashMap[K, V, KI, VI]) Set(kvPairs ...basic.Pair[K, V]) error

Description: Places a write lock on the underlying map and then calls the underlying hash map HashMap.Set implementaiton method. The HashMap.Set method is not called directly to avoid copying the vals varargs twice, which could be expensive with a large types for the K or V generics or a large number of values. Note that the key will be updated as well. It will only be updated if the key can still be found in the map using the KI widgets Eq and Hash functions.

Lock Type: Write

Time Complexity: O(m), where m=len(vals)

func (*SyncedHashMap[K, V, KI, VI]) Unlock

func (m *SyncedHashMap[K, V, KI, VI]) Unlock()

The SyncedHashMap method to override the HashMap pass through function and actually apply the mutex operation.

func (*SyncedHashMap[K, V, KI, VI]) Vals

func (m *SyncedHashMap[K, V, KI, VI]) Vals() iter.Iter[V]

Description: Modifies the iterator chain returned by the unerlying HashMap.Vals method such that a read lock will be placed on the underlying hash map when the iterator is consumed. The hash map will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator starts to be consumed.

Lock Type: Read

Time Complexity: O(n)

func (*SyncedHashMap[K, V, KI, VI]) Zero

func (_ *SyncedHashMap[K, V, KI, VI]) Zero(other *SyncedHashMap[K, V, KI, VI])

An zero function that implements the [algo.widget.WidgetInterface] interface. Internally this is equivalent to SyncedHashMap.Clear.

type SyncedHashSet

type SyncedHashSet[T any, U widgets.BaseInterface[T]] struct {
	*sync.RWMutex
	HashSet[T, U]
}

A synchronized version of HashSet. All operations will be wrapped in the appropriate calls the embedded RWMutex. A pointer to a RWMutex is embedded rather than a value to avoid copying the lock value.

func NewSyncedHashSet

func NewSyncedHashSet[T any, U widgets.BaseInterface[T]](
	size int,
) (SyncedHashSet[T, U], error)

Creates a new synced hash set initialized with enough memory to hold size elements. Size must be >= 0, an error will be returned if it is not. If size is 0 the hash set will be initialized with 0 elements. The underlying RWMutex value will be fully unlocked upon initialization.

func SyncedHashSetValInit

func SyncedHashSetValInit[T any, U widgets.BaseInterface[T]](
	vals ...T,
) SyncedHashSet[T, U]

Creates a new synced hash set and populates it with the supplied values. Duplicated values will be ignored.

func (*SyncedHashSet[T, U]) AppendUnique

func (h *SyncedHashSet[T, U]) AppendUnique(vals ...T) error

Description: Places a write lock on the underlying hash set and then calls the underlying hash sets HashSet.AppendUnique implementaion method. The HashSet.AppendUnique method is not called directly to avoid copying the vals varargs twice, which could be expensive with a large type for the T generic or a large number of values.

Lock Type: Write

Time Complexity: Best case O(m) (no reallocation), worst case O(n+m) (reallocation), where m=len(vals).

func (*SyncedHashSet[T, U]) Clear

func (h *SyncedHashSet[T, U]) Clear()

Description: Places a write lock on the underlying hash set and then calls the underlying hash sets HashSet.Clear method.

Lock Type: Write

Time Complexity: O(1)

func (*SyncedHashSet[T, U]) Contains

func (h *SyncedHashSet[T, U]) Contains(v T) bool

Description: Places a read lock on the underlying hash set and then calls the underlying hash sets HashSet.ContainsPntr method.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedHashSet[T, U]) ContainsPntr

func (h *SyncedHashSet[T, U]) ContainsPntr(v *T) bool

Description: Places a read lock on the underlying hash set and then calls the underlying hash sets HashSet.ContainsPntr method.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedHashSet[T, U]) Difference

func (h *SyncedHashSet[T, U]) Difference(
	l containerTypes.ComparisonsOtherConstraint[T],
	r containerTypes.ComparisonsOtherConstraint[T],
)

Description: Places a write lock on the underlying hash set and then calls the underlying hash sets [hash set.Difference] method. Attempts to place a read lock on l and r but whether or not that happens is implementation dependent.

Lock Type: Write on this hash set, read on l and r

Time Complexity: Dependent on the time complexity of the implementation of the ContainsPntr method on l and r. In big-O it might look something like this, O(O(r.ContainsPntr)*O(l.ContainsPntr)), where O(r.ContainsPntr) represents the time complexity of the containsPntr method on r and O(l.ContainsPntr) represents the time complexity of the containsPntr method on l.

func (*SyncedHashSet[T, U]) Eq

func (_ *SyncedHashSet[T, U]) Eq(
	l *SyncedHashSet[T, U],
	r *SyncedHashSet[T, U],
) bool

An equality function that implements the [algo.widget.WidgetInterface] interface. Internally this is equivalent to SyncedHashSet.UnorderedEq. Returns true if l==r, false otherwise.

func (*SyncedHashSet[T, U]) GetUnique

func (h *SyncedHashSet[T, U]) GetUnique(v *T) error

Description: Places a read lock on the underlying hash set and then calls the underlying hash sets HashSet.GetUnique method.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedHashSet[T, U]) Hash

func (_ *SyncedHashSet[T, U]) Hash(other *SyncedHashSet[T, U]) hash.Hash

Places a read lock on the underlying hash set of other and then calls others underlying hash set [hash set.IsSubset] method.

func (*SyncedHashSet[T, U]) Intersection

func (h *SyncedHashSet[T, U]) Intersection(
	l containerTypes.ComparisonsOtherConstraint[T],
	r containerTypes.ComparisonsOtherConstraint[T],
)

Description: Places a write lock on the underlying hash set and then calls the underlying hash sets HashSet.Intersection method. Attempts to place a read lock on l and r but whether or not that happens is implementation dependent.

Lock Type: Write on this hash set, read on l and r

Time Complexity: Dependent on the time complexity of the implementation of the ContainsPntr method on l and r. In big-O it might look something like this, O(O(r.ContainsPntr)*O(l.ContainsPntr)), where O(r.ContainsPntr) represents the time complexity of the containsPntr method on r and O(l.ContainsPntr) represents the time complexity of the containsPntr method on l.

func (*SyncedHashSet[T, U]) IsSubset

func (h *SyncedHashSet[T, U]) IsSubset(
	other containerTypes.ComparisonsOtherConstraint[T],
) bool

Description: Places a read lock on the underlying hash set and then calls the underlying hash sets HashSet.IsSubset method. Attempts to place a read lock on other but whether or not that happens is implementation dependent.

Lock Type: Read on this hash set, read on other

Time Complexity: Dependent on the ContainsPntr method of other. In big-O terms it may look somwthing like this: O(n*O(other.ContainsPntr)), where n is the number of elements in the current hash set and other.ContainsPntr represents the time complexity of the containsPntr method on other.

func (*SyncedHashSet[T, U]) IsSuperset

func (h *SyncedHashSet[T, U]) IsSuperset(
	other containerTypes.ComparisonsOtherConstraint[T],
) bool

Description: Places a read lock on the underlying hash set and then calls the underlying hash sets HashSet.IsSuperset method. Attempts to place a read lock on other but whether or not that happens is implementation dependent.

Lock Type: Read on this hash set, read on other

Time Complexity: O(m), where m is the numbe rof values in other.

func (*SyncedHashSet[T, U]) IsSynced

func (h *SyncedHashSet[T, U]) IsSynced() bool

Returns true, a synced hash set is synced. :O

func (*SyncedHashSet[T, U]) Length

func (h *SyncedHashSet[T, U]) Length() int

Description: Places a read lock on the underlying hash set and then calls the underlying hash set's HashSet.Length method.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedHashSet[T, U]) Lock

func (h *SyncedHashSet[T, U]) Lock()

The SyncedHashSet method to override the HashSet pass through function and actually apply the mutex operation.

func (*SyncedHashSet[T, U]) Pop

func (h *SyncedHashSet[T, U]) Pop(v T) int

Description: Places a write lock on the underlying hash set and then calls the underlying hash sets [hash set.PopPntr] method.

Lock Type: Write

Time Complexity: O(1)

func (*SyncedHashSet[T, U]) PopPntr

func (h *SyncedHashSet[T, U]) PopPntr(v *T) int

Description: Places a write lock on the underlying hash set and then calls the underlying hash sets HashSet.PopPntr method.

Lock Type: Write

Time Complexity: O(1)

func (*SyncedHashSet[T, U]) RLock

func (h *SyncedHashSet[T, U]) RLock()

The SyncedHashSet method to override the HashSet pass through function and actually apply the mutex operation.

func (*SyncedHashSet[T, U]) RUnlock

func (h *SyncedHashSet[T, U]) RUnlock()

The SyncedHashSet method to override the HashSet pass through function and actually apply the mutex operation.

func (*SyncedHashSet[T, U]) Union

func (h *SyncedHashSet[T, U]) Union(
	l containerTypes.ComparisonsOtherConstraint[T],
	r containerTypes.ComparisonsOtherConstraint[T],
)

Description: Places a write lock on the underlying hash set and then calls the underlying hash sets [hash set.Union] method. Attempts to place a read lock on l and r but whether or not that happens is implementation dependent.

Lock Type: Write on this hash set, read on l and r

Time Complexity: O((n+m)*(n+m)), where n is the number of values in l and m is the number of values in r.

func (*SyncedHashSet[T, U]) Unlock

func (h *SyncedHashSet[T, U]) Unlock()

The SyncedHashSet method to override the HashSet pass through function and actually apply the mutex operation.

func (*SyncedHashSet[T, U]) UnorderedEq

func (h *SyncedHashSet[T, U]) UnorderedEq(
	other containerTypes.ComparisonsOtherConstraint[T],
) bool

Description: Places a read lock on the underlying hash set and then calls the underlying hash sets HashSet.UnorderedEq method. Attempts to place a read lock on other but whether or not that happens is implementation dependent.

Lock Type: Read on this hash set, read on other

Time Complexity: Dependent on the time complexity of the implementation of the ContainsPntr method on other. In big-O it might look something like this, O(n*O(other.ContainsPntr))), where O(other.ContainsPntr) represents the time complexity of the ContainsPntr method on other with m values.

func (*SyncedHashSet[T, U]) UpdateUnique

func (h *SyncedHashSet[T, U]) UpdateUnique(
	orig T,
	updateOp func(orig *T),
) error

Description: Places a write lock on the underlying hash set and then calls the underlying hash sets HashSet.UpdateUnique implementation method. The HashSet.UpdateUnique method is not called directly to avoid copying the supplied value, which could be expensive with a large type for the T generic.

Lock Type: Write

Time Complexity: O(1)

func (*SyncedHashSet[T, U]) Vals

func (h *SyncedHashSet[T, U]) Vals() iter.Iter[T]

Description: Modifies the iterator chain returned by the unerlying HashSet.Vals method such that a read lock will be placed on the underlying hash set when iterator is consumed. The hash set will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator starts to be consumed.

Lock Type: Read

Time Complexity: O(n)

func (*SyncedHashSet[T, U]) Zero

func (_ *SyncedHashSet[T, U]) Zero(other *SyncedHashSet[T, U])

An zero function that implements the [algo.widget.WidgetInterface] interface. Internally this is equivalent to SyncedHashSet.Clear.

type SyncedHookedHashSet

type SyncedHookedHashSet[T any, U widgets.BaseInterface[T]] struct {
	SyncedHashSet[T, U]
	// contains filtered or unexported fields
}

A synchronized version of HookedHashSet. All operations will be wrapped in the appropriate calls to the embedded RWMutex. A pointer to a RWMutex is embedded rather than a value to avoid copying the lock value.

func NewSyncedHookedHashSet

func NewSyncedHookedHashSet[T any, U widgets.BaseInterface[T]](
	hooks HashSetHooks,
	size int,
) (SyncedHookedHashSet[T, U], error)

Creates a new synced hooked hash set initialized with enough memory to hold size elements. Size must be >= 0, an error will be returned if it is not. If size is 0 the hash set will be initialized with 0 elements. The underlying RWMutex value will be fully unlocked upon initialization.

func (*SyncedHookedHashSet[T, U]) AppendUnique

func (h *SyncedHookedHashSet[T, U]) AppendUnique(vals ...T) error

Description: Places a write lock on the underlying hash set before appending the values to the underlying hash set, calling the addOp hook each time a value is successfully added to the set.

Lock Type: Write

Time Complexity: O(n), where n=len(vals)

func (*SyncedHookedHashSet[T, U]) Clear

func (h *SyncedHookedHashSet[T, U]) Clear()

Description: Places a write lock on the underlying hash set before calling the clearOp hook before clearing all values from the underlying hash set.

Time Complexity: O(n)

func (*SyncedHookedHashSet[T, U]) Eq

func (_ *SyncedHookedHashSet[T, U]) Eq(
	l *SyncedHookedHashSet[T, U],
	r *SyncedHookedHashSet[T, U],
) bool

An equality function that implements the [algo.widget.WidgetInterface] interface. Returns true if l==r, false otherwise.

func (*SyncedHookedHashSet[T, U]) GetFromHash

func (h *SyncedHookedHashSet[T, U]) GetFromHash(
	internalHash HashSetHash,
) (T, error)

Description: Places a read lock on the underlying hash set and then gets the value from the supplied hash, returning an error if the supplied hash is not present in the set.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedHookedHashSet[T, U]) GetHashPosition

func (h *SyncedHookedHashSet[T, U]) GetHashPosition(v *T) (HashSetHash, bool)

Description: Places a read lock on the underlying hash set and then attempts to get the underlying hash position for the supplied value. The boolean flag indicates if the value was found or not.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedHookedHashSet[T, U]) Hash

func (_ *SyncedHookedHashSet[T, U]) Hash(
	other *SyncedHookedHashSet[T, U],
) hash.Hash

A function that returns a hash of a vector to implement the [algo.widget.WidgetInterface]. To do this all of the individual hashes that are produced from the elements of the set are combined in a way that maintains identity, making it so the hash will represent the same equality operation that [SyncedHookedHashSet.KeyedEq] and SyncedHookedHashSet.Eq provide.

func (*SyncedHookedHashSet[T, U]) Pop

func (h *SyncedHookedHashSet[T, U]) Pop(v T) int

Description: Places a write lock on the underlying hash set before removing the supplied element from the set if it is present. No action is performed if the value is not in the set. The deleteOp hook is called only if a value was removed from the set.

Lock Type: Write

Time Complexity: O(1)

func (*SyncedHookedHashSet[T, U]) PopPntr

func (h *SyncedHookedHashSet[T, U]) PopPntr(v *T) int

Description: Places a write lock on the underlying hash set before removing the supplied element from the set if it is present. No action is performed if the value is not in the set. The deleteOp hook is called only if a value was removed from the set.

Lock Type: Write

Time Complexity: O(1)

func (*SyncedHookedHashSet[T, U]) Zero

func (_ *SyncedHookedHashSet[T, U]) Zero(other *SyncedHookedHashSet[T, U])

An zero function that implements the [algo.widget.WidgetInterface] interface. Internally this is equivalent to HookedHashSet.Clear.

type SyncedVector

type SyncedVector[T any, U widgets.BaseInterface[T]] struct {
	*sync.RWMutex
	Vector[T, U]
}

A synchronized version of Vector. All operations will be wrapped in the appropriate calls to the embedded RWMutex. A pointer to a RWMutex is embedded rather than a value to avoid copying the lock value.

func NewSyncedVector

func NewSyncedVector[T any, U widgets.BaseInterface[T]](
	size int,
) (SyncedVector[T, U], error)

Creates a new synced vector initialized with size zero valued elements. Size must be >= 0, an error will be returned if it is not. If size is 0 the vector will be initialized with 0 elements. The underlying RWMutex value will be fully unlocked upon initialization.

func SyncedVectorValInit

func SyncedVectorValInit[T any, U widgets.BaseInterface[T]](
	vals ...T,
) SyncedVector[T, U]

Creates a new synced vector and populates it with the supplied values.

func (*SyncedVector[T, U]) Append

func (v *SyncedVector[T, U]) Append(vals ...T) error

Description: Places a write lock on the underlying vector and then calls the underlying vectors Vector.Append method.

Lock Type: Write

Time Complexity: Best case O(m) (no reallocation), worst case O(n+m) (reallocation), where m=len(vals).

func (*SyncedVector[T, U]) AppendUnique

func (v *SyncedVector[T, U]) AppendUnique(vals ...T) error

Description: Places a write lock on the underlying vector and then calls the underlying vectors Vector.AppendUnique implementaion method. The Vector.AppendUnique method is not called directly to avoid copying the vals varargs twice, which could be expensive with a large type for the T generic or a large number of values.

Lock Type: Write

Time Complexity: Best case O(m) (no reallocation), worst case O(n+m) (reallocation), where m=len(vals).

func (*SyncedVector[T, U]) Capacity

func (v *SyncedVector[T, U]) Capacity() int

Description: Places a read lock on the underlying vector and then calls the underlying vectors Vector.Capacity method.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedVector[T, U]) Clear

func (v *SyncedVector[T, U]) Clear()

Description: Places a write lock on the underlying vector and then calls the underlying vectors Vector.Clear method.

Lock Type: Write

Time Complexity: O(n)

func (*SyncedVector[T, U]) Contains

func (v *SyncedVector[T, U]) Contains(val T) bool

Description: Places a read lock on the underlying vector and then calls the underlying vectors Vector.ContainsPntr method.

Lock Type: Read

Time Complexity: O(n) (linear search)

func (*SyncedVector[T, U]) ContainsPntr

func (v *SyncedVector[T, U]) ContainsPntr(val *T) bool

Description: Places a read lock on the underlying vector and then calls the underlying vectors Vector.ContainsPntr method.

Lock Type: Read

Time Complexity: O(n) (linear search)

func (*SyncedVector[T, U]) Delete

func (v *SyncedVector[T, U]) Delete(idx int) error

Description: Places a write lock on the underlying vector and then calls the underlying vectors Vector.Delete method.

Lock Type: Write

Time Complexity: O(n)

func (*SyncedVector[T, U]) DeleteSequential

func (v *SyncedVector[T, U]) DeleteSequential(start int, end int) error

Description: Places a write lock on the underlying vector and then calls the underlying vectors Vector.DeleteSequential method.

Lock Type: Write

Time Complexity: O(n)

func (*SyncedVector[T, U]) Difference

func (v *SyncedVector[T, U]) Difference(
	l containerTypes.ComparisonsOtherConstraint[T],
	r containerTypes.ComparisonsOtherConstraint[T],
)

Description: Places a write lock on the underlying vector and then calls the underlying vectors Vector.Difference method. Attempts to place a read lock on l and r but whether or not that happens is implementation dependent.

Lock Type: Write on this vector, read on l and r

Time Complexity: Dependent on the time complexity of the implementation of the ContainsPntr method on l and r. In big-O it might look something like this, O(O(r.ContainsPntr)*O(l.ContainsPntr)), where O(r.ContainsPntr) represents the time complexity of the containsPntr method on r and O(l.ContainsPntr) represents the time complexity of the containsPntr method on l.

func (*SyncedVector[T, U]) Eq

func (_ *SyncedVector[T, U]) Eq(l *SyncedVector[T, U], r *SyncedVector[T, U]) bool

An equality function that implements the [widget.Base] interface. Internally this is equivalent to SyncedVector.KeyedEq. Returns true if l==r, false otherwise.

func (*SyncedVector[T, U]) ForcePushBack

func (v *SyncedVector[T, U]) ForcePushBack(vals ...T)

Description: Places a write lock on the underlying vector and then pushes values to the front of the vector. Exhibits the same behavior as Vector.ForcePushBack. The underlying Vector.ForcePushBack method is not called to avoid copying the list of values twice, which could be inefficient with a large type for the T generic or many values.

Lock Type: Write

Time Complexity: O(m), where m=len(vals)

func (*SyncedVector[T, U]) ForcePushFront

func (v *SyncedVector[T, U]) ForcePushFront(vals ...T)

Description: Places a write lock on the underlying vector and then pushes values to the front of the vector. Exhibits the same behavior as Vector.ForcePushFront. The underlying Vector.ForcePushFront method is not called to avoid copying the list of values twice, which could be inefficient with a large type for the T generic or many values.

Lock Type: Write

Time Complexity: O(n+m), where m=len(vals)

func (*SyncedVector[T, U]) Get

func (v *SyncedVector[T, U]) Get(idx int) (T, error)

Description: Places a read lock on the underlying vector and then gets the value at the specified index. Exhibits the same behavior as the Vector.Get method. The underlying Vector.Get method is not called to avoid copying the return value twice, which could be inefficient with a large value for the T generic.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedVector[T, U]) GetPntr

func (v *SyncedVector[T, U]) GetPntr(idx int) (*T, error)

Description: Places a read lock on the underlying vector and then calls the underlying vectors Vector.GetPntr method.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedVector[T, U]) GetUnique

func (v *SyncedVector[T, U]) GetUnique(val *T) error

Description: Places a read lock on the underlying vector and then calls the underlying vectors Vector.GetUnique method.

Lock Type: Read

Time Complexity: O(n)

func (*SyncedVector[T, U]) Hash

func (_ *SyncedVector[T, U]) Hash(other *SyncedVector[T, U]) hash.Hash

Places a read lock on the underlying vector of other and then calls others underlying vector Vector.Hash method. Implements the [widget.Base].

func (*SyncedVector[T, U]) Insert

func (v *SyncedVector[T, U]) Insert(vals ...basic.Pair[int, T]) error

Description: Places a write lock on the underlying vector and then calls the underlying vectors Vector.Insert method.

Lock Type: Write

Time Complexity: O(n*m), where m=len(vals)

func (*SyncedVector[T, U]) InsertSequential

func (v *SyncedVector[T, U]) InsertSequential(idx int, vals ...T) error

Description: Places a write lock on the underlying vector and then calls the underlying vectors Vector.InsertSequential method.

Lock Type: Write

Time Complexity: O(n+m), where m=len(vals). For time complexity see the InsertVector section of https://go.dev/wiki/SliceTricks

func (*SyncedVector[T, U]) Intersection

func (v *SyncedVector[T, U]) Intersection(
	l containerTypes.ComparisonsOtherConstraint[T],
	r containerTypes.ComparisonsOtherConstraint[T],
)

Description: Places a write lock on the underlying vector and then calls the underlying vectors Vector.Intersection method. Attempts to place a read lock on l and r but whether or not that happens is implementation dependent.

Lock Type: Write on this vector, read on l and r

Time Complexity: Dependent on the time complexity of the implementation of the ContainsPntr method on l and r. In big-O it might look something like this, O(O(r.ContainsPntr)*O(l.ContainsPntr)), where O(r.ContainsPntr) represents the time complexity of the containsPntr method on r and O(l.ContainsPntr) represents the time complexity of the containsPntr method on l.

func (*SyncedVector[T, U]) IsSubset

func (v *SyncedVector[T, U]) IsSubset(
	other containerTypes.ComparisonsOtherConstraint[T],
) bool

Description: Places a read lock on the underlying vector and then calls the underlying vectors Vector.IsSubset method. Attempts to place a read lock on other but whether or not that happens is implementation dependent.

Lock Type: Read on this vector, read on other

Time Complexity: Dependent on the ContainsPntr method of other. In big-O terms it may look somwthing like this: O(n*O(other.ContainsPntr)), where n is the number of elements in the current vector and other.ContainsPntr represents the time complexity of the containsPntr method on other.

func (*SyncedVector[T, U]) IsSuperset

func (v *SyncedVector[T, U]) IsSuperset(
	other containerTypes.ComparisonsOtherConstraint[T],
) bool

Description: Places a read lock on the underlying vector and then calls the underlying vectors Vector.IsSuperset method. Attempts to place a read lock on other but whether or not that happens is implementation dependent.

Lock Type: Read on this vector, read on other

Time Complexity: O(n*m), where n is the number of values in this vector and m is the number of values in other.

func (*SyncedVector[T, U]) IsSynced

func (h *SyncedVector[T, U]) IsSynced() bool

Returns true, a synced vector is synced. :O

func (*SyncedVector[T, U]) KeyOf

func (v *SyncedVector[T, U]) KeyOf(val T) (int, bool)

Description: Places a read lock on the underlying vector and then calls the underlying vectors Vector.KeyOf implementation method. The Vector.KeyOf method is not called directly to avoid copying the val variable twice, which could be expensive with a large type for the T generic.

Lock Type: Read

Time Complexity: O(n) (linear search)

func (*SyncedVector[T, U]) KeyOfPntr

func (v *SyncedVector[T, U]) KeyOfPntr(val *T) (int, bool)

Description: Places a read lock on the underlying vector and then calls the underlying vectors Vector.KeyOfPntr method.

Lock Type: Read

Time Complexity: O(n) (linear search)

func (*SyncedVector[T, U]) KeyedEq

func (v *SyncedVector[T, U]) KeyedEq(
	other containerTypes.KeyedComparisonsOtherConstraint[int, T],
) bool

Description: Places a read lock on the underlying vector and then calls the underlying vectors Vector.KeyedEq method. Attempts to place a read lock on other but whether or not that happens is implementation dependent.

Lock Type: Read on this vector, read on other

Time Complexity: Dependent on the time complexity of the implementation of the GetPntr method on other. In big-O it might look something like this, O(n*O(other.GetPntr))), where n is the number of elements in v and O(other.ContainsPntr) represents the time complexity of the containsPntr method on other.

func (*SyncedVector[T, U]) Keys

func (v *SyncedVector[T, U]) Keys() iter.Iter[int]

Description: Modifies the iterator chain returned by the unerlying Vector.Keys method such that a read lock will be placed on the underlying vector when iterator is consumed. The vector will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator starts to be consumed.

Lock Type: Read

Time Complexity: O(n)

func (*SyncedVector[T, U]) Length

func (v *SyncedVector[T, U]) Length() int

Description: Places a read lock on the underlying vector and then calls the underlying vectors Vector.Length method.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedVector[T, U]) Lock

func (v *SyncedVector[T, U]) Lock()

The SyncedVector method to override the Vector pass through function and actually apply the mutex operation.

func (*SyncedVector[T, U]) PeekBack

func (v *SyncedVector[T, U]) PeekBack() (T, error)

Description: Places a read lock on the underlying vector and then attempts to return the value at index len(v)-1 if one is present. Exhibits the same behavior as the Vector.PeekBack method. The underlying Vector.PeekBack method is not called to avoid copying the value twice, which could be inefficient with a large type for the T generic.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedVector[T, U]) PeekFront

func (v *SyncedVector[T, U]) PeekFront() (T, error)

Description: Places a read lock on the underlying vector and then attempts to return the value at index 0 if one is present. Exhibits the same behavior as the Vector.PeekFront method. The underlying Vector.PeekFront method is not called to avoid copying the value twice, which could be inefficient with a large type for the T generic.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedVector[T, U]) PeekPntrBack

func (v *SyncedVector[T, U]) PeekPntrBack() (*T, error)

Description: Places a read lock on the underlying vector and then calls the underlying vectors Vector.PeekPntrBack method.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedVector[T, U]) PeekPntrFront

func (v *SyncedVector[T, U]) PeekPntrFront() (*T, error)

Description: Places a read lock on the underlying vector and then calls the underlying vectors Vector.PeekPntrFront method.

Lock Type: Read

Time Complexity: O(1)

func (*SyncedVector[T, U]) Pop

func (v *SyncedVector[T, U]) Pop(val T) int

Description: Places a write lock on the underlying vector and then calls the underlying vectors Vector.Pop implementation method.

Lock Type: Write

Time Complexity: O(n)

func (*SyncedVector[T, U]) PopBack

func (v *SyncedVector[T, U]) PopBack() (T, error)

Description: Places a write lock on the underlying vector and then calls the underlying vectors Vector.PopFront implementation method.

Lock Type: Write

Time Complexity: O(1)

func (*SyncedVector[T, U]) PopFront

func (v *SyncedVector[T, U]) PopFront() (T, error)

Description: Places a write lock on the underlying vector and then calls the underlying vectors Vector.PopFront implementation method.

Lock Type: Write

Time Complexity: O(n)

func (*SyncedVector[T, U]) PopPntr

func (v *SyncedVector[T, U]) PopPntr(val *T) int

Description: Places a write lock on the underlying vector and then calls the underlying vectors Vector.PopPntr implementation method.

Lock Type: Write

Time Complexity: O(n)

func (*SyncedVector[T, U]) PopSequential

func (v *SyncedVector[T, U]) PopSequential(val T, num int) int

Description: Places a write lock on the underlying vector and then calls the underlying vectors Vector.PopSequential implementation method.

Lock Type: Write

Time Complexity: O(n)

func (*SyncedVector[T, U]) PushBack

func (v *SyncedVector[T, U]) PushBack(vals ...T) error

Description: Places a write lock on the underlying vector and then appends values to the end of the vector. Exhibits the same behavior as Vector.PushBack. The underlying Vector.PushBack method is not called to avoid copying the list of values twice, which could be inefficient with a large type for the T generic or many values.

Lock Type: Write

Time Complexity: best case O(m) (no reallocation), worst case O(n+m) (with reallocation), where m=len(vals)

func (*SyncedVector[T, U]) PushFront

func (v *SyncedVector[T, U]) PushFront(vals ...T) error

Description: Places a write lock on the underlying vector and then pushes values to the front of the vector. Exhibits the same behavior as [Vector.PusFront]. The underlying Vector.PushFront method is not called to avoid copying the list of values twice, which could be inefficient with a large type for the T generic or many values.

Lock Type: Write

Time Complexity: O(n+m), where m=len(vals)

func (*SyncedVector[T, U]) RLock

func (v *SyncedVector[T, U]) RLock()

The SyncedVector method to override the Vector pass through function and actually apply the mutex operation.

func (*SyncedVector[T, U]) RUnlock

func (v *SyncedVector[T, U]) RUnlock()

The SyncedVector method to override the Vector pass through function and actually apply the mutex operation.

func (*SyncedVector[T, U]) Set

func (v *SyncedVector[T, U]) Set(vals ...basic.Pair[int, T]) error

Description: Places a write lock on the underlying vector and then calls the underlying vectors Vector.Set method.

Lock Type: Write

Time Complexity: O(m), where m=len(vals)

func (*SyncedVector[T, U]) SetCapacity

func (v *SyncedVector[T, U]) SetCapacity(c int) error

Description: Places a write lock on the underlying vector and then calls the underlying vectors Vector.SetCapacity method.

Lock Type: Write

Time Complexity: O(n), same as Vector.SetCapacity.

func (*SyncedVector[T, U]) SetSequential

func (v *SyncedVector[T, U]) SetSequential(idx int, vals ...T) error

Description: Places a write lock on the underlying vector and then calls the underlying vectors Vector.SetSequential method.

Lock Type: Write

Time Complexity: O(m), where m=len(vals)

func (*SyncedVector[T, U]) Union

func (v *SyncedVector[T, U]) Union(
	l containerTypes.ComparisonsOtherConstraint[T],
	r containerTypes.ComparisonsOtherConstraint[T],
)

Description: Places a write lock on the underlying vector and then calls the underlying vectors Vector.Union method. Attempts to place a read lock on l and r but whether or not that happens is implementation dependent.

Lock Type: Write on this vector, read on l and r

Time Complexity: O((n+m)*(n+m)), where n is the number of values in l and m is the number of values in r.

func (*SyncedVector[T, U]) Unlock

func (v *SyncedVector[T, U]) Unlock()

The SyncedVector method to override the Vector pass through function and actually apply the mutex operation.

func (*SyncedVector[T, U]) UnorderedEq

func (v *SyncedVector[T, U]) UnorderedEq(
	other containerTypes.ComparisonsOtherConstraint[T],
) bool

Description: Places a read lock on the underlying vector and then calls the underlying vectors Vector.UnorderedEq method. Attempts to place a read lock on other but whether or not that happens is implementation dependent.

Lock Type: Read on this vector, read on other

Time Complexity: Dependent on the time complexity of the implementation of the ContainsPntr method on other. In big-O it might look something like this, O(n*O(other.ContainsPntr))), where O(other.ContainsPntr) represents the time complexity of the ContainsPntr method on other with m values.

func (*SyncedVector[T, U]) UpdateUnique

func (v *SyncedVector[T, U]) UpdateUnique(orig T, updateOp func(orig *T)) error

Description: Places a write lock on the underlying vector and then calls the underlying vectors Vector.UpdateUnique implementation method. The Vector.UpdateUnique method is not called directly to avoid copying the supplied value, which could be expensive with a large type for the T generic.

Lock Type: Write

Time Complexity: O(n)

func (*SyncedVector[T, U]) ValPntrs

func (v *SyncedVector[T, U]) ValPntrs() iter.Iter[*T]

Description: Modifies the iterator chain returned by the unerlying Vector.ValPntrs method such that a read lock will be placed on the underlying vector when the iterator is consumed. The vector will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator starts to be consumed.

Lock Type: Read

Time Complexity: O(n)

func (*SyncedVector[T, U]) Vals

func (v *SyncedVector[T, U]) Vals() iter.Iter[T]

Description: Modifies the iterator chain returned by the unerlying Vector.Vals method such that a read lock will be placed on the underlying vector when the iterator is consumed. The vector will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator starts to be consumed.

Lock Type: Read

Time Complexity: O(n)

func (*SyncedVector[T, U]) Zero

func (_ *SyncedVector[T, U]) Zero(other *SyncedVector[T, U])

An zero function that implements the [widget.Base] interface. Internally this is equivalent to SyncedVector.Clear.

type Vector

type Vector[T any, U widgets.BaseInterface[T]] []T

A type to represent an array that dynamically grows as elements are added. This is nothing more than a generically initialized slice with methods attached to it so it can be passed to functions that use the interfaces defined in the containerTypes, staticContainers, or dynamicContainers packages. The type constraints on the generics define the logic for how value specific operations, such as equality comparisons, will be handled.

Example (TypeCasting)
// Vectors can be type casted back and forth to regular slices. Note that
// when you do this you loose any type information provided by the widget
// interface.
v, _ := NewVector[string, widgets.BuiltinString](3)
s := []string(v)
_ = s

s2 := make([]string, 4)
v2 := Vector[string, widgets.BuiltinString](s2)
_ = v2
Output:

Example (ValueInitilizer)
v := VectorValInit[string, widgets.BuiltinString]("one", "two", "three")
fmt.Println(v)
Output:

vec[one two three]

func NewVector

func NewVector[T any, U widgets.BaseInterface[T]](size int) (Vector[T, U], error)

Creates a new vector initialized with size zero valued elements. Size must be >= 0, an error will be returned if it is not. If size is 0 the vector will be initialized with 0 elements. A vector can also be created by type casting a standard slice, as shown below.

// Vector to slice.
v,_:=NewVector[string,builtinBases.BuiltinString](3)
s:=[]string(v)
// Slice to vector.
s2:=make([]string,4)
v2:=Vector[string,builtinBases.BuiltinString](s2)

Note that by performing the above type casts the operations provided by the widget, including equality, are not preserved.

func VectorValInit

func VectorValInit[T any, U widgets.BaseInterface[T]](vals ...T) Vector[T, U]

Creates a new vector and populates it with the supplied values.

func (*Vector[T, U]) Append

func (v *Vector[T, U]) Append(vals ...T) error

Description: Append the supplied values to the vector. This function will never return an error.

Time Complexity: Best case O(m), worst case O(n+m) (reallocation), where m=len(vals).

func (*Vector[T, U]) AppendUnique

func (v *Vector[T, U]) AppendUnique(vals ...T) error

Description: AppendUnique will append the supplied values to the vector if they are not already present in the vector (unique). Non-unique values will not be appended. This function will never return an error.

Time Complexity: Best case O(m) (no reallocation), worst case O(n+m) (reallocation), where m=len(vals).

func (*Vector[T, U]) Capacity

func (v *Vector[T, U]) Capacity() int

Description: Returns the capacity of the vector.

Time Complexity: O(1)

func (*Vector[T, U]) Clear

func (v *Vector[T, U]) Clear()

Description: Clears all values from the vector.

Time Complexity: O(n) (Because of zeroing)

func (*Vector[T, U]) Contains

func (v *Vector[T, U]) Contains(val T) bool

Description: Contains will return true if the supplied value is in the vector, false otherwise. All equality comparisons are performed by the generic U widget type that the vector was initialized with.

Time Complexity: O(n) (linear search)

func (*Vector[T, U]) ContainsPntr

func (v *Vector[T, U]) ContainsPntr(val *T) bool

Description: ContainsPntr will return true if the supplied value is in the vector, false otherwise. All equality comparisons are performed by the generic U widget type that the vector was initialized with.

Time Complexity: O(n) (linear search)

func (*Vector[T, U]) Delete

func (v *Vector[T, U]) Delete(idx int) error

Description: Deletes the value at the specified index. Returns an error if the index is >= the length of the vector.

Time Complexity: O(n)

func (*Vector[T, U]) DeleteSequential

func (v *Vector[T, U]) DeleteSequential(start int, end int) error

Description: Deletes the values in the index range [start,end). Returns an error if the start index is < 0, the end index is > the length of the vector, or the end index is < the start index.

Time Complexity: O(n)

func (*Vector[T, U]) Difference

Description: Populates the vector with the result of taking the difference of r from l. This vector will be cleared before storing the result. When clearing, the new resulting vector will be initialized with zero capacity and enough backing memory to store half the length of l. This means that there should be at most 1 reallocation beyond this initial allocation, and that additional allocation should only occur when the length of the difference is greater than half the length of l. This logic is predicated on the fact that differences will likely be much smaller than the original vector.

Time Complexity: Dependent on the time complexity of the implementation of the ContainsPntr method on l and r. In big-O it might look something like this, O(O(r.ContainsPntr)*O(l.ContainsPntr)), where O(r.ContainsPntr) represents the time complexity of the containsPntr method on r and O(l.ContainsPntr) represents the time complexity of the containsPntr method on l.

func (*Vector[T, U]) Eq

func (_ *Vector[T, U]) Eq(l *Vector[T, U], r *Vector[T, U]) bool

An equality function that implements the [widget.Base] interface. Internally this is equivalent to Vector.KeyedEq. Returns true if l==r, false otherwise.

func (*Vector[T, U]) ForcePushBack

func (v *Vector[T, U]) ForcePushBack(vals ...T)

Description: Pushes an element to the back of the vector. Equivalent to appending a single value to the end of the vector. Has the same behavior as PushBack because the underlying vector grows as needed.

Time Complexity: O(m), where m=len(vals)

func (*Vector[T, U]) ForcePushFront

func (v *Vector[T, U]) ForcePushFront(vals ...T)

Description: Pushes an element to the front of the vector. Equivalent to inserting a single value at the front of the vector. Has the same behavior as PushBack because the underlying vector grows as needed.

Time Complexity: O(n+m), where m=len(vals)

func (Vector[T, U]) Format

func (v Vector[T, U]) Format(f fmt.State, verb rune)

Implements the fmt.Formatter interface.

func (*Vector[T, U]) Get

func (v *Vector[T, U]) Get(idx int) (T, error)

Description: Gets the value at the specified index. Returns an error if the index is >= the length of the vector.

Time Complexity: O(1)

func (*Vector[T, U]) GetPntr

func (v *Vector[T, U]) GetPntr(idx int) (*T, error)

Description: Gets a pointer to the value at the specified index. Returns an error if the index is >= the length of the vector.

Time Complexity: O(1)

func (*Vector[T, U]) GetUnique

func (v *Vector[T, U]) GetUnique(val *T) error

Description: Populates the supplied value with the value that is in the container. This is useful when storing structs and the structs identity as defined by the U widget only depends on a subset of the structs fields. This function allows for getting the entire value based on just the part of the struct that defines it's identity. Returns a value error if the value is not found in the vector.

Time complexity: O(n)

func (*Vector[T, U]) Hash

func (_ *Vector[T, U]) Hash(other *Vector[T, U]) hash.Hash

A function that returns a hash of a vector to implement the [widget.Base]. To do this all of the individual hashes that are produced from the elements of the vector are combined in a way that maintains identity, making it so the hash will represent the same equality operation that Vector.KeyedEq and Vector.Eq provide.

func (*Vector[T, U]) Insert

func (v *Vector[T, U]) Insert(vals ...basic.Pair[int, T]) error

Description: Insert will insert the supplied values into the vector. The values will be inserted in the order that they are given.

Time Complexity: O(n*m), where m=len(vals)

func (*Vector[T, U]) InsertSequential

func (v *Vector[T, U]) InsertSequential(idx int, vals ...T) error

Description: Inserts the supplied values at the given index. Returns an error if the index is >= the length of the vector.

Time Complexity: O(n+m), where m=len(vals). For time complexity see the InsertVector section of https://go.dev/wiki/SliceTricks

func (*Vector[T, U]) Intersection

Description: Populates the vector with the intersection of values from the l and r containers. This vector will be cleared before storing the result. When clearing, the new resulting vector will be initialized with zero length and enough backing capacity to store (l.Length()+r.Length())/2 elements before reallocating. This means that there should be at most 1 reallocation beyond this initial allocation, and that additional allocation should only occur when the length of the intersection is greater than the average length of the l and r vectors. This logic is predicated on the fact that intersections will likely be much smaller than the original vectors.

Time Complexity: Dependent on the time complexity of the implementation of the ContainsPntr method on l and r. In big-O it might look something like this, O(O(r.ContainsPntr)*O(l.ContainsPntr)), where O(r.ContainsPntr) represents the time complexity of the containsPntr method on r and O(l.ContainsPntr) represents the time complexity of the containsPntr method on l.

func (*Vector[T, U]) IsAddressable

func (v *Vector[T, U]) IsAddressable() bool

Returns true, vectors are addressable.

func (*Vector[T, U]) IsSubset

func (v *Vector[T, U]) IsSubset(
	other containerTypes.ComparisonsOtherConstraint[T],
) bool

Description: Returns true if this vector is a subset to other.

Time Complexity: Dependent on the ContainsPntr method of other. In big-O terms it may look somwthing like this: O(n*O(other.ContainsPntr)), where n is the number of elements in the current vector and other.ContainsPntr represents the time complexity of the containsPntr method on other.

func (*Vector[T, U]) IsSuperset

func (v *Vector[T, U]) IsSuperset(
	other containerTypes.ComparisonsOtherConstraint[T],
) bool

Description: Returns true if this vector is a superset to other.

Time Complexity: O(n*m), where n is the number of values in this vector and m is the number of values in other.

func (*Vector[T, U]) IsSynced

func (h *Vector[T, U]) IsSynced() bool

Returns false, a vector is not synced.

func (*Vector[T, U]) KeyOf

func (v *Vector[T, U]) KeyOf(val T) (int, bool)

Description: KeyOf will return the index of the first occurrence of the supplied value in the vector. If the value is not found then the returned index will be -1 and the boolean flag will be set to false. If the value is found then the boolean flag will be set to true. All equality comparisons are performed by the generic U widget type that the vector was initialized with.

Time Complexity: O(n) (linear search)

func (*Vector[T, U]) KeyOfPntr

func (v *Vector[T, U]) KeyOfPntr(val *T) (int, bool)

Description: KeyOfPntr will return the index of the first occurrence of the supplied value in the vector. If the value is not found then the returned index will be -1 and the boolean flag will be set to false. If the value is found then the boolean flag will be set to true. All equality comparisons are performed by the generic U widget type that the vector was initialized with.

Time Complexity: O(n) (linear search)

func (*Vector[T, U]) KeyedEq

func (v *Vector[T, U]) KeyedEq(
	other containerTypes.KeyedComparisonsOtherConstraint[int, T],
) bool

Description: Returns true if all the key value pairs in v are all contained in other and the key value pairs in other are all contained in v. Returns false otherwise.

Time Complexity: Dependent on the time complexity of the implementation of the Get/GetPntr method on other. In big-O it might look something like this, O(n*O(other.GetPntr))), where n is the number of elements in v and O(other.ContainsPntr) represents the time complexity of the containsPntr method on other.

func (*Vector[T, U]) Keys

func (v *Vector[T, U]) Keys() iter.Iter[int]

Description: Returns an iterator that iterates over the keys (indexes) of the vector. The vector will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator starts to be consumed.

Time Complexity: O(n)

func (*Vector[T, U]) Length

func (v *Vector[T, U]) Length() int

Description: Returns the length of the vector.

Time Complexity: O(1)

func (*Vector[T, U]) Lock

func (v *Vector[T, U]) Lock()

A empty pass through function that performs no action. Needed for the containerTypes.Comparisons interface.

func (*Vector[T, U]) PeekBack

func (v *Vector[T, U]) PeekBack() (T, error)

Description: Returns the value at index len(v)-1 if one is present. If the vector has no elements then an error is returned.

Time Complexity: O(1)

func (*Vector[T, U]) PeekFront

func (v *Vector[T, U]) PeekFront() (T, error)

Description: Returns the value at index 0 if one is present. If the vector has no elements then an error is returned.

Time Complexity: O(1)

func (*Vector[T, U]) PeekPntrBack

func (v *Vector[T, U]) PeekPntrBack() (*T, error)

Description: Returns a pointer to the value at index len(v)-1 if one is present. If the vector has no elements then an error is returned.

Time Complexity: O(1)

func (*Vector[T, U]) PeekPntrFront

func (v *Vector[T, U]) PeekPntrFront() (*T, error)

Description: Returns a pointer to the value at index 0 if one is present. If the vector has no elements then an error is returned.

Time Complexity: O(1)

func (*Vector[T, U]) Pop

func (v *Vector[T, U]) Pop(val T) int

Description: Pop will remove all occurrences of val in the vector. All equality comparisons are performed by the generic U widget type that the vector was initialized with.

Time Complexity: O(n)

func (*Vector[T, U]) PopBack

func (v *Vector[T, U]) PopBack() (T, error)

Description: Returns and removes the element at the back of the vector. Returns an error if the vector has no elements.

Time Complexity: O(1)

func (*Vector[T, U]) PopFront

func (v *Vector[T, U]) PopFront() (T, error)

Description: Returns and removes the element at the front of the vector. Returns an error if the vector has no elements.

Time Complexity: O(n)

func (*Vector[T, U]) PopPntr

func (v *Vector[T, U]) PopPntr(val *T) int

Description: PopPntr will remove all occurrences of val in the vector. All equality comparisons are performed by the generic U widget type that the vector was initialized with.

Time Complexity: O(n)

func (*Vector[T, U]) PopSequential

func (v *Vector[T, U]) PopSequential(val T, num int) int

Description: PopSequential will remove the first num occurrences of val in the vector. All equality comparisons are performed by the generic U widget type that the vector was initialized with. If num is <=0 then no values will be poped and the vector will not change.

Time Complexity: O(n)

func (*Vector[T, U]) PushBack

func (v *Vector[T, U]) PushBack(vals ...T) error

Description: Pushes an element to the back of the vector. Equivalent to appending values to the end of the vector. Values will be pushed back in the order that they are given. For example, calling push back on [0,1,2] with vals of [3,4] will result in [0,1,2,3,4].

Time Complexity: best case O(m) (no reallocation), worst case O(n+m) (with reallocation), where m=len(vals)

func (*Vector[T, U]) PushFront

func (v *Vector[T, U]) PushFront(vals ...T) error

Description: Pushes an element to the front of the vector. Equivalent to inserting a single value at the front of the vector. Values will be pushed to the front in the order that they are given. For example, calling push front on [0,1,2] with vals of [3,4] will result in [3,4,0,1,2].

Time Complexity: O(n+m), where m=len(vals)

func (*Vector[T, U]) RLock

func (v *Vector[T, U]) RLock()

A empty pass through function that performs no action. Needed for the containerTypes.Comparisons interface.

func (*Vector[T, U]) RUnlock

func (v *Vector[T, U]) RUnlock()

A empty pass through function that performs no action. Needed for the containerTypes.Comparisons interface.

func (*Vector[T, U]) Set

func (v *Vector[T, U]) Set(vals ...basic.Pair[int, T]) error

Description: Sets the values at the specified indexes. Returns an error if the index is >= the length of the vector. Stops setting values as soon as an error is encountered.

Time Complexity: O(m), where m=len(vals)

func (*Vector[T, U]) SetCapacity

func (v *Vector[T, U]) SetCapacity(c int) error

Description: Sets the capacity of the underlying slice. If the new capacity is less than the old capacity then values at the end of the slice will be dropped.

Time Complexity: O(n) because a copy operation is performed.

func (*Vector[T, U]) SetSequential

func (v *Vector[T, U]) SetSequential(idx int, vals ...T) error

Description: Sets the supplied values sequentially starting at the supplied index and continuing sequentailly after that. Returns and error if any index that is attempted to be set is >= the length of the vector. If an error occurs, all values will be set up until the value that caused the error.

Time Complexity: O(m), where m=len(vals)

func (*Vector[T, U]) String

func (v *Vector[T, U]) String() string

Implements the fmt.Stringer interface.

func (*Vector[T, U]) ToSynced

func (v *Vector[T, U]) ToSynced() SyncedVector[T, U]

Converts the supplied vector to a syncronized vector. Beware: The original non-synced vector will remain useable.

func (*Vector[T, U]) Union

Description: Populates the vector with the union of values from the l and r containers. This vector will be cleared before storing the result. When clearing, the new resulting vector will be initialized with zero capacity and enough backing memory to store the average of the maximum and minimum possible union sizes before reallocating. This means that there should be at most 1 reallocation beyond this initial allocation, and that additional allocation should only occur when the length of the union is greater than the average length of the minimum and maximum possible union sizes. This logic is predicated on the fact that unions will likely be much smaller than the original vectors.

Time Complexity: O((n+m)*(n+m)), where n is the number of values in l and m is the number of values in r.

func (*Vector[T, U]) Unlock

func (v *Vector[T, U]) Unlock()

A empty pass through function that performs no action. Needed for the containerTypes.Comparisons interface.

func (*Vector[T, U]) UnorderedEq

func (v *Vector[T, U]) UnorderedEq(
	other containerTypes.ComparisonsOtherConstraint[T],
) bool

Description: Returns true if the elements in v are all contained in other and the elements of other are all contained in v, regardless of position. Returns false otherwise.

Time Complexity: Dependent on the time complexity of the implementation of the ContainsPntr method on other. In big-O it might look something like this, O(n*O(other.ContainsPntr))), where O(other.ContainsPntr) represents the time complexity of the ContainsPntr method on other with m values.

func (*Vector[T, U]) UpdateUnique

func (v *Vector[T, U]) UpdateUnique(orig T, updateOp func(orig *T)) error

Description: updates the supplied value in the underlying vector set, assuming that it is present in the vector already. The hash must not change from the update and the updated value must compare equal to the original value. If these rules are broken then an update violation error will be returned. This method is useful when you are storing struct values and want to update a field that is not utilized when calculating the hash and is also ignored when comparing for equality. This assumes congruency is present between the hash and equality methods defined in the U widget. If the value is not found then a key error will be returned.

Time Complexity: O(n)

func (*Vector[T, U]) ValPntrs

func (v *Vector[T, U]) ValPntrs() iter.Iter[*T]

Description: Returns an iterator that iterates over the pointers to the values in the vector. The vector will have a read lock the entire time the iteration is being performed. The lock will not be applied until the iterator is consumed.

Time Complexity: O(n)

func (*Vector[T, U]) Vals

func (v *Vector[T, U]) Vals() iter.Iter[T]

Description: Returns an iterator that iterates over the values in the vector.

Time Complexity: O(n)

func (*Vector[T, U]) Zero

func (_ *Vector[T, U]) Zero(other *Vector[T, U])

An zero function that implements the [widget.Base] interface. Internally this is equivalent to Vector.Clear.

Jump to

Keyboard shortcuts

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