Documentation
¶
Overview ¶
Package datastructures provides generic data structure interfaces and implementations for Go.
See README.md for details.
Index ¶
- Variables
- type AbstractMap
- type AbstractMatrix
- type AbstractSet
- type BiMap
- type Clonable
- type ConcurrentBiMap
- type ConcurrentMap
- type ConcurrentSet
- type Equatable
- type HashCode
- type Hashable
- type ImmutableTable
- type Map
- type MapEntry
- type MutableBiMap
- type MutableMap
- type MutableSet
- type Set
- type Table
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidSize = errs.New("invalid size")
ErrInvalidSize is returned when an operation encounters a size mismatch or invalid size constraint.
Functions ¶
This section is empty.
Types ¶
type AbstractMap ¶
type AbstractMap[K, V, C any] interface { // Size returns the number of key-value pairs in the map. Size() C // Iter returns an iterator over all key-value pairs. Iter() iter.Seq2[K, V] }
AbstractMap defines the core operations for any map-like data structure. K is the key type, V is the value type, and C is the type used for size.
type AbstractMatrix ¶
type AbstractMatrix[T, C any] interface { // Dimensions returns the number of rows (n) and columns (m) in the matrix. Dimensions() (n, m C) // Transpose returns a new matrix with rows and columns swapped. Transpose() T // SubMatrix returns a sub-matrix from row1 to row2 and col1 to col2 (exclusive). SubMatrix(row1, row2, col1, col2 int) T // IsSquare returns true if the matrix has equal rows and columns. IsSquare() bool // IsDiagonal returns true if all non-diagonal elements are zero. IsDiagonal() bool }
AbstractMatrix defines basic matrix operations for any matrix-like data structure. T is the concrete matrix type and C is the type used for dimension counts.
type AbstractSet ¶
type AbstractSet[E, C any] interface { // Cardinality returns the number of elements in the set. Cardinality() C // Iter returns an iterator over all elements in the set. Iter() iter.Seq[E] // Contains returns true if the element is in the set. Contains(e E) bool }
AbstractSet defines the core operations for any set-like data structure. E is the element type and C is the type used for cardinality.
type BiMap ¶
type BiMap[K, V any] interface { // Reverse returns a view of this bimap with keys and values swapped. Reverse() BiMap[V, K] // Unfreeze returns a mutable copy of this bimap. Unfreeze() MutableBiMap[K, V] // contains filtered or unexported methods }
BiMap is an immutable bidirectional map where both keys and values are unique. Looking up by key or by value is equally efficient via the Reverse method.
type Clonable ¶
type Clonable[T any] interface { // Clone creates and returns a deep copy of the receiver. Clone() T }
Clonable represents a type that can be cloned.
type ConcurrentBiMap ¶
type ConcurrentBiMap[K, V any] interface { // Reverse returns a thread-safe view of this bimap with keys and values swapped. Reverse() ConcurrentBiMap[V, K] // contains filtered or unexported methods }
ConcurrentBiMap is a thread-safe bidirectional map supporting atomic compute operations. All methods are safe for concurrent use by multiple goroutines.
type ConcurrentMap ¶
type ConcurrentMap[K, V any] interface { // Enumerate returns an iterator with index and MapEntry pairs. Enumerate() iter.Seq2[int, MapEntry[K, V]] // contains filtered or unexported methods }
ConcurrentMap is a thread-safe map interface supporting atomic compute operations. All methods are safe for concurrent use by multiple goroutines.
type ConcurrentSet ¶
type ConcurrentSet[E any] interface { // contains filtered or unexported methods }
ConcurrentSet is a thread-safe set interface supporting atomic compute operations. All methods are safe for concurrent use by multiple goroutines.
type Equatable ¶
type Equatable[T any] interface { // Equal checks if the receiver is equal to rhs. Equal(rhs T) bool }
Equatable represents a type that can be compared for equality.
type HashCode ¶
type HashCode uint64
HashCode represents a 64-bit hash code.
func DeriveHashCode ¶
DeriveHashCode derives a HashCode from one or more byte slices.
type Hashable ¶
type Hashable[T any] interface { Equatable[T] // HashCode returns the hash code of the receiver. HashCode() HashCode }
Hashable represents a type that can be hashed and compared for equality.
type ImmutableTable ¶
type ImmutableTable[E any] immutableTable[E, ImmutableTable[E]]
ImmutableTable is a read-only two-dimensional table of elements.
type Map ¶
type Map[K, V any] interface { // Enumerate returns an iterator with index and MapEntry pairs. Enumerate() iter.Seq2[int, MapEntry[K, V]] // Unfreeze returns a mutable copy of this map. Unfreeze() MutableMap[K, V] // contains filtered or unexported methods }
Map is an immutable map interface providing read-only access to key-value pairs. Use Unfreeze to obtain a mutable copy.
type MutableBiMap ¶
type MutableBiMap[K, V any] interface { // Reverse returns a view of this bimap with keys and values swapped. Reverse() MutableBiMap[V, K] // Freeze returns an immutable snapshot of this bimap. Freeze() BiMap[K, V] // contains filtered or unexported methods }
MutableBiMap is a mutable bidirectional map where both keys and values are unique. Looking up by key or by value is equally efficient via the Reverse method.
type MutableMap ¶
type MutableMap[K, V any] interface { // Enumerate returns an iterator with index and MapEntry pairs. Enumerate() iter.Seq2[int, MapEntry[K, V]] // Freeze returns an immutable snapshot of this map. Freeze() Map[K, V] // contains filtered or unexported methods }
MutableMap is a mutable map interface supporting put, remove, and clear operations. Use Freeze to obtain an immutable snapshot.
type MutableSet ¶
type MutableSet[E any] interface { // Freeze returns an immutable snapshot of this set. Freeze() Set[E] // contains filtered or unexported methods }
MutableSet is a mutable set interface supporting add, remove, and clear operations. Use Freeze to obtain an immutable snapshot.
type Set ¶
type Set[E any] interface { // Unfreeze returns a mutable copy of this set. Unfreeze() MutableSet[E] // contains filtered or unexported methods }
Set is an immutable set interface providing read-only access to set elements. Use Unfreeze to obtain a mutable copy.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package bimap provides bidirectional map implementations for the datastructures interfaces.
|
Package bimap provides bidirectional map implementations for the datastructures interfaces. |
|
Package hashmap provides hash-based map implementations for the datastructures interfaces.
|
Package hashmap provides hash-based map implementations for the datastructures interfaces. |
|
Package hashset provides hash-based set implementations for the datastructures interfaces.
|
Package hashset provides hash-based set implementations for the datastructures interfaces. |