Documentation ¶
Overview ¶
Package zarray provides array operations
Index ¶
- Variables
- func Contains[T comparable](collection []T, v T) bool
- func CopySlice[T any](l []T) []T
- func Diff[T comparable](list1 []T, list2 []T) ([]T, []T)
- func Filter[T any](slice []T, predicate func(index int, item T) bool) []T
- func Find[T any](collection []T, predicate func(index int, item T) bool) (res T, ok bool)
- func GetInf(arr []interface{}, index int, def ...interface{}) (value interface{}, err error)
- func Keys[K comparable, V any](in map[K]V) []K
- func Map[T any, R any](collection []T, iteratee func(int, T) R) []R
- func ParallelMap[T any, R any](collection []T, iteratee func(int, T) R, workers uint) []R
- func Pop[T comparable](list *[]T) (v T)
- func Rand[T any](collection []T) T
- func Reverse[T any](collection []T) []T
- func Shift[T comparable](list *[]T) (v T)
- func Shuffle[T any](collection []T) []T
- func Unique[T comparable](collection []T) []T
- func Values[K comparable, V any](in map[K]V) []V
- type Array
- func (arr *Array) Add(index int, value interface{}) (err error)
- func (arr *Array) CapLength() int
- func (arr *Array) Clear()
- func (arr *Array) Contains(value interface{}) bool
- func (arr *Array) Format() (format string)
- func (arr *Array) Get(index int, def ...interface{}) (value interface{}, err error)
- func (arr *Array) Index(value interface{}) int
- func (arr *Array) IsEmpty() bool
- func (arr *Array) Length() int
- func (arr *Array) Map(fn func(int, interface{}) interface{}) *Array
- func (arr *Array) Pop() (interface{}, error)
- func (arr *Array) Push(values ...interface{})
- func (arr *Array) Raw() []interface{}
- func (arr *Array) Remove(index int, l ...int) (value []interface{}, err error)
- func (arr *Array) RemoveValue(value interface{}) (e interface{}, err error)
- func (arr *Array) Set(index int, value interface{}) (err error)
- func (arr *Array) Shift() (interface{}, error)
- func (arr *Array) Shuffle() (array *Array)
- func (arr *Array) Unshift(value interface{}) error
- type Maper
- func (m *Maper[K, V]) CAS(key K, oldValue, newValue V) bool
- func (m *Maper[K, V]) Clear()
- func (m *Maper[K, V]) Delete(keys ...K)
- func (m *Maper[K, V]) Fillrate() uintptr
- func (m *Maper[K, V]) ForEach(lambda func(K, V) bool)
- func (m *Maper[K, V]) Get(key K) (value V, ok bool)
- func (m *Maper[K, V]) GetAndDelete(key K) (value V, ok bool)
- func (m *Maper[K, V]) GetOrSet(key K, value V) (actual V, loaded bool)
- func (m *Maper[K, V]) Grow(newSize uintptr)
- func (m *Maper[K, V]) Has(key K) (ok bool)
- func (m *Maper[K, V]) Keys() (keys []K)
- func (m *Maper[K, V]) Len() uintptr
- func (m *Maper[K, V]) MarshalJSON() ([]byte, error)
- func (m *Maper[K, V]) ProvideGet(key K, provide func() (V, bool)) (actual V, loaded, computed bool)
- func (m *Maper[K, V]) Set(key K, value V)
- func (m *Maper[K, V]) SetHasher(hasher func(K) uintptr)
- func (m *Maper[K, V]) Swap(key K, newValue V) (oldValue V, swapped bool)
- func (m *Maper[K, V]) UnmarshalJSON(i []byte) error
- type SortMaper
- func (s *SortMaper[K, V]) Delete(key ...K)
- func (s *SortMaper[K, V]) ForEach(lambda func(K, V) bool)
- func (s *SortMaper[K, V]) Get(key K) (value V, ok bool)
- func (s *SortMaper[K, V]) Has(key K) (ok bool)
- func (s *SortMaper[K, V]) Keys() []K
- func (s *SortMaper[K, V]) Len() int
- func (s *SortMaper[K, V]) Set(key K, value V)
Constants ¶
This section is empty.
Variables ¶
var ErrIllegalIndex = errors.New("illegal index")
ErrIllegalIndex illegal index
Functions ¶
func Contains ¶ added in v1.4.3
func Contains[T comparable](collection []T, v T) bool
Contains returns true if an eent is present in a collection.
func Diff ¶ added in v1.4.5
func Diff[T comparable](list1 []T, list2 []T) ([]T, []T)
Diff returns the difference between two slices.
func Find ¶ added in v1.4.5
Find search an eent in a slice based on a predicate. It returns eent and true if eent was found.
func GetInf ¶ added in v1.3.2
GetInf Get the element corresponding to the index position of [] interface {}
func Keys ¶ added in v1.4.3
func Keys[K comparable, V any](in map[K]V) []K
Keys creates an array of the map keys
func ParallelMap ¶ added in v1.7.9
ParallelMap Parallel manipulates a slice and transforms it to a slice of another type. If the calculation does not involve time-consuming operations, we recommend using a Map.
func Pop ¶ added in v1.6.0
func Pop[T comparable](list *[]T) (v T)
Pop returns an eent and removes it from the slice.
func Reverse ¶ added in v1.7.0
func Reverse[T any](collection []T) []T
Reverse creates a slice of reversed values.
func Shift ¶ added in v1.6.0
func Shift[T comparable](list *[]T) (v T)
Shift returns an eent and removes it from the slice.
func Shuffle ¶ added in v1.3.6
func Shuffle[T any](collection []T) []T
Shuffle creates a slice of shuffled values.
func Unique ¶ added in v1.4.5
func Unique[T comparable](collection []T) []T
Unique returns a duplicate-free version of an array.
func Values ¶ added in v1.4.3
func Values[K comparable, V any](in map[K]V) []V
Values creates an array of the map values
Types ¶
type Array ¶
type Array struct {
// contains filtered or unexported fields
}
Array insert, delete, random access according to the subscript operation, the data is interface type
func (*Array) Push ¶
func (arr *Array) Push(values ...interface{})
Push insert element to end of array
func (*Array) RemoveValue ¶
RemoveValue removes the specified element from the array
type Maper ¶ added in v1.4.5
type Maper[K hashable, V any] struct { // contains filtered or unexported fields }
Maper implements the concurrent hashmap
func NewHashMap ¶ added in v1.4.4
func (*Maper[K, V]) CAS ¶ added in v1.4.5
func (m *Maper[K, V]) CAS(key K, oldValue, newValue V) bool
CAS `Maper` struct is used to perform a Compare-and-Swap operation on a key-value pair in the hashmap.
func (*Maper[K, V]) Delete ¶ added in v1.4.9
func (m *Maper[K, V]) Delete(keys ...K)
Delete a map data structure.
func (*Maper[K, V]) Fillrate ¶ added in v1.4.5
func (m *Maper[K, V]) Fillrate() uintptr
Fillrate calculates the fill rate of the hashmap. It returns the percentage of slots in the hashmap that are currently occupied by elements.
func (*Maper[K, V]) ForEach ¶ added in v1.4.5
func (m *Maper[K, V]) ForEach(lambda func(K, V) bool)
ForEach `Maper` struct iterates over each key-value pair in the hashmap and applies a lambda function to each pair. The lambda function takes a key and value as input parameters and returns a boolean value. If the lambda function returns `true`, the iteration continues to the next key-value pair. If the lambda function returns `false`, the iteration stops.
func (*Maper[K, V]) Get ¶ added in v1.4.5
func (m *Maper[K, V]) Get(key K) (value V, ok bool)
Get `Maper` struct is used to retrieve the value associated with a given key from the hashmap. It takes a key as input and returns the corresponding value and a boolean indicating whether the key exists in the hashmap.
func (*Maper[K, V]) GetAndDelete ¶ added in v1.5.0
func (m *Maper[K, V]) GetAndDelete(key K) (value V, ok bool)
func (*Maper[K, V]) GetOrSet ¶ added in v1.4.8
func (m *Maper[K, V]) GetOrSet(key K, value V) (actual V, loaded bool)
func (*Maper[K, V]) Has ¶ added in v1.5.0
func (m *Maper[K, V]) Has(key K) (ok bool)
Has a parameter "key" of type K and returns a boolean value "ok".
func (*Maper[K, V]) Keys ¶ added in v1.7.2
func (m *Maper[K, V]) Keys() (keys []K)
Keys returns the keys of the map.
func (*Maper[K, V]) MarshalJSON ¶ added in v1.5.0
MarshalJSON convert the `Maper` object into a JSON-encoded byte slice.
func (*Maper[K, V]) ProvideGet ¶ added in v1.4.5
ProvideGet `Maper` struct is used to retrieve the value associated with a given key from the hashmap. If the key exists in the hashmap, the function returns the value and sets the `loaded` flag to true. If the key does not exist, the function calls the `provide` function to compute the value and sets the `computed` flag to true. The computed value is then added to the hashmap and returned.
func (*Maper[K, V]) SetHasher ¶ added in v1.4.5
func (m *Maper[K, V]) SetHasher(hasher func(K) uintptr)
func (*Maper[K, V]) Swap ¶ added in v1.4.5
func (m *Maper[K, V]) Swap(key K, newValue V) (oldValue V, swapped bool)
Swap `Maper` struct is used to atomically swap the value associated with a given key in the hashmap. It takes a key and a new value as input parameters and returns the old value that was swapped out and a boolean indicating whether the swap was successful.
func (*Maper[K, V]) UnmarshalJSON ¶ added in v1.5.0
UnmarshalJSON used to deserialize a JSON-encoded byte slice into a `Maper` object.