zarray

package
v1.7.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2024 License: MIT Imports: 16 Imported by: 14

Documentation

Overview

Package zarray provides array operations

Index

Constants

This section is empty.

Variables

View Source
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 CopySlice added in v1.7.5

func CopySlice[T any](l []T) []T

CopySlice copy a slice.

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 Filter added in v1.3.6

func Filter[T any](slice []T, predicate func(index int, item T) bool) []T

Filter iterates over eents of collection.

func Find added in v1.4.5

func Find[T any](collection []T, predicate func(index int, item T) bool) (res T, ok bool)

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

func GetInf(arr []interface{}, index int, def ...interface{}) (value interface{}, err error)

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 Map added in v1.4.4

func Map[T any, R any](collection []T, iteratee func(int, T) R) []R

Map manipulates a slice and transforms it to a slice of another type.

func ParallelMap added in v1.7.9

func ParallelMap[T any, R any](collection []T, iteratee func(int, T) R, workers uint) []R

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 Rand added in v1.4.3

func Rand[T any](collection []T) T

Rand A random eents.

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 Copy deprecated

func Copy(arr interface{}) (array *Array, err error)

Deprecated: please use CopyArray

func CopyArray added in v1.4.4

func CopyArray(arr interface{}) (array *Array, err error)

Copy an array

func New deprecated

func New(capacity ...int) (array *Array)

Deprecated: please use NewArray

func NewArray added in v1.4.4

func NewArray(capacity ...int) (array *Array)

New array initialization memory

func (*Array) Add

func (arr *Array) Add(index int, value interface{}) (err error)

Add in the index position insert the element

func (*Array) CapLength

func (arr *Array) CapLength() int

CapLength get array capacity

func (*Array) Clear

func (arr *Array) Clear()

Clear array

func (*Array) Contains

func (arr *Array) Contains(value interface{}) bool

Contains find if there are elements in the array

func (*Array) Format

func (arr *Array) Format() (format string)

Format output sequence

func (*Array) Get

func (arr *Array) Get(index int, def ...interface{}) (value interface{}, err error)

Get the element corresponding to the index position

func (*Array) Index

func (arr *Array) Index(value interface{}) int

Index find array by index, index range [0, n-1] (not found, return - 1)

func (*Array) IsEmpty

func (arr *Array) IsEmpty() bool

IsEmpty determine whether the array is empty

func (*Array) Length

func (arr *Array) Length() int

Length get array length

func (*Array) Map added in v0.0.17

func (arr *Array) Map(fn func(int, interface{}) interface{}) *Array

Map ForEcho traversing generates a new array

func (*Array) Pop

func (arr *Array) Pop() (interface{}, error)

Pop delete end element

func (*Array) Push

func (arr *Array) Push(values ...interface{})

Push insert element to end of array

func (*Array) Raw

func (arr *Array) Raw() []interface{}

Raw original array

func (*Array) Remove

func (arr *Array) Remove(index int, l ...int) (value []interface{}, err error)

Remove delete the element at index position and return

func (*Array) RemoveValue

func (arr *Array) RemoveValue(value interface{}) (e interface{}, err error)

RemoveValue removes the specified element from the array

func (*Array) Set

func (arr *Array) Set(index int, value interface{}) (err error)

Set modify the element at the index position

func (*Array) Shift

func (arr *Array) Shift() (interface{}, error)

Shift delete the first element of the array

func (*Array) Shuffle added in v1.3.2

func (arr *Array) Shuffle() (array *Array)

Shuffle creates an slice of shuffled values

func (*Array) Unshift

func (arr *Array) Unshift(value interface{}) error

Unshift insert element into array header

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 NewHashMap[K hashable, V any](size ...uintptr) *Maper[K, V]

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]) Clear added in v1.7.0

func (m *Maper[K, V]) Clear()

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]) Grow added in v1.4.5

func (m *Maper[K, V]) Grow(newSize uintptr)

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]) Len added in v1.4.5

func (m *Maper[K, V]) Len() uintptr

func (*Maper[K, V]) MarshalJSON added in v1.5.0

func (m *Maper[K, V]) MarshalJSON() ([]byte, error)

MarshalJSON convert the `Maper` object into a JSON-encoded byte slice.

func (*Maper[K, V]) ProvideGet added in v1.4.5

func (m *Maper[K, V]) ProvideGet(key K, provide func() (V, bool)) (actual V, loaded, computed bool)

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]) Set added in v1.4.5

func (m *Maper[K, V]) Set(key K, value V)

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

func (m *Maper[K, V]) UnmarshalJSON(i []byte) error

UnmarshalJSON used to deserialize a JSON-encoded byte slice into a `Maper` object.

type SortMaper added in v1.5.0

type SortMaper[K hashable, V any] struct {
	// contains filtered or unexported fields
}

func NewSortMap added in v1.5.0

func NewSortMap[K hashable, V any](size ...uintptr) *SortMaper[K, V]

func (*SortMaper[K, V]) Delete added in v1.5.0

func (s *SortMaper[K, V]) Delete(key ...K)

func (*SortMaper[K, V]) ForEach added in v1.5.0

func (s *SortMaper[K, V]) ForEach(lambda func(K, V) bool)

func (*SortMaper[K, V]) Get added in v1.5.0

func (s *SortMaper[K, V]) Get(key K) (value V, ok bool)

func (*SortMaper[K, V]) Has added in v1.5.0

func (s *SortMaper[K, V]) Has(key K) (ok bool)

func (*SortMaper[K, V]) Keys added in v1.5.0

func (s *SortMaper[K, V]) Keys() []K

func (*SortMaper[K, V]) Len added in v1.5.0

func (s *SortMaper[K, V]) Len() int

func (*SortMaper[K, V]) Set added in v1.5.0

func (s *SortMaper[K, V]) Set(key K, value V)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL