Documentation ¶
Overview ¶
Example ¶
bus := NewPubSub[greetingMessage](DefaultPublishChannelBufferSize) // the topic with a type which you want to publish and subscribe. ctx, cancel := context.WithCancel(context.Background()) done := make(chan struct{}) go func() { if err := bus.Start(ctx); err != nil { // Start the topic. This call of Start blocks until the context is canceled. println(err) return } done <- struct{}{} }() if err := bus.Dispatch(greetingMessage{greeting: "Hello, Badu!"}); err != nil { // Dispatch a message to the topic. This call of Dispatch is non-blocking. println(err) return } // Listen the topic. This call of Listen is non-blocking. err := bus.Listen(DefaultSubscribeChannelBufferSize, func(message greetingMessage) { println(message.greeting) }) if err != nil { println(err) return } cancel() <-done
Output:
Index ¶
- Constants
- Variables
- func Common[T comparable](source1 []T, source2 []T) []T
- func Count[T comparable](source []T, value T) (count int)
- func CountWhere[T any](source []T, fn func(T) bool) (count int)
- func DelayedInvoke(times int, delay time.Duration, fn func(int, time.Duration) error) (int, time.Duration, error)
- func Diff[T comparable](source1 []T, source2 []T) ([]T, []T)
- func Drop[T any](source []T, n int) []T
- func DropRight[T any](source []T, n int) []T
- func DropRightWhile[T any](source []T, fn func(T) bool) []T
- func DropWhile[T any](source []T, fn func(T) bool) []T
- func Fill[T Clonable[T]](source []T, defaults T) []T
- func Filter[V any](source []V, fn func(V, int) bool) []V
- func FilterMap[K comparable, V any](source map[K]V, fn func(K, V) bool) map[K]V
- func FilterWhereKeys[K comparable, V any](source map[K]V, keys []K) map[K]V
- func FilterWhereValues[K comparable, V comparable](source map[K]V, values []V) map[K]V
- func Find[T comparable](source []*T, fn func(*T) bool) (*T, bool)
- func FindString[T comparable](source []T, fn func(T) bool) (T, bool)
- func FirstIndexOf[T comparable](source []*T, el T) int
- func FlatMap[T, R any](source []T, fn func(T, int) []R) []R
- func Flatten[T any](source [][]T) []T
- func FromEntries[K comparable, V any](source []Entry[K, V]) map[K]V
- func GroupWhere[T any, U comparable](source []T, fn func(T) U) map[U][]T
- func Has[T comparable](slice []T, element T) bool
- func HasWhere[T any](slice []T, fn func(T) bool) bool
- func Hash[T comparable](value T) uint32
- func HashBytes(b []byte) uint32
- func Included[T comparable](slice []T, other []T) bool
- func IncludedWhere[V any](slice []V, fn func(V) bool) bool
- func IncludesOne[T comparable](slice []T, other []T) bool
- func IncludesOneWhere[V any](slice []V, fn func(V) bool) bool
- func Indexes[T comparable](source []*T, el T) []int
- func Invoke(times int, fn func(int) error) (int, error)
- func KeyWhere[K comparable, V any](source []V, fn func(V) K) map[K]V
- func Keys[K comparable, V any](source map[K]V) []K
- func LastIndexOf[T comparable](source []*T, el T) int
- func Map[T, R any](source []T, fn func(T, int) R) []R
- func MapKeys[K comparable, V any, R comparable](source map[K]V, fn func(V, K) R) map[R]V
- func MapValues[K comparable, V any, R any](source map[K]V, fn func(V, K) R) map[K]R
- func MapWhere[T, R any](source []T, fn func(T, int) (R, bool)) []R
- func Max[T constraints.Ordered](source []T) T
- func MaxWhere[T any](source []T, fn func(T, T) bool) T
- func Merge[K comparable, V any](sources ...map[K]V) map[K]V
- func Min[T constraints.Ordered](source []T) T
- func MinWhere[T any](source []T, fn func(T, T) bool) T
- func NewDebounce(delay time.Duration, fns ...func()) (func(), func())
- func NotIncludes[V comparable](slice []V, subset []V) bool
- func NotIncludesWhere[V any](slice []V, fn func(V) bool) bool
- func NumericFirstIndexOf[T comparable](source []T, el T) int
- func NumericIndexes[T comparable](source []T, el T) []int
- func NumericLastIndexOf[T comparable](source []T, el T) int
- func ParallelDo[T any](count int, fn func(int) T) []T
- func ParallelForEach[T any](slice []T, fn func(T, int))
- func ParallelGroupWhere[T any, U comparable](slice []T, fn func(T) U) map[U][]T
- func ParallelMap[T any, R any](collection []T, iteratee func(T, int) R) []R
- func ParallelPartitionWhere[T any, K comparable](slice []T, fn func(x T) K) [][]T
- func Partition[T any](source []T, size int) ([][]T, error)
- func PartitionWhere[T any, K comparable](source []T, fn func(x T) K) [][]T
- func Permutations[T any](source []T) ([][]T, error)
- func Produce[T any](count int, fn func(int) T) []T
- func Reduce[T comparable, R any](source []T, fn func(R, T, int) R, result R) R
- func Reject[V any](source []V, fn func(V, int) bool) []V
- func Repeat[T Clonable[T]](count int, initial T) []T
- func RepeatWhere[T any](count int, fn func(int) T) []T
- func Replace[T comparable](source []T, old T, new T, n int) []T
- func ReplaceAll[T comparable](source []T, old T, new T) []T
- func Reverse[T any](source []T) []T
- func Shuffle[T any](source []T) []T
- func Subset[T any](source []T, offset int, length uint) []T
- func SwapKeyValue[K comparable, V comparable](source map[K]V) map[V]K
- func Union[T comparable](source1, source2 []T) []T
- func Unique[T comparable](source []T) []T
- func UniqueWhere[T any, U comparable](source []T, fn func(T) U) []T
- func Value[T any](ctx context.Context) (T, bool)
- func Values[K comparable, V any](source map[K]V) []V
- func Wait(ws ...Waiter) error
- func WhereElse[T any](source []T, fallback T, fn func(T) bool) *T
- func WhereFirst[T any](source []T, fn func(T) bool) (T, int, bool)
- func WhereLast[T any](source []T, fn func(T) bool) (*T, int, bool)
- func WithValue[T any](ctx context.Context, value T) context.Context
- type BinaryHeap
- func (b *BinaryHeap[T]) Clear()
- func (b *BinaryHeap[T]) Count() int
- func (b *BinaryHeap[T]) Empty() bool
- func (b *BinaryHeap[T]) ForEach(predicate func(val T))
- func (b *BinaryHeap[T]) Has(val T) bool
- func (b *BinaryHeap[T]) Peek() T
- func (b *BinaryHeap[T]) Pop() *T
- func (b *BinaryHeap[T]) Push(val T)
- type Cache
- func (c Cache) CleanExpired()
- func (c Cache) Delete(key string)
- func (c Cache) Flush()
- func (c Cache) GetWithExpiration(key string) (T, time.Time, bool)
- func (c Cache) Load(r io.Reader) error
- func (c Cache) LoadFile(filename string) error
- func (c Cache) Objects() map[string]CacheObject[T]
- func (c Cache) ObjectsCount() int
- func (c Cache) OnBeforeDeletion(hook func(string, T))
- func (c Cache) Read(key string) (T, bool)
- func (c Cache) Replace(key string, object T, d time.Duration) error
- func (c Cache) Save(w io.Writer) error
- func (c Cache) SaveFile(filename string) error
- func (c Cache) Set(key string, object T, defaultExpiration time.Duration)
- func (c Cache) SetWithDefault(key string, object T)
- func (c Cache) Store(key string, object T, d time.Duration) error
- type CacheObject
- type Clonable
- type Entry
- type HashMap
- func (m *HashMap[K, V]) Clear()
- func (m *HashMap[K, V]) ContainsKey(key K) bool
- func (m *HashMap[K, V]) ContainsValue(val V) bool
- func (m *HashMap[K, V]) Count() int
- func (m *HashMap[K, V]) Empty() bool
- func (m *HashMap[K, V]) ForEach(f func(key K, val V))
- func (m *HashMap[K, V]) Get(key K) (val V, ok bool)
- func (m *HashMap[K, V]) Put(key K, val V)
- func (m *HashMap[K, V]) Remove(key K)
- type Hasher
- type KV
- type LinkedList
- func (l *LinkedList[T]) AddAt(value T, index int) error
- func (l *LinkedList[T]) Bottom() *T
- func (l *LinkedList[T]) Clear()
- func (l *LinkedList[T]) Count() int
- func (l *LinkedList[T]) Empty() bool
- func (l *LinkedList[T]) ForEach(f func(i int, val T))
- func (l *LinkedList[T]) Get(index int) *T
- func (l *LinkedList[T]) Has(value T) bool
- func (l *LinkedList[T]) PopBottom()
- func (l *LinkedList[T]) PopTop()
- func (l *LinkedList[T]) PutOnBottom(val T)
- func (l *LinkedList[T]) PutOnTop(value T)
- func (l *LinkedList[T]) Remove(index int)
- func (l *LinkedList[T]) Top() *T
- func (l *LinkedList[T]) Update(index int, val T)
- type Promise
- type Promising
- type Queue
- type SortedMap
- type Stack
- type StringKeyOrderedMap
- func (m *StringKeyOrderedMap[V]) Append(newOm *StringKeyOrderedMap[V], overwrite bool) *StringKeyOrderedMap[V]
- func (m *StringKeyOrderedMap[V]) Delete(key string)
- func (m *StringKeyOrderedMap[V]) Exists(key string) bool
- func (m *StringKeyOrderedMap[V]) Get(key string) V
- func (m *StringKeyOrderedMap[V]) GetKeys() []string
- func (m *StringKeyOrderedMap[V]) GetList() []KV[V]
- func (m *StringKeyOrderedMap[V]) Len() int
- func (m *StringKeyOrderedMap[V]) MarshalJSON() ([]byte, error)
- func (m *StringKeyOrderedMap[V]) Set(key string, value V) *StringKeyOrderedMap[V]
- func (m *StringKeyOrderedMap[V]) String() string
- type Topiq
- type Waiter
Examples ¶
Constants ¶
const ( NeverExpire time.Duration = -1 DefaultExpire time.Duration = 0 )
const ( DefaultPublishChannelBufferSize = 100 DefaultSubscribeChannelBufferSize = 100 )
Variables ¶
var ( ErrAlreadyStarted = errors.New("this topic has been already started") ErrNotRunning = errors.New("this topic has been already closed") )
var ErrNotDone = errors.New("not done")
Functions ¶
func Common ¶
func Common[T comparable](source1 []T, source2 []T) []T
Common returns the intersection between two slices.
func Count ¶
func Count[T comparable](source []T, value T) (count int)
Count counts the number of elements in the slice that compare equal to value.
func CountWhere ¶
CountWhere counts the number of elements in the slice for which callback is true.
func DelayedInvoke ¶
func DelayedInvoke(times int, delay time.Duration, fn func(int, time.Duration) error) (int, time.Duration, error)
DelayedInvoke invokes a function N times until it returns valid output, with a pause between each call. Returning either the caught error or nil. When first argument is less than `1`, the function runs until a successful response is returned.
func Diff ¶
func Diff[T comparable](source1 []T, source2 []T) ([]T, []T)
Diff returns the difference between two slices. The first return is the slice of elements absent of source1. The second return is the slice of elements absent of source2.
func DropRightWhile ¶
DropRightWhile drops elements from the end of a slice or slice while the callback returns true.
func DropWhile ¶
DropWhile drops elements from the beginning of a slice or slice while the callback returns true.
func Fill ¶
func Fill[T Clonable[T]](source []T, defaults T) []T
Fill fills elements of slice with `defaults` values.
func Filter ¶
Filter iterates over elements of slice, returning a slice of all elements callback returns truthy for.
func FilterMap ¶
func FilterMap[K comparable, V any](source map[K]V, fn func(K, V) bool) map[K]V
FilterMap returns same map type filtered by given callback.
func FilterWhereKeys ¶
func FilterWhereKeys[K comparable, V any](source map[K]V, keys []K) map[K]V
FilterWhereKeys returns same map type filtered by given keys.
func FilterWhereValues ¶
func FilterWhereValues[K comparable, V comparable](source map[K]V, values []V) map[K]V
FilterWhereValues returns same map type filtered by given values.
func Find ¶
func Find[T comparable](source []*T, fn func(*T) bool) (*T, bool)
Find search an element in a slice based on a callback. It returns element and true if element was found.
func FindString ¶
func FindString[T comparable](source []T, fn func(T) bool) (T, bool)
FindString search an element in a slice based on a callback. It returns element and true if element was found.
func FirstIndexOf ¶
func FirstIndexOf[T comparable](source []*T, el T) int
FirstIndexOf returns the index at which the first occurrence of a value is found in a slice or return -1 if the value cannot be found.
func FromEntries ¶
func FromEntries[K comparable, V any](source []Entry[K, V]) map[K]V
FromEntries transforms an array of key/value pairs into a map.
func GroupWhere ¶
func GroupWhere[T any, U comparable](source []T, fn func(T) U) map[U][]T
GroupWhere returns an object composed of keys generated from the results of running each element of slice.
func Has ¶
func Has[T comparable](slice []T, element T) bool
Has returns true if an element is present in a slice.
func Hash ¶
func Hash[T comparable](value T) uint32
Hash returns a 32 bit unsigned integer hash for any value passed in
func Included ¶
func Included[T comparable](slice []T, other []T) bool
Included returns true if all elements of a subset are contained into a slice or if the subset is empty.
func IncludedWhere ¶
IncludedWhere returns true if the callback returns true for all of the elements in the slice or if the slice is empty.
func IncludesOne ¶
func IncludesOne[T comparable](slice []T, other []T) bool
IncludesOne returns true if at least 1 element of a subset is contained into a slice.
func IncludesOneWhere ¶
IncludesOneWhere returns true if the callback returns true for any of the elements in the slice.
func Indexes ¶
func Indexes[T comparable](source []*T, el T) []int
Indexes returns the indexes at which the last occurrence of a value is found in a slice
func Invoke ¶
Invoke invokes a function N times until it returns valid output. Returning either the caught error or nil. When first argument is less than `1`, the function runs until a successful response is returned.
func KeyWhere ¶
func KeyWhere[K comparable, V any](source []V, fn func(V) K) map[K]V
KeyWhere transforms a slice or a slice of structs to a map based on a pivot callback.
func Keys ¶
func Keys[K comparable, V any](source map[K]V) []K
Keys creates an array of the map keys.
func LastIndexOf ¶
func LastIndexOf[T comparable](source []*T, el T) int
LastIndexOf returns the index at which the last occurrence of a value is found in a slice or return -1 if the value cannot be found.
func MapKeys ¶
func MapKeys[K comparable, V any, R comparable](source map[K]V, fn func(V, K) R) map[R]V
MapKeys manipulates a map keys and transforms it to a map of another type.
func MapValues ¶
func MapValues[K comparable, V any, R any](source map[K]V, fn func(V, K) R) map[K]R
MapValues manipulates a map values and transforms it to a map of another type.
func MapWhere ¶
MapWhere returns a slice which obtained after both filtering and mapping using the given callback function.
func MaxWhere ¶
MaxWhere search the maximum value of a slice using the given comparison function. If several values of the slice are equal to the greatest value, returns the first such value.
func Merge ¶
func Merge[K comparable, V any](sources ...map[K]V) map[K]V
Merge merges multiple maps from left to right.
func MinWhere ¶
MinWhere search the minimum value of a slice using the given comparison function. If several values of the slice are equal to the smallest value, returns the first such value.
func NewDebounce ¶
NewDebounce creates a debounced instance that delays invoking functions given until after wait milliseconds have elapsed.
func NotIncludes ¶
func NotIncludes[V comparable](slice []V, subset []V) bool
NotIncludes returns true if no element of a subset are contained into a slice or if the subset is empty.
func NotIncludesWhere ¶
NotIncludesWhere returns true if the callback returns true for none of the elements in the slice or if the slice is empty.
func NumericFirstIndexOf ¶
func NumericFirstIndexOf[T comparable](source []T, el T) int
NumericFirstIndexOf returns the index at which the first occurrence of a value is found in a slice or return -1 if the value cannot be found.
func NumericIndexes ¶
func NumericIndexes[T comparable](source []T, el T) []int
NumericIndexes returns the indexes at which the last occurrence of a value is found in a slice
func NumericLastIndexOf ¶
func NumericLastIndexOf[T comparable](source []T, el T) int
NumericLastIndexOf returns the index at which the last occurrence of a value is found in a slice or return -1 if the value cannot be found.
func ParallelDo ¶
ParallelDo invokes the callback n times, returning a slice of the results of each invocation.
func ParallelForEach ¶
ParallelForEach iterates over elements of slice and invokes callback for each element.
func ParallelGroupWhere ¶
func ParallelGroupWhere[T any, U comparable](slice []T, fn func(T) U) map[U][]T
ParallelGroupWhere returns an object composed of keys generated from the results of running each element of slice through callback.
func ParallelMap ¶
ParallelMap manipulates a slice and transforms it to a slice of another type. `iteratee` is call in parallel. Resolve keep the same order.
func ParallelPartitionWhere ¶
func ParallelPartitionWhere[T any, K comparable](slice []T, fn func(x T) K) [][]T
ParallelPartitionWhere returns a slice of elements split into groups. The order of grouped values is determined by the order they occur in slice. The grouping is generated from the results of running each element of slice through callback. `callback` is call in parallel.
func Partition ¶
Partition returns a slice of elements split into groups the length of size. If slice can't be split evenly, the final chunk will be the remaining elements.
func PartitionWhere ¶
func PartitionWhere[T any, K comparable](source []T, fn func(x T) K) [][]T
PartitionWhere returns a slice of elements split into groups. The order of grouped values is determined by the order they occur in slice. The grouping is generated from the results of running each element of slice through callback.
func Permutations ¶
Permutations returns all permutations of the slice's elements.
func Produce ¶
Produce invokes the callback n times, returning a slice of the results of each invocation.
func Reduce ¶
func Reduce[T comparable, R any](source []T, fn func(R, T, int) R, result R) R
Reduce reduces slice to a value which is the accumulated result of running each element in slice through a function, where each successive invocation is supplied the return value of the previous.
func Reject ¶
Reject is the opposite of Filter, this method returns the elements of slice that callback does not return truthy for.
func RepeatWhere ¶
RepeatWhere builds a slice with values returned by N calls of callback.
func Replace ¶
func Replace[T comparable](source []T, old T, new T, n int) []T
Replace returns a copy of the slice with the first n non-overlapping instances of old replaced by new.
func ReplaceAll ¶
func ReplaceAll[T comparable](source []T, old T, new T) []T
ReplaceAll returns a copy of the slice with all non-overlapping instances of old replaced by new.
func Reverse ¶
func Reverse[T any](source []T) []T
Reverse reverses slice so that the first element becomes the last, the second element becomes the second to last, and so on.
func Shuffle ¶
func Shuffle[T any](source []T) []T
Shuffle returns a slice of shuffled values. Uses the Fisher-Yates shuffle algorithm.
func SwapKeyValue ¶
func SwapKeyValue[K comparable, V comparable](source map[K]V) map[V]K
SwapKeyValue creates a map composed of the inverted keys and values. If map contains duplicate values, of course, subsequent values will overwrite property assignments of previous values.
func Union ¶
func Union[T comparable](source1, source2 []T) []T
Union returns all distinct elements from both slices. Resolve DOES NOT change the order of elements relatively.
func Unique ¶
func Unique[T comparable](source []T) []T
Unique returns a duplicate-free version of a slice, in which only the first occurrence of each element is kept, while preserving the order in which they occur in the slice.
func UniqueWhere ¶
func UniqueWhere[T any, U comparable](source []T, fn func(T) U) []T
UniqueWhere returns a duplicate-free version of a slice, in which only the FIRST occurrence of each element is kept, while preserving the order in which they occur in the slice.
func Values ¶
func Values[K comparable, V any](source map[K]V) []V
Values creates an array of the map values.
func WhereElse ¶
WhereElse search an element in a slice based on a callback. It returns the element if found or a given fallback value otherwise.
func WhereFirst ¶
WhereFirst searches an element in a slice based on a callback and returns the index and true. It returns -1 and false if the element is not found.
Types ¶
type BinaryHeap ¶
type BinaryHeap[T comparable] struct { // contains filtered or unexported fields }
BinaryHeap is the main heap type.
func NewBinaryHeap ¶
func NewBinaryHeap[T comparable](predicate func(a, b T) bool, capacity ...int) BinaryHeap[T]
NewBinaryHeap is used to create a new heap. The passed function is a predicate that returns true if the first parameter is greater than the second. This predicate defines the sorting order between the heap items and is called during insertion and extraction.
func (*BinaryHeap[T]) Count ¶
func (b *BinaryHeap[T]) Count() int
Count returns the amount of entries in the heap.
func (*BinaryHeap[T]) Empty ¶
func (b *BinaryHeap[T]) Empty() bool
Empty returns true if the heap is empty, false if not.
func (*BinaryHeap[T]) ForEach ¶
func (b *BinaryHeap[T]) ForEach(predicate func(val T))
ForEach iterates over the dataset within the heap, calling the passed function for each value.
func (*BinaryHeap[T]) Has ¶
func (b *BinaryHeap[T]) Has(val T) bool
Has returns true if the value exists in the heap, false if not.
func (*BinaryHeap[T]) Peek ¶
func (b *BinaryHeap[T]) Peek() T
Peek returns the first value at the top of the heap.
func (*BinaryHeap[T]) Pop ¶
func (b *BinaryHeap[T]) Pop() *T
Pop returns and removes the first value from the heap.
func (*BinaryHeap[T]) Push ¶
func (b *BinaryHeap[T]) Push(val T)
Push inserts a new value into the heap.
type Cache ¶
type Cache[T any] struct { // contains filtered or unexported fields }
func NewCacheFrom ¶
func (Cache) CleanExpired ¶
func (c Cache) CleanExpired()
CleanExpired all expired objects from the cache.
func (Cache) Delete ¶
func (c Cache) Delete(key string)
Delete an object from the cache. Does nothing if the key is not in the cache.
func (Cache) GetWithExpiration ¶
GetWithExpiration returns an object and its expiration time from the cache. It returns the object or nil, the expiration time if one is set (if the object never expires a zero value for time.Time is returned), and a bool indicating whether the key was found.
func (Cache) Objects ¶
func (c Cache) Objects() map[string]CacheObject[T]
Objects lists all objects in the cache
func (Cache) ObjectsCount ¶
func (c Cache) ObjectsCount() int
ObjectsCount returns the number of cached objects
func (Cache) OnBeforeDeletion ¶
func (c Cache) OnBeforeDeletion(hook func(string, T))
OnBeforeDeletion registers a function to be called before eviction
func (Cache) Read ¶
Read an object from the cache. Returns the item or nil, and a bool indicating whether the key was found.
func (Cache) Replace ¶
Replace a new value for the cache key only if it already exists, and the existing object hasn't expired. Returns an error otherwise.
func (Cache) SetWithDefault ¶
func (c Cache) SetWithDefault(key string, object T)
SetWithDefault adds an object to the cache, replacing any existing item, using the default expiration value.
type CacheObject ¶
func (*CacheObject[T]) Expired ¶
func (item *CacheObject[T]) Expired() bool
type Clonable ¶
type Clonable[T any] interface { Clone() T }
Clonable defines a constraint of types having Clone() T method.
type Entry ¶
type Entry[K comparable, V any] struct { Key K Value V }
Entry defines a key/value pairs.
func ToEntries ¶
func ToEntries[K comparable, V any](source map[K]V) []Entry[K, V]
ToEntries transforms a map into array of key/value pairs.
type HashMap ¶
type HashMap[K, V comparable] struct { // contains filtered or unexported fields }
HashMap is the main hash map type.
func NewHashMap ¶
func NewHashMap[K, V comparable]() HashMap[K, V]
NewHashMap is used to create a new map.
func (*HashMap[K, V]) ContainsKey ¶
ContainsKey returns true if the passed key is present, false if not.
func (*HashMap[K, V]) ContainsValue ¶
ContainsValue returns true if the passed value is present, false if not.
func (*HashMap[K, V]) ForEach ¶
func (m *HashMap[K, V]) ForEach(f func(key K, val V))
ForEach iterates over the dataset within the hash map, calling the passed function for each value.
type Hasher ¶
type Hasher interface {
Hash() uint32
}
Hasher is an interface primarily for structs to provide a hash of their contents
type KV ¶
func (KV[V]) MarshalJSON ¶
type LinkedList ¶
type LinkedList[T comparable] struct { // contains filtered or unexported fields }
LinkedList is the main linked list type.
func NewLinkedList ¶
func NewLinkedList[T comparable]() LinkedList[T]
NewLinkedList is used to create a new linked list.
func (*LinkedList[T]) AddAt ¶
func (l *LinkedList[T]) AddAt(value T, index int) error
AddAt inserts a value at the specified index.
func (*LinkedList[T]) Bottom ¶
func (l *LinkedList[T]) Bottom() *T
Bottom returns the value at the end of the linked list.
func (*LinkedList[T]) Count ¶
func (l *LinkedList[T]) Count() int
Count returns the amount of entries in the linked list.
func (*LinkedList[T]) Empty ¶
func (l *LinkedList[T]) Empty() bool
Empty returns true if the linked list is empty, false if not.
func (*LinkedList[T]) ForEach ¶
func (l *LinkedList[T]) ForEach(f func(i int, val T))
ForEach iterates over the dataset within the linked list, calling the passed function for each value.
func (*LinkedList[T]) Get ¶
func (l *LinkedList[T]) Get(index int) *T
Get gets a value at the specified index.
func (*LinkedList[T]) Has ¶
func (l *LinkedList[T]) Has(value T) bool
Has returns true if the value exists in the linked list, false if not.
func (*LinkedList[T]) PopBottom ¶
func (l *LinkedList[T]) PopBottom()
PopBottom removes the last value in the linked list.
func (*LinkedList[T]) PopTop ¶
func (l *LinkedList[T]) PopTop()
PopTop removes the first value in the linked list.
func (*LinkedList[T]) PutOnBottom ¶
func (l *LinkedList[T]) PutOnBottom(val T)
PutOnBottom inserts a value at the end of the linked list.
func (*LinkedList[T]) PutOnTop ¶
func (l *LinkedList[T]) PutOnTop(value T)
PutOnTop inserts a value at the beginning of the linked list.
func (*LinkedList[T]) Remove ¶
func (l *LinkedList[T]) Remove(index int)
Remove removes a value at the specified index.
func (*LinkedList[T]) Top ¶
func (l *LinkedList[T]) Top() *T
Top returns the value at the beginning of the linked list.
func (*LinkedList[T]) Update ¶
func (l *LinkedList[T]) Update(index int, val T)
Update updates a value at the specified index.
type Promising ¶
func WithCancel ¶
type Queue ¶
type Queue[T comparable] struct { // contains filtered or unexported fields }
Queue is the main queue type.
func NewQueue ¶
func NewQueue[T comparable](capacity ...int) Queue[T]
NewQueue is used to create a new queue.
func (*Queue[T]) Dequeue ¶
func (q *Queue[T]) Dequeue() *T
Dequeue returns the first value and removes it.
type SortedMap ¶
type SortedMap[K ordered, V any] struct { // contains filtered or unexported fields }
func NewSortedMap ¶
type Stack ¶
type Stack[T comparable] struct { // contains filtered or unexported fields }
Stack is the main stack type.
type StringKeyOrderedMap ¶
type StringKeyOrderedMap[V any] struct { // contains filtered or unexported fields }
func NewStringKeyOrderedMap ¶
func NewStringKeyOrderedMap[V any](kvList ...*KV[V]) *StringKeyOrderedMap[V]
func (*StringKeyOrderedMap[V]) Append ¶
func (m *StringKeyOrderedMap[V]) Append(newOm *StringKeyOrderedMap[V], overwrite bool) *StringKeyOrderedMap[V]
func (*StringKeyOrderedMap[V]) Delete ¶
func (m *StringKeyOrderedMap[V]) Delete(key string)
func (*StringKeyOrderedMap[V]) Exists ¶
func (m *StringKeyOrderedMap[V]) Exists(key string) bool
func (*StringKeyOrderedMap[V]) Get ¶
func (m *StringKeyOrderedMap[V]) Get(key string) V
func (*StringKeyOrderedMap[V]) GetKeys ¶
func (m *StringKeyOrderedMap[V]) GetKeys() []string
func (*StringKeyOrderedMap[V]) GetList ¶
func (m *StringKeyOrderedMap[V]) GetList() []KV[V]
func (*StringKeyOrderedMap[V]) Len ¶
func (m *StringKeyOrderedMap[V]) Len() int
func (*StringKeyOrderedMap[V]) MarshalJSON ¶
func (m *StringKeyOrderedMap[V]) MarshalJSON() ([]byte, error)
func (*StringKeyOrderedMap[V]) Set ¶
func (m *StringKeyOrderedMap[V]) Set(key string, value V) *StringKeyOrderedMap[V]
func (*StringKeyOrderedMap[V]) String ¶
func (m *StringKeyOrderedMap[V]) String() string
type Topiq ¶
type Topiq[T any] struct { // contains filtered or unexported fields }
Topiq is a publish-subscribe topic.
func (*Topiq[T]) Dispatch ¶
Dispatch publishes a message to the Topiq. This method is non-blocking and concurrent-safe. Returns ErrNotRunning if the Topiq has been already closed.
func (*Topiq[T]) Listen ¶
Listen registers the passed function as a subscriber to the Topiq. This method is non-blocking and concurrent-safe. Function passed to Listen is called when a message is published to the Topiq, obviously. Returns ErrNotRunning if the Topiq has been already closed.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package timsort provides fast stable sort, uses external comparator.
|
Package timsort provides fast stable sort, uses external comparator. |