Documentation
¶
Index ¶
- Variables
- func All[T any](slice []T, f func(T) bool) bool
- func AnyOf[T comparable](e T, values ...T) bool
- func DerefSlice[T any](v *[]T) []T
- func FeltArrToString(arr []*felt.Felt) string
- func Filter[T any](slice []T, f func(T) bool) []T
- func Gzip64Decode(data string) ([]byte, error)
- func Gzip64Encode(data []byte) (string, error)
- func IsNil(i any) bool
- func Map[T1, T2 any](slice []T1, f func(T1) T2) []T2
- func NonNilSlice[T any](sl []T) []T
- func Set[T comparable](slice []T) []T
- func ToMap[T any, K comparable, V any](sl []T, f func(T) (K, V)) map[K]V
- func ToPtrSlice[T any](s []T) []*T
- func ToSlice[K comparable, V any, T any](m map[K]V, f func(K, V) T) []T
- type OrderedSet
- type Throttler
Constants ¶
This section is empty.
Variables ¶
var ErrResourceBusy = errors.New("resource busy, try again")
Functions ¶
func AnyOf ¶ added in v0.12.0
func AnyOf[T comparable](e T, values ...T) bool
func DerefSlice ¶ added in v0.8.0
func DerefSlice[T any](v *[]T) []T
func FeltArrToString ¶ added in v0.13.0
func Gzip64Decode ¶ added in v0.4.0
func Gzip64Encode ¶ added in v0.4.0
func IsNil ¶ added in v0.13.0
IsNil checks if the underlying value of the interface is nil.
In Golang, an interface is boxed by an underlying type and value; both of them need to be nil for the interface to be nil. See the following examples:
var i any fmt.Println(i == nil) // true var p *int var i any = p fmt.Println(i == nil) // false!
A solution for this is to use i == nil || reflect.ValueOf(i).IsNil()), however, this can cause a panic as not all reflect.Value has IsNil() defined. Therefore, default is to return false. For example, reflect.Array cannot be nil, hence calling IsNil() will cause a panic.
func NonNilSlice ¶ added in v0.8.0
func NonNilSlice[T any](sl []T) []T
func Set ¶ added in v0.13.0
func Set[T comparable](slice []T) []T
Unique returns a new slice with duplicates removed. Panics if the slice contains pointer types.
func ToMap ¶ added in v0.10.0
func ToMap[T any, K comparable, V any](sl []T, f func(T) (K, V)) map[K]V
func ToPtrSlice ¶ added in v0.16.1
func ToPtrSlice[T any](s []T) []*T
ToPtrSlice returns a slice of pointers, where each pointer refers to a copy of the corresponding input element.
func ToSlice ¶ added in v0.10.0
func ToSlice[K comparable, V any, T any](m map[K]V, f func(K, V) T) []T
Types ¶
type OrderedSet ¶ added in v0.13.0
type OrderedSet[K comparable, V any] struct { // contains filtered or unexported fields }
OrderedSet is a thread-safe data structure that maintains both uniqueness and insertion order of elements. It combines the benefits of both maps and slices: - Uses a map for O(1) lookups and to ensure element uniqueness - Uses a slice to maintain insertion order and enable ordered iteration The data structure is safe for concurrent access through the use of a read-write mutex.
func NewOrderedSet ¶ added in v0.13.0
func NewOrderedSet[K comparable, V any]() *OrderedSet[K, V]
func (*OrderedSet[K, V]) Clear ¶ added in v0.14.5
func (o *OrderedSet[K, V]) Clear()
func (*OrderedSet[K, V]) Get ¶ added in v0.13.0
func (o *OrderedSet[K, V]) Get(key K) (V, bool)
func (*OrderedSet[K, V]) Keys ¶ added in v0.13.0
func (o *OrderedSet[K, V]) Keys() []K
Keys returns a slice of keys in their insertion order
func (*OrderedSet[K, V]) List ¶ added in v0.13.0
func (o *OrderedSet[K, V]) List() []V
List returns a shallow copy of the proof set's value list.
func (*OrderedSet[K, V]) Put ¶ added in v0.13.0
func (o *OrderedSet[K, V]) Put(key K, value V)
func (*OrderedSet[K, V]) Size ¶ added in v0.13.0
func (o *OrderedSet[K, V]) Size() int
type Throttler ¶ added in v0.7.4
type Throttler[T any] struct { // contains filtered or unexported fields }
func NewThrottler ¶ added in v0.7.4
func (*Throttler[T]) Do ¶ added in v0.7.4
Do lets caller acquire the resource within the context of a callback
func (*Throttler[T]) JobsRunning ¶ added in v0.10.0
JobsRunning returns the number of Do calls that are running at the moment
func (*Throttler[T]) QueueLen ¶ added in v0.7.4
QueueLen returns the number of Do calls that is blocked on the resource
func (*Throttler[T]) WithMaxQueueLen ¶ added in v0.7.4
WithMaxQueueLen sets the maximum length the queue can grow to