Documentation
¶
Index ¶
- type EqualSet
- type OrderedSet
- func (m *OrderedSet[K, V]) Add(key K, value V)
- func (m OrderedSet[K, V]) Contains(key K) bool
- func (m OrderedSet[K, V]) Entry() iter.Seq2[K, V]
- func (m *OrderedSet[K, V]) ForceAdd(key K, value V)
- func (m OrderedSet[K, V]) Get(key K) (V, bool)
- func (m OrderedSet[K, V]) IsEmpty() bool
- func (m OrderedSet[K, V]) Keys() []K
- func (m OrderedSet[K, V]) Map() map[K]V
- func (m *OrderedSet[K, V]) Remove(key K)
- func (m *OrderedSet[K, V]) Reset()
- func (m OrderedSet[K, V]) Size() int
- type SeenSet
- func (sm SeenSet[T]) Copy() *SeenSet[T]
- func (sm SeenSet[T]) FilterNotSeen(elems []T) []T
- func (sm SeenSet[T]) FilterSeen(elems []T) []T
- func (sm SeenSet[T]) Has(v T) bool
- func (sm SeenSet[T]) IsEmpty() bool
- func (sm *SeenSet[T]) Reset()
- func (sm *SeenSet[T]) See(v T) bool
- func (sm *SeenSet[T]) SetSeen(v T)
- func (sm SeenSet[T]) Size() int
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EqualSet ¶
type EqualSet[T interface { Equals(other T) bool }] struct { // contains filtered or unexported fields }
EqualSet represents a set of elements that implements the Equals method.
Interface: Equals(other T) bool
func NewEqualSet ¶
NewEqualSet creates a new empty set.
Returns:
- *EqualSet[T]: The created set. Never returns nil.
func (*EqualSet[T]) Add ¶
func (s *EqualSet[T]) Add(elem T)
Add adds an element to the set. If the element already exists or the receiver is nil, this function does nothing.
Parameters:
- elem: The element to add.
func (*EqualSet[T]) AddMany ¶
func (s *EqualSet[T]) AddMany(elems []T)
AddMany is the same as Add, but adds many elements at once. More optimized than calling Add multiple times.
Parameters:
- elems: The elements to add.
func (*EqualSet[T]) All ¶
All returns an iterator that iterates over all elements in the set.
Returns:
- iter.Seq[T]: The iterator. Never returns nil.
type OrderedSet ¶
OrderedSet is a set that is ordered by the keys.
func NewOrderedSet ¶
func NewOrderedSet[K cmp.Ordered, V any]() *OrderedSet[K, V]
NewOrderedSet creates a new OrderedSet.
Returns:
- *OrderedSet: A pointer to the newly created OrderedSet. Never returns nil.
func (*OrderedSet[K, V]) Add ¶
func (m *OrderedSet[K, V]) Add(key K, value V)
Add adds a key-value pair to the map. Does nothing if the receiver is nil or the key already exists.
Parameters:
- key: The key to add.
- value: The value to add.
func (OrderedSet[K, V]) Contains ¶
func (m OrderedSet[K, V]) Contains(key K) bool
Contains checks if the key exists in the map.
Parameters:
- key: The key to check.
Returns:
- bool: True if the key exists in the map. False if the key does not exist.
func (OrderedSet[K, V]) Entry ¶
func (m OrderedSet[K, V]) Entry() iter.Seq2[K, V]
Entry returns an iterator that iterates over the entries in the map according to the order of the keys.
Returns:
- iter.Seq2[K, V]: The iterator. Never returns nil.
func (*OrderedSet[K, V]) ForceAdd ¶
func (m *OrderedSet[K, V]) ForceAdd(key K, value V)
ForceAdd is the same as Add, except that it will overwrite the value if the key already exists.
Parameters:
- key: The key to add.
- value: The value to add.
func (OrderedSet[K, V]) Get ¶
func (m OrderedSet[K, V]) Get(key K) (V, bool)
Get returns the value of the key in the map.
Parameters:
- key: The key to get.
Returns:
- V: The value of the key in the map.
- bool: True if the key exists in the map. False if the key does not exist.
func (OrderedSet[K, V]) IsEmpty ¶
func (m OrderedSet[K, V]) IsEmpty() bool
IsEmpty implements the Set interface.
func (OrderedSet[K, V]) Keys ¶
func (m OrderedSet[K, V]) Keys() []K
Keys returns a copy of the keys in the map.
Returns:
- []K: The keys in the map.
func (OrderedSet[K, V]) Map ¶
func (m OrderedSet[K, V]) Map() map[K]V
Map returns a copy of the map of the values in the map.
Returns:
- map[K]V: The map of the values in the map. Nil if there are no keys.
func (*OrderedSet[K, V]) Remove ¶
func (m *OrderedSet[K, V]) Remove(key K)
Remove removes the key from the map. Does nothing if the receiver is nil or the key does not exist.
Parameters:
- key: The key to remove.
func (*OrderedSet[K, V]) Reset ¶
func (m *OrderedSet[K, V]) Reset()
Reset implements the Set interface.
func (OrderedSet[K, V]) Size ¶
func (m OrderedSet[K, V]) Size() int
Size implements the Set interface.
type SeenSet ¶
type SeenSet[T comparable] struct { // contains filtered or unexported fields }
SeenSet is a map that keeps track of seen values.
func NewSeenSet ¶
func NewSeenSet[T comparable]() *SeenSet[T]
NewSeenSet creates a new SeenSet.
Returns:
- *SeenSet[T]: The new SeenSet. Never returns nil.
func (SeenSet[T]) Copy ¶ added in v0.1.1
Copy returns a shallow copy of the receiver.
Returns:
- *SeenSet[T]: The copy. Never returns nil.
func (SeenSet[T]) FilterNotSeen ¶
func (sm SeenSet[T]) FilterNotSeen(elems []T) []T
FilterNotSeen is like FilterSeen but returns the elements that are not seen.
Parameters:
- elems: The elements to filter.
Returns:
- []T: The elements that are not seen.
func (SeenSet[T]) FilterSeen ¶
func (sm SeenSet[T]) FilterSeen(elems []T) []T
FilterSeen returns the elements that are seen. The order of the elements is preserved and no duplicates are contained.
Parameters:
- elems: The elements to filter.
Returns:
- []T: The elements that are seen.
func (SeenSet[T]) Has ¶
Has checks whether the value is seen.
Parameters:
- v: The value to check.
Returns:
- bool: True if the value is seen, false otherwise.
func (*SeenSet[T]) See ¶
See sets the value as seen.
Parameters:
- v: The value to set as seen.
Returns:
- bool: True if the value was set as seen or the receiver was nil. False otherwise.
type Set ¶
type Set interface { // IsEmpty checks whether the set is empty. // // Returns: // - bool: True if the set is empty, false otherwise. IsEmpty() bool // Size returns the number of elements in the set. // // Returns: // - int: The number of elements in the set. Never returns a negative number. Size() int // Reset removes all elements from the set. Reset() }