zarray

package
v1.4.9 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2022 License: MIT Imports: 13 Imported by: 15

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 Diff added in v1.4.5

func Diff[T comparable](list1 []T, list2 []T) ([]T, []T)

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) (T, 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 Rand added in v1.4.3

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

Rand A random eents

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
}

Map 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

func (*Maper[K, V]) Delete added in v1.4.9

func (m *Maper[K, V]) Delete(keys ...K)

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

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

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

func (m *Maper[K, V]) ForEach(lambda func(K, V) bool)

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

func (m *Maper[K, V]) Get(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]) Len added in v1.4.5

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

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 bool)

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)

Jump to

Keyboard shortcuts

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