Documentation ¶
Index ¶
- type ComparableSet
- func (s *ComparableSet[T]) Add(elem T)
- func (s *ComparableSet[T]) Clear()
- func (s *ComparableSet[T]) Copy() *ComparableSet[T]
- func (s *ComparableSet[T]) Difference(other *ComparableSet[T]) *ComparableSet[T]
- func (s *ComparableSet[T]) Equals(other *ComparableSet[T]) bool
- func (s *ComparableSet[T]) HasElem(elem T) bool
- func (s *ComparableSet[T]) Intersection(other *ComparableSet[T]) *ComparableSet[T]
- func (s *ComparableSet[T]) IsEmpty() bool
- func (s *ComparableSet[T]) IsSubset(other *ComparableSet[T]) bool
- func (s *ComparableSet[T]) Iterator() uc.Iterater[T]
- func (s *ComparableSet[T]) Remove(elem T)
- func (s *ComparableSet[T]) Size() int
- func (s *ComparableSet[T]) Slice() []T
- func (s *ComparableSet[T]) String() string
- func (s *ComparableSet[T]) SymmetricDifference(other *ComparableSet[T]) *ComparableSet[T]
- func (s *ComparableSet[T]) Union(other *ComparableSet[T]) *ComparableSet[T]
- type LessSet
- func (s *LessSet[T]) Add(elem T)
- func (s *LessSet[T]) Clear()
- func (s *LessSet[T]) Copy() *LessSet[T]
- func (s *LessSet[T]) Difference(other *LessSet[T]) *LessSet[T]
- func (s *LessSet[T]) Equals(other *LessSet[T]) bool
- func (s *LessSet[T]) Find(elem T) (int, bool)
- func (s *LessSet[T]) HasElem(elem T) bool
- func (s *LessSet[T]) Intersection(other *LessSet[T]) *LessSet[T]
- func (s *LessSet[T]) IsEmpty() bool
- func (s *LessSet[T]) IsSubset(other *LessSet[T]) bool
- func (s *LessSet[T]) Iterator() uc.Iterater[T]
- func (s *LessSet[T]) Remove(elem T)
- func (s *LessSet[T]) Size() int
- func (s *LessSet[T]) Slice() []T
- func (s *LessSet[T]) String() string
- func (s *LessSet[T]) SymmetricDifference(other *LessSet[T]) *LessSet[T]
- func (s *LessSet[T]) Union(other *LessSet[T]) *LessSet[T]
- type Seter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ComparableSet ¶
type ComparableSet[T comparable] struct { // contains filtered or unexported fields }
ComparableSet is a set that uses the == operator to compare elements.
func NewComparableSet ¶
func NewComparableSet[T comparable](elems []T) *ComparableSet[T]
NewComparableSet creates a new ComparableSet.
Parameters:
- elems: The elements to add to the set.
Returns:
- *ComparableSet[T]: A new ComparableSet.
Behaviors:
- It ignores duplicate elements.
func (*ComparableSet[T]) Add ¶
func (s *ComparableSet[T]) Add(elem T)
Add adds an element to the set.
Parameters:
- elem: The element to add.
Behaviors:
- If the element is already in the set, the function does nothing.
func (*ComparableSet[T]) Clear ¶
func (s *ComparableSet[T]) Clear()
Clear removes all elements from the set.
func (*ComparableSet[T]) Copy ¶
func (s *ComparableSet[T]) Copy() *ComparableSet[T]
Copy returns a copy of the set.
Returns:
- *ComparableSet[T]: A copy of the set.
func (*ComparableSet[T]) Difference ¶
func (s *ComparableSet[T]) Difference(other *ComparableSet[T]) *ComparableSet[T]
Difference returns the difference of the set with another set.
Parameters:
- other: The other set.
Returns:
- *ComparableSet[T]: The difference of the set with the other set.
func (*ComparableSet[T]) Equals ¶
func (s *ComparableSet[T]) Equals(other *ComparableSet[T]) bool
Equals checks if the set is equal to another set.
Parameters:
- other: The other set to compare.
Returns:
- bool: True if the sets are equal, false otherwise.
func (*ComparableSet[T]) HasElem ¶
func (s *ComparableSet[T]) HasElem(elem T) bool
HasElem checks if the set has the element.
Parameters:
- elem: The element to check.
Returns:
- bool: True if the set has the element, false otherwise.
func (*ComparableSet[T]) Intersection ¶
func (s *ComparableSet[T]) Intersection(other *ComparableSet[T]) *ComparableSet[T]
Intersection returns the intersection of the set with another set.
Parameters:
- other: The other set.
Returns:
- *ComparableSet[T]: The intersection of the set with the other set.
func (*ComparableSet[T]) IsEmpty ¶
func (s *ComparableSet[T]) IsEmpty() bool
IsEmpty checks if the set is empty.
Returns:
- bool: True if the set is empty, false otherwise.
func (*ComparableSet[T]) IsSubset ¶
func (s *ComparableSet[T]) IsSubset(other *ComparableSet[T]) bool
IsSubset checks if the set is a subset of another set.
Parameters:
- other: The other set to check.
Returns:
- bool: True if the set is a subset of the other set, false otherwise.
func (*ComparableSet[T]) Iterator ¶
func (s *ComparableSet[T]) Iterator() uc.Iterater[T]
Iterator returns an iterator for the set.
Returns:
- uc.Iterater[T]: An iterator for the set.
func (*ComparableSet[T]) Remove ¶
func (s *ComparableSet[T]) Remove(elem T)
Remove removes an element from the set.
Parameters:
- elem: The element to remove.
Behaviors:
- If the element is not in the set, the function does nothing.
func (*ComparableSet[T]) Size ¶
func (s *ComparableSet[T]) Size() int
Size returns the number of elements in the set.
Returns:
- int: The number of elements in the set.
func (*ComparableSet[T]) Slice ¶
func (s *ComparableSet[T]) Slice() []T
Slice returns a slice of the elements in the set.
Returns:
- []T: A slice of the elements in the set.
func (*ComparableSet[T]) String ¶
func (s *ComparableSet[T]) String() string
String returns a string representation of the set.
Returns:
- string: The string representation of the set.
func (*ComparableSet[T]) SymmetricDifference ¶
func (s *ComparableSet[T]) SymmetricDifference(other *ComparableSet[T]) *ComparableSet[T]
SymmetricDifference returns the symmetric difference of the set with another set.
Parameters:
- other: The other set.
Returns:
- *ComparableSet[T]: The symmetric difference of the set with the other set.
func (*ComparableSet[T]) Union ¶
func (s *ComparableSet[T]) Union(other *ComparableSet[T]) *ComparableSet[T]
Union returns the union of the set with another set.
Parameters:
- other: The other set.
Returns:
- *ComparableSet[T]: The union of the set with the other set.
type LessSet ¶
type LessSet[T any] struct { // contains filtered or unexported fields }
LessSet is a set that uses the Equals method to compare elements.
func NewLessSet ¶
NewLessSet creates a new LessSet.
Parameters:
- elems: The elements to add to the set.
- sf: The sort function to use.
Returns:
- *LessSet: A new LessSet.
Behaviors:
- If the sort function is nil, the function returns nil.
func (*LessSet[T]) Add ¶
func (s *LessSet[T]) Add(elem T)
Add adds an element to the set.
Parameters:
- elem: The element to add.
Behaviors:
- If the element is already in the set, the function does nothing.
func (*LessSet[T]) Difference ¶
Difference returns the difference of the set with another set.
Parameters:
- other: The other set.
Returns:
- *LessSet[T]: The difference of the set with the other set.
func (*LessSet[T]) Equals ¶
Equals checks if the set is equal to another set.
Parameters:
- other: The other set to compare.
Returns:
- bool: True if the sets are equal, false otherwise.
func (*LessSet[T]) Find ¶
Find finds an element in the set.
Parameters:
- elem: The element to find.
Returns:
- int: The index of the element in the set.
- bool: True if the element is in the set, false otherwise.
func (*LessSet[T]) HasElem ¶
HasElem checks if the set has the element.
Parameters:
- elem: The element to check.
Returns:
- bool: True if the set has the element, false otherwise.
func (*LessSet[T]) Intersection ¶
Intersection returns the intersection of the set with another set.
Parameters:
- other: The other set.
Returns:
- *LessSet[T]: The intersection of the set with the other set.
func (*LessSet[T]) IsEmpty ¶
IsEmpty checks if the set is empty.
Returns:
- bool: True if the set is empty, false otherwise.
func (*LessSet[T]) IsSubset ¶
IsSubset checks if the set is a subset of another set.
Parameters:
- other: The other set to check.
Returns:
- bool: True if the set is a subset of the other set, false otherwise.
func (*LessSet[T]) Iterator ¶
Iterator returns an iterator for the set.
Returns:
- uc.Iterater[T]: An iterator for the set.
func (*LessSet[T]) Remove ¶
func (s *LessSet[T]) Remove(elem T)
Remove removes an element from the set.
Parameters:
- elem: The element to remove.
Behaviors:
- If the element is not in the set, the function does nothing.
func (*LessSet[T]) Size ¶
Size returns the number of elements in the set.
Returns:
- int: The number of elements in the set.
func (*LessSet[T]) Slice ¶
func (s *LessSet[T]) Slice() []T
Slice returns a slice of the elements in the set.
Returns:
- []T: A slice of the elements in the set.
func (*LessSet[T]) String ¶
String returns a string representation of the set.
Returns:
- string: The string representation of the set.
func (*LessSet[T]) SymmetricDifference ¶
SymmetricDifference returns the symmetric difference of the set with another set.
Parameters:
- other: The other set.
Returns:
- *LessSet[T]: The symmetric difference of the set with the other set.
type Seter ¶
type Seter[T any] interface { // IsEmpty checks if 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. Size() int // HasElem checks if the set has the element. // // Parameters: // - elem: The element to check. // // Returns: // - bool: True if the set has the element, false otherwise. HasElem(elem T) bool // Add adds an element to the set. // // Parameters: // - elem: The element to add. // // Behaviors: // - If the element is already in the set, the function does nothing. Add(elem T) // Remove removes an element from the set. // // Parameters: // - elem: The element to remove. // // Behaviors: // - If the element is not in the set, the function does nothing. Remove(elem T) // Union returns the union of the set with another set. // // Parameters: // - other: The other set. // // Returns: // - Seter[T]: The union of the set with the other set. Union(other Seter[T]) Seter[T] // Intersection returns the intersection of the set with another set. // // Parameters: // - other: The other set. // // Returns: // - Seter[T]: The intersection of the set with the other set. Intersection(other Seter[T]) Seter[T] // Difference returns the difference of the set with another set. // // Parameters: // - other: The other set. // // Returns: // - Seter[T]: The difference of the set with the other set. Difference(other Seter[T]) Seter[T] // SymmetricDifference returns the symmetric difference of the set with another set. // // Parameters: // - other: The other set. // // Returns: // - Seter[T]: The symmetric difference of the set with the other set. SymmetricDifference(other Seter[T]) Seter[T] // IsSubset checks if the set is a subset of another set. // // Parameters: // - other: The other set. // // Returns: // - bool: True if the set is a subset of the other set, false otherwise. IsSubset(other Seter[T]) bool // Clear removes all elements from the set. Clear() fmt.Stringer Slice() []T uc.Iterable[T] }
Seter is an interface for a set.