garray

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StrArray

type StrArray struct {
	// contains filtered or unexported fields
}

StrArray is a golang string array with rich features.

func NewStrArray

func NewStrArray(safe ...bool) *StrArray

NewStrArray creates and returns an empty array. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.

func NewStrArrayFrom

func NewStrArrayFrom(array []string, safe ...bool) *StrArray

NewStrArrayFrom creates and returns an array with given slice <array>. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.

func NewStrArrayFromCopy

func NewStrArrayFromCopy(array []string, safe ...bool) *StrArray

NewStrArrayFromCopy creates and returns an array from a copy of given slice <array>. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.

func NewStrArraySize

func NewStrArraySize(size int, cap int, safe ...bool) *StrArray

NewStrArraySize create and returns an array with given size and cap. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.

func (*StrArray) Append

func (a *StrArray) Append(value ...string) *StrArray

See PushRight.

func (*StrArray) Chunk

func (a *StrArray) Chunk(size int) [][]string

Chunk splits an array into multiple arrays, the size of each array is determined by <size>. The last chunk may contain less than size elements.

func (*StrArray) Clear

func (a *StrArray) Clear() *StrArray

Clear deletes all items of current array.

func (*StrArray) Clone

func (a *StrArray) Clone() (newArray *StrArray)

Clone returns a new array, which is a copy of current array.

func (*StrArray) Contains

func (a *StrArray) Contains(value string) bool

Contains checks whether a value exists in the array.

func (*StrArray) ContainsI

func (a *StrArray) ContainsI(value string) bool

ContainsI checks whether a value exists in the array with case-insensitively. Note that it internally iterates the whole array to do the comparison with case-insensitively.

func (*StrArray) CountValues

func (a *StrArray) CountValues() map[string]int

CountValues counts the number of occurrences of all values in the array.

func (*StrArray) Fill

func (a *StrArray) Fill(startIndex int, num int, value string) error

Fill fills an array with num entries of the value <value>, keys starting at the <startIndex> parameter.

func (*StrArray) FilterEmpty

func (a *StrArray) FilterEmpty() *StrArray

FilterEmpty removes all empty string value of the array.

func (*StrArray) Get

func (a *StrArray) Get(index int) (value string, found bool)

Get returns the value by the specified index. If the given <index> is out of range of the array, the <found> is false.

func (*StrArray) InsertAfter

func (a *StrArray) InsertAfter(index int, value string) error

InsertAfter inserts the <value> to the back of <index>.

func (*StrArray) InsertBefore

func (a *StrArray) InsertBefore(index int, value string) error

InsertBefore inserts the <value> to the front of <index>.

func (*StrArray) Interfaces

func (a *StrArray) Interfaces() []interface{}

Interfaces returns current array as []interface{}.

func (*StrArray) IsEmpty

func (a *StrArray) IsEmpty() bool

IsEmpty checks whether the array is empty.

func (*StrArray) Iterator

func (a *StrArray) Iterator(f func(k int, v string) bool)

Iterator is alias of IteratorAsc.

func (*StrArray) IteratorAsc

func (a *StrArray) IteratorAsc(f func(k int, v string) bool)

IteratorAsc iterates the array readonly in ascending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.

func (*StrArray) IteratorDesc

func (a *StrArray) IteratorDesc(f func(k int, v string) bool)

IteratorDesc iterates the array readonly in descending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.

func (*StrArray) Join

func (a *StrArray) Join(glue string) string

Join joins array elements with a string <glue>.

func (*StrArray) Len

func (a *StrArray) Len() int

Len returns the length of array.

func (*StrArray) LockFunc

func (a *StrArray) LockFunc(f func(array []string)) *StrArray

LockFunc locks writing by callback function <f>.

func (StrArray) MarshalJSON

func (a StrArray) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface MarshalJSON for json.Marshal. Note that do not use pointer as its receiver here.

func (*StrArray) Merge

func (a *StrArray) Merge(array []string) *StrArray

Merge merges <array> into current array. The parameter <array> can be any garray or slice type. The difference between Merge and Append is Append supports only specified slice type, but Merge supports more parameter types.

func (*StrArray) Pad

func (a *StrArray) Pad(size int, value string) *StrArray

Pad pads array to the specified length with <value>. If size is positive then the array is padded on the right, or negative on the left. If the absolute value of <size> is less than or equal to the length of the array then no padding takes place.

func (*StrArray) PopLeft

func (a *StrArray) PopLeft() (value string, found bool)

PopLeft pops and returns an item from the beginning of array. Note that if the array is empty, the <found> is false.

func (*StrArray) PopLefts

func (a *StrArray) PopLefts(size int) []string

PopLefts pops and returns <size> items from the beginning of array. If the given <size> is greater than size of the array, it returns all elements of the array. Note that if given <size> <= 0 or the array is empty, it returns nil.

func (*StrArray) PopRand

func (a *StrArray) PopRand() (value string, found bool)

PopRand randomly pops and return an item out of array. Note that if the array is empty, the <found> is false.

func (*StrArray) PopRands

func (a *StrArray) PopRands(size int) []string

PopRands randomly pops and returns <size> items out of array. If the given <size> is greater than size of the array, it returns all elements of the array. Note that if given <size> <= 0 or the array is empty, it returns nil.

func (*StrArray) PopRight

func (a *StrArray) PopRight() (value string, found bool)

PopRight pops and returns an item from the end of array. Note that if the array is empty, the <found> is false.

func (*StrArray) PopRights

func (a *StrArray) PopRights(size int) []string

PopRights pops and returns <size> items from the end of array. If the given <size> is greater than size of the array, it returns all elements of the array. Note that if given <size> <= 0 or the array is empty, it returns nil.

func (*StrArray) PushLeft

func (a *StrArray) PushLeft(value ...string) *StrArray

PushLeft pushes one or multiple items to the beginning of array.

func (*StrArray) PushRight

func (a *StrArray) PushRight(value ...string) *StrArray

PushRight pushes one or multiple items to the end of array. It equals to Append.

func (*StrArray) RLockFunc

func (a *StrArray) RLockFunc(f func(array []string)) *StrArray

RLockFunc locks reading by callback function <f>.

func (*StrArray) Rand

func (a *StrArray) Rand() (value string, found bool)

Rand randomly returns one item from array(no deleting).

func (*StrArray) Rands

func (a *StrArray) Rands(size int) []string

Rands randomly returns <size> items from array(no deleting).

func (*StrArray) Range

func (a *StrArray) Range(start int, end ...int) []string

Range picks and returns items by range, like array[start:end]. Notice, if in concurrent-safe usage, it returns a copy of slice; else a pointer to the underlying data.

If <end> is negative, then the offset will start from the end of array. If <end> is omitted, then the sequence will have everything from start up until the end of the array.

func (*StrArray) Remove

func (a *StrArray) Remove(index int) (value string, found bool)

Remove removes an item by index. If the given <index> is out of range of the array, the <found> is false.

func (*StrArray) RemoveValue

func (a *StrArray) RemoveValue(value string) bool

RemoveValue removes an item by value. It returns true if value is found in the array, or else false if not found.

func (*StrArray) Replace

func (a *StrArray) Replace(array []string) *StrArray

Replace replaces the array items by given <array> from the beginning of array.

func (*StrArray) Reverse

func (a *StrArray) Reverse() *StrArray

Reverse makes array with elements in reverse order.

func (*StrArray) Search

func (a *StrArray) Search(value string) int

Search searches array by <value>, returns the index of <value>, or returns -1 if not exists.

func (*StrArray) Set

func (a *StrArray) Set(index int, value string) error

Set sets value to specified index.

func (*StrArray) SetArray

func (a *StrArray) SetArray(array []string) *StrArray

SetArray sets the underlying slice array with the given <array>.

func (*StrArray) Shuffle

func (a *StrArray) Shuffle() *StrArray

Shuffle randomly shuffles the array.

func (*StrArray) Slice

func (a *StrArray) Slice() []string

Slice returns the underlying data of array. Note that, if it's in concurrent-safe usage, it returns a copy of underlying data, or else a pointer to the underlying data.

func (*StrArray) Sort

func (a *StrArray) Sort(reverse ...bool) *StrArray

Sort sorts the array in increasing order. The parameter <reverse> controls whether sort in increasing order(default) or decreasing order

func (*StrArray) SortFunc

func (a *StrArray) SortFunc(less func(v1, v2 string) bool) *StrArray

SortFunc sorts the array by custom function <less>.

func (*StrArray) SubSlice

func (a *StrArray) SubSlice(offset int, length ...int) []string

SubSlice returns a slice of elements from the array as specified by the <offset> and <size> parameters. If in concurrent safe usage, it returns a copy of the slice; else a pointer.

If offset is non-negative, the sequence will start at that offset in the array. If offset is negative, the sequence will start that far from the end of the array.

If length is given and is positive, then the sequence will have up to that many elements in it. If the array is shorter than the length, then only the available array elements will be present. If length is given and is negative then the sequence will stop that many elements from the end of the array. If it is omitted, then the sequence will have everything from offset up until the end of the array.

Any possibility crossing the left border of array, it will fail.

func (*StrArray) Sum

func (a *StrArray) Sum() (sum int)

Sum returns the sum of values in an array.

func (*StrArray) Unique

func (a *StrArray) Unique() *StrArray

Unique uniques the array, clear repeated items. Example: [1,1,2,3,2] -> [1,2,3]

func (*StrArray) UnmarshalJSON

func (a *StrArray) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

func (*StrArray) Walk

func (a *StrArray) Walk(f func(value string) string) *StrArray

Walk applies a user supplied function <f> to every item of array.

Jump to

Keyboard shortcuts

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