Documentation ¶
Index ¶
- func CompareOrdered[V constraints.Ordered](a, b V) int
- func DoubleCapacity(before, need int) (after int)
- func EqualOrdered[V constraints.Ordered](a, b V) bool
- func Filter[V any](collection Collection[V], keep PredicateFunc[V])
- func GreaterOrdered[V constraints.Ordered](a, b V) bool
- func LessOrdered[V constraints.Ordered](a, b V) bool
- func Realloc[T any](size int, s []T) []T
- func ReverseCompareOrdered[V constraints.Ordered](a, b V) int
- type CapacityFunc
- type Collection
- type CompareFunc
- type Deque
- type EqualFunc
- type Iterator
- type LessFunc
- type List
- type ListIterator
- type PredicateFunc
- type Queue
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareOrdered ¶
func CompareOrdered[V constraints.Ordered](a, b V) int
CompareOrdered is a CompareFunc which compares two values of any type which implements constraints.Ordered, returning their natural ordering.
a == b: 0 a < b: -1 a > b: +1
func DoubleCapacity ¶
DoubleCapacity returns a capacity double that of the old capacity until it exceeds need, or 1 if the old capacity was 0.
func EqualOrdered ¶
func EqualOrdered[V constraints.Ordered](a, b V) bool
EqualOrdered is an EqualFunc which operates on a type which satisfies the constraints.Ordered interface.
func Filter ¶
func Filter[V any](collection Collection[V], keep PredicateFunc[V])
func GreaterOrdered ¶
func GreaterOrdered[V constraints.Ordered](a, b V) bool
GreaterOrdered is a LessFunc which compares two values of any type which implements constraints.Ordered, returning the inverse of their natural ordering.
b < a
func LessOrdered ¶
func LessOrdered[V constraints.Ordered](a, b V) bool
LessOrdered is a LessFunc which compares two values of any type which implements constraints.Ordered, returning their natural ordering.
a < b
func Realloc ¶
Realloc reallocates a slice with the new size. It can be used to increase or decrease the slice size.
func ReverseCompareOrdered ¶
func ReverseCompareOrdered[V constraints.Ordered](a, b V) int
ReverseCompareOrdered is a CompareFunc which compares two values of any type which implements constraints.Ordered, returning the inverse of their natural ordering.
a == b: 0 a < b: +1 a > b: -1
Types ¶
type CapacityFunc ¶
CapacityFunc is a function used to return a new capacity for a slice when it needs to be increased. It must return an integer equal to or greater than need, otherwise it may cause a panic from the caller.
type Collection ¶
type Collection[V any] interface { Add(value V) bool AddAll(other Collection[V]) bool AddIterator(iter Iterator[V]) bool Clear() Contains(value V) bool ContainsAll(other Collection[V]) bool ContainsIterator(iter Iterator[V]) bool IsEmpty() bool Iterator() Iterator[V] Remove(value V) bool RemoveAll(other Collection[V]) bool RemoveIterator(iter Iterator[V]) bool RetainAll(other Collection[V]) bool Size() int Values() []V }
type CompareFunc ¶
CompareFunc is a function which returns an integer indicating the difference between the first and second value.
n == 0: a == b n < 0: a < b n > 0: a > b
CompareOrdered or ReverseCompareOrdered can be used for any type which implements constraints.Ordered.
func Reverse ¶
func Reverse[V any](cmp CompareFunc[V]) CompareFunc[V]
Reverse reverses a comparison function, effectively reversing the sorting order of the values based on an existing compare function.
type Deque ¶
type Deque[V any] interface { Collection[V] Queue[V] AddFirst(value V) AddLast(value V) GetFirst() V GetLast() V Offer(value V) bool OfferFirst(value V) bool OfferLast(value V) bool Peek() V PeekFirst() V PeekLast() V Poll() V PollFirst() V PollLast() V Pop() V Push(value V) RemoveHead() V RemoveFirst() V RemoveFirstOccurrence(value V) bool RemoveLast() V RemoveLastOccurrence(value V) bool }
type EqualFunc ¶
EqualFunc is a function which returns whether the first value is equal to the second value, using custom behavior.
EqualOrdered can be used for any type which implements constraints.Ordered.
type LessFunc ¶
LessFunc is a function which returns whether the first value is strictly smaller than (not equal to) the second value.
type ListIterator ¶
type PredicateFunc ¶
PredicateFunc is a function which returns a true or false value for a given input, for example a function used to indicate whether a particular value is a prime number.
type Queue ¶
type Queue[V any] interface { Collection[V] Element() V Peek() V Poll() V RemoveHead() V }
type Set ¶
type Set[V any] interface { Collection[V] }