Documentation
¶
Index ¶
- type Adder
- type Clearer
- type Containser
- type Differencer
- type EmptyChecker
- type Equaler
- type InsertionOrderedSet
- func (s *InsertionOrderedSet[T]) Add(items ...T)
- func (s *InsertionOrderedSet[T]) All() iter.Seq[T]
- func (s *InsertionOrderedSet[T]) Clear()
- func (s *InsertionOrderedSet[T]) Contains(t T) bool
- func (s *InsertionOrderedSet[T]) Difference(other *InsertionOrderedSet[T]) *InsertionOrderedSet[T]
- func (s *InsertionOrderedSet[T]) Equal(other *InsertionOrderedSet[T]) bool
- func (s *InsertionOrderedSet[T]) Intersection(other *InsertionOrderedSet[T]) *InsertionOrderedSet[T]
- func (s *InsertionOrderedSet[T]) IsEmpty() bool
- func (s *InsertionOrderedSet[T]) Len() int
- func (s *InsertionOrderedSet[T]) Remove(items ...T)
- func (s *InsertionOrderedSet[T]) Union(other *InsertionOrderedSet[T]) *InsertionOrderedSet[T]
- func (s *InsertionOrderedSet[T]) Values() []T
- type Intersectioner
- type Iterable
- type Lener
- type OrderedSet
- func (s *OrderedSet[T]) Add(items ...T)
- func (s *OrderedSet[T]) All() iter.Seq[T]
- func (s *OrderedSet[T]) Clear()
- func (s *OrderedSet[T]) Contains(t T) (found bool)
- func (s *OrderedSet[T]) Difference(other *OrderedSet[T]) *OrderedSet[T]
- func (s *OrderedSet[T]) Equal(other *OrderedSet[T]) bool
- func (s *OrderedSet[T]) Intersection(other *OrderedSet[T]) *OrderedSet[T]
- func (s *OrderedSet[T]) IsEmpty() bool
- func (s *OrderedSet[T]) Len() int
- func (s *OrderedSet[T]) Remove(items ...T)
- func (s *OrderedSet[T]) Union(other *OrderedSet[T]) *OrderedSet[T]
- func (s *OrderedSet[T]) Values() []T
- type Remover
- type Set
- func (s *Set[T]) Add(items ...T)
- func (s *Set[T]) All() iter.Seq[T]
- func (s *Set[T]) Clear()
- func (s *Set[T]) Contains(t T) (found bool)
- func (s *Set[T]) Difference(other *Set[T]) *Set[T]
- func (s *Set[T]) Equal(other *Set[T]) bool
- func (s *Set[T]) Intersection(other *Set[T]) *Set[T]
- func (s *Set[T]) IsEmpty() bool
- func (s *Set[T]) Len() int
- func (s *Set[T]) Remove(items ...T)
- func (s *Set[T]) Union(other *Set[T]) *Set[T]
- func (s *Set[T]) Values() []T
- type Unioner
- type Valuer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adder ¶ added in v1.0.0
type Adder[T any] interface { Add(...T) }
Adder inserts elements into a collection.
type Clearer ¶ added in v1.0.0
type Clearer interface {
Clear()
}
Clearer removes all elements from a collection.
type Containser ¶ added in v1.0.0
Containser checks if an element exists in a collection.
type Differencer ¶ added in v1.0.0
Differencer returns elements in one collection but not another.
type EmptyChecker ¶ added in v1.0.0
type EmptyChecker interface {
IsEmpty() bool
}
EmptyChecker determines if a collection is empty.
type InsertionOrderedSet ¶ added in v1.0.0
type InsertionOrderedSet[T comparable] struct { // contains filtered or unexported fields }
InsertionOrderedSet is a generic set data structure that preserves insertion order. Unlike Set (unordered) and OrderedSet (sorted), InsertionOrderedSet returns values in the order they were first added. It provides O(1) membership checks but O(n) removal operations. Duplicate values are automatically handled - adding the same value multiple times has no effect beyond the first addition.
func NewInsertionOrderedSet ¶ added in v1.0.0
func NewInsertionOrderedSet[T comparable](items ...T) *InsertionOrderedSet[T]
NewInsertionOrderedSet creates a new InsertionOrderedSet with the given initial items. Items are stored in the order provided. Duplicate items are deduplicated while preserving the first occurrence's position.
func (*InsertionOrderedSet[T]) Add ¶ added in v1.0.0
func (s *InsertionOrderedSet[T]) Add(items ...T)
Add inserts one or more items into the set. Items are added to the end of the order. Adding items that already exist has no effect. Time complexity: O(m) where m is the number of items to add
func (*InsertionOrderedSet[T]) All ¶ added in v1.0.0
func (s *InsertionOrderedSet[T]) All() iter.Seq[T]
All returns an iterator over all elements in the set in insertion order. Elements are yielded in the order they were first added to the set. The iterator can be used with range loops: for v := range set.All() { ... } Time complexity: O(n)
func (*InsertionOrderedSet[T]) Clear ¶ added in v1.0.0
func (s *InsertionOrderedSet[T]) Clear()
Clear removes all elements from the set, making it empty. Time complexity: O(1)
func (*InsertionOrderedSet[T]) Contains ¶ added in v1.0.0
func (s *InsertionOrderedSet[T]) Contains(t T) bool
Contains checks if the given item exists in the set. Returns true if the item is present, false otherwise. Time complexity: O(1)
func (*InsertionOrderedSet[T]) Difference ¶ added in v1.0.0
func (s *InsertionOrderedSet[T]) Difference(other *InsertionOrderedSet[T]) *InsertionOrderedSet[T]
Difference returns a new set containing elements that are in this set but not in the other set. The insertion order from this set is preserved. Time complexity: O(n) where n is the size of this set
func (*InsertionOrderedSet[T]) Equal ¶ added in v1.0.0
func (s *InsertionOrderedSet[T]) Equal(other *InsertionOrderedSet[T]) bool
Equal returns true if both sets contain exactly the same elements. Order is not considered for equality - only membership matters. Time complexity: O(n) where n is the size of this set
func (*InsertionOrderedSet[T]) Intersection ¶ added in v1.0.0
func (s *InsertionOrderedSet[T]) Intersection(other *InsertionOrderedSet[T]) *InsertionOrderedSet[T]
Intersection returns a new set containing only elements that exist in both sets. The insertion order from this set is preserved for common elements. Time complexity: O(n) where n is the size of this set
func (*InsertionOrderedSet[T]) IsEmpty ¶ added in v1.0.0
func (s *InsertionOrderedSet[T]) IsEmpty() bool
IsEmpty returns true if the set contains no elements. Time complexity: O(1)
func (*InsertionOrderedSet[T]) Len ¶ added in v1.0.0
func (s *InsertionOrderedSet[T]) Len() int
Len returns the number of elements in the set. Time complexity: O(1)
func (*InsertionOrderedSet[T]) Remove ¶ added in v1.0.0
func (s *InsertionOrderedSet[T]) Remove(items ...T)
Remove deletes one or more items from the set. Removing items that don't exist has no effect. Time complexity: O(n*m) where n is set size and m is number of items to remove
func (*InsertionOrderedSet[T]) Union ¶ added in v1.0.0
func (s *InsertionOrderedSet[T]) Union(other *InsertionOrderedSet[T]) *InsertionOrderedSet[T]
Union returns a new set containing all elements from both this set and the other set. Elements from this set appear first in insertion order, followed by new elements from the other set in their insertion order. Time complexity: O(n + m) where n and m are the sizes of the two sets
func (*InsertionOrderedSet[T]) Values ¶ added in v1.0.0
func (s *InsertionOrderedSet[T]) Values() []T
Values returns all elements in the set as a slice in insertion order. The order reflects the sequence in which elements were first added. Time complexity: O(n)
type Intersectioner ¶ added in v1.0.0
Intersectioner returns common elements between two collections.
type Lener ¶ added in v1.0.0
type Lener interface {
Len() int
}
Lener returns the number of elements in a collection.
type OrderedSet ¶ added in v1.0.0
OrderedSet is a generic set data structure for ordered types (integers, floats, strings). Unlike Set, OrderedSet returns values in sorted order when calling Values(). It provides O(1) membership checks and efficient set operations. Duplicate values are automatically handled - adding the same value multiple times has no effect beyond the first addition.
func NewOrderedSet ¶
func NewOrderedSet[T cmp.Ordered](items ...T) *OrderedSet[T]
NewOrderedSet creates a new OrderedSet with the given initial items. Duplicate items in the input are automatically deduplicated.
func (*OrderedSet[T]) Add ¶ added in v1.0.0
func (s *OrderedSet[T]) Add(items ...T)
Add inserts one or more items into the set. Adding items that already exist has no effect.
func (*OrderedSet[T]) All ¶ added in v1.0.0
func (s *OrderedSet[T]) All() iter.Seq[T]
All returns an iterator over all elements in the set in sorted order. Elements are yielded in ascending order. The iterator can be used with range loops: for v := range set.All() { ... }
func (*OrderedSet[T]) Clear ¶ added in v1.0.0
func (s *OrderedSet[T]) Clear()
Clear removes all elements from the set, making it empty.
func (*OrderedSet[T]) Contains ¶ added in v1.0.0
func (s *OrderedSet[T]) Contains(t T) (found bool)
Contains checks if the given item exists in the set. Returns true if the item is present, false otherwise.
func (*OrderedSet[T]) Difference ¶ added in v1.0.0
func (s *OrderedSet[T]) Difference(other *OrderedSet[T]) *OrderedSet[T]
Difference returns a new set containing elements that are in this set but not in the other set.
func (*OrderedSet[T]) Equal ¶ added in v1.0.0
func (s *OrderedSet[T]) Equal(other *OrderedSet[T]) bool
Equal returns true if both sets contain exactly the same elements.
func (*OrderedSet[T]) Intersection ¶ added in v1.0.0
func (s *OrderedSet[T]) Intersection(other *OrderedSet[T]) *OrderedSet[T]
Intersection returns a new set containing only elements that exist in both sets.
func (*OrderedSet[T]) IsEmpty ¶ added in v1.0.0
func (s *OrderedSet[T]) IsEmpty() bool
IsEmpty returns true if the set contains no elements.
func (*OrderedSet[T]) Len ¶ added in v1.0.0
func (s *OrderedSet[T]) Len() int
Len returns the number of elements in the set.
func (*OrderedSet[T]) Remove ¶ added in v1.0.0
func (s *OrderedSet[T]) Remove(items ...T)
Remove deletes one or more items from the set. Removing items that don't exist has no effect.
func (*OrderedSet[T]) Union ¶ added in v1.0.0
func (s *OrderedSet[T]) Union(other *OrderedSet[T]) *OrderedSet[T]
Union returns a new set containing all elements from both this set and the other set.
func (*OrderedSet[T]) Values ¶ added in v1.0.0
func (s *OrderedSet[T]) Values() []T
Values returns all elements in the set as a sorted slice. Elements are sorted in ascending order.
type Remover ¶ added in v1.0.0
type Remover[T any] interface { Remove(...T) }
Remover deletes elements from a collection.
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
Set is a generic unordered set data structure for any comparable type. It provides O(1) membership checks and efficient set operations. Duplicate values are automatically handled - adding the same value multiple times has no effect beyond the first addition.
func NewSet ¶
func NewSet[T comparable](items ...T) *Set[T]
NewSet creates a new Set with the given initial items. Duplicate items in the input are automatically deduplicated.
func (*Set[T]) Add ¶ added in v1.0.0
func (s *Set[T]) Add(items ...T)
Add inserts one or more items into the set. Adding items that already exist has no effect.
func (*Set[T]) All ¶ added in v1.0.0
All returns an iterator over all elements in the set. The iteration order is not guaranteed and may vary between calls. The iterator can be used with range loops: for v := range set.All() { ... }
func (*Set[T]) Clear ¶ added in v1.0.0
func (s *Set[T]) Clear()
Clear removes all elements from the set, making it empty.
func (*Set[T]) Contains ¶
Contains checks if the given item exists in the set. Returns true if the item is present, false otherwise.
func (*Set[T]) Difference ¶ added in v1.0.0
Difference returns a new set containing elements that are in this set but not in the other set.
func (*Set[T]) Equal ¶ added in v1.0.0
Equal returns true if both sets contain exactly the same elements.
func (*Set[T]) Intersection ¶ added in v1.0.0
Intersection returns a new set containing only elements that exist in both sets.
func (*Set[T]) Remove ¶ added in v1.0.0
func (s *Set[T]) Remove(items ...T)
Remove deletes one or more items from the set. Removing items that don't exist has no effect.