Documentation
¶
Index ¶
- func DeleteElem[T cmp.Ordered](slice []T, elem T) []T
- func Max[T cmp.Ordered](a, b T) T
- func MaxVar[T cmp.Ordered](elems []T) (T, bool)
- func Maxs[T cmp.Ordered](elems []T) []int
- func Min[T cmp.Ordered](a, b T) T
- func MinVar[T cmp.Ordered](elems []T) (T, bool)
- func Mins[T cmp.Ordered](elems []T) []int
- func Uniquefy[T cmp.Ordered](S []T, prioritizeFirst bool) []T
- type Set
- func (s *Set[T]) Add(elem T) bool
- func (s Set[T]) All() iter.Seq[T]
- func (s Set[T]) Contains(elem T) bool
- func (s Set[T]) Equals(other *Set[T]) bool
- func (s Set[T]) IsEmpty() bool
- func (s Set[T]) Len() int
- func (s Set[T]) Slice() []T
- func (s Set[T]) String() string
- func (s *Set[T]) Union(other *Set[T]) int
- type SetElem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteElem ¶ added in v0.1.6
DeleteElem deletes an element from a slice and returns the new slice. If the element is not found, the slice is returned unchanged.
Parameters:
- slice: The slice to delete the element from.
- elem: The element to delete.
Returns:
- []T: The new slice with the element deleted.
func Max ¶
Max returns the maximum of a and b.
Parameters:
- a: The first value.
- b: The second value.
Returns:
- T: The maximum value.
func MaxVar ¶
MaxVar returns the maximum of the elements in the slice.
Parameters:
- elems: The elements.
Returns:
- T: The maximum value.
- bool: Whether the operation was successful.
func Maxs ¶
Maxs returns the maximums of the elements in the slice.
Parameters:
- elems: The elements.
Returns:
- []int: The indices of the maximum values.
func Min ¶
Min returns the minimum of a and b.
Parameters:
- a: The first value.
- b: The second value.
Returns:
- T: The minimum value.
func MinVar ¶
MinVar returns the minimum of the elements in the slice.
Parameters:
- elems: The elements.
Returns:
- T: The minimum value.
- bool: Whether the operation was successful.
func Mins ¶
Mins returns the minimums of the elements in the slice.
Parameters:
- elems: The elements.
Returns:
- []int: The indices of the minimum values.
func Uniquefy ¶ added in v0.1.11
Uniquefy removes duplicate elements from the slice.
Parameters:
- S: slice of elements.
- prioritizeFirst: If true, the first occurrence of an element is kept. If false, the last occurrence of an element is kept.
Returns:
- []T: slice of elements with duplicates removed.
Behavior:
- The function preserves the order of the elements in the slice.
Types ¶
type Set ¶ added in v0.1.11
type Set[T SetElem] struct { // contains filtered or unexported fields }
Set represents a set of elements.
func NewSet ¶ added in v0.1.11
NewSet creates a new Set.
Returns:
- *Set[T]: The created Set. Never returns nil.
func NewSetFromSlice ¶ added in v0.1.11
NewSetFromSlice creates a new Set from a slice of elements.
Parameters:
- elems: The slice of elements.
Returns:
- *Set[T]: The created Set. Never returns nil.
func (*Set[T]) Add ¶ added in v0.1.11
Add adds an element to the set. If the element is already in the set, this method does nothing.
Parameters:
- elem: The element to add.
Returns:
- bool: True if the element was added to the set, false otherwise.
if the receiver is nil, this method returns false.
func (Set[T]) All ¶ added in v0.1.11
All returns an iterator over all elements in the set.
Returns:
- iter.Seq[T]: An iterator over all elements in the set.
func (Set[T]) Contains ¶ added in v0.1.11
Contains checks whether the set contains the given element.
Parameters:
- elem: The element to check for.
Returns:
- bool: True if the set contains the element, false otherwise.
func (Set[T]) Equals ¶ added in v0.1.11
Equals checks whether the set is equal to another set. Two Sets are said to be equal if the intersection of their elements is non-empty.
Parameters:
- other: The other set to compare with.
Returns:
- bool: True if the sets are equal, false otherwise.
If 'others' is nil, this method returns false.
func (Set[T]) IsEmpty ¶ added in v0.1.11
IsEmpty checks whether the set is empty.
Returns:
- bool: True if the set is empty, false otherwise.
func (Set[T]) Len ¶ added in v0.1.11
Len returns the number of elements in the set.
Returns:
- int: The number of elements in the set.
func (Set[T]) Slice ¶ added in v0.1.11
func (s Set[T]) Slice() []T
Slice returns the slice of elements in the set.
Returns:
- []T: The slice of elements in the set.