gf: github.com/johng-cn/gf/g/container/garray Index | Examples | Files

package garray

import "github.com/johng-cn/gf/g/container/garray"

Package garray provides kinds of concurrent-safe(alternative) arrays.

并发安全数组.

Code:

// 创建普通的数组,默认并发安全(带锁)
a := garray.New()

// 添加数据项
for i := 0; i < 10; i++ {
    a.Append(i)
}

// 获取当前数组长度
fmt.Println(a.Len())

// 获取当前数据项列表
fmt.Println(a.Slice())

// 获取指定索引项
fmt.Println(a.Get(6))

// 查找指定数据项是否存在
fmt.Println(a.Contains(6))
fmt.Println(a.Contains(100))

// 在指定索引前插入数据项
a.InsertAfter(9, 11)
// 在指定索引后插入数据项
a.InsertBefore(10, 10)

fmt.Println(a.Slice())

// 修改指定索引的数据项
a.Set(0, 100)
fmt.Println(a.Slice())

// 搜索数据项,返回搜索到的索引位置
fmt.Println(a.Search(5))

// 删除指定索引的数据项
a.Remove(0)
fmt.Println(a.Slice())

// 清空数组
fmt.Println(a.Slice())
a.Clear()
fmt.Println(a.Slice())

Output:

10
[0 1 2 3 4 5 6 7 8 9]
6
true
false
[0 1 2 3 4 5 6 7 8 9 10 11]
[100 1 2 3 4 5 6 7 8 9 10 11]
5
[1 2 3 4 5 6 7 8 9 10 11]
[1 2 3 4 5 6 7 8 9 10 11]
[]

Code:

array1 := garray.NewFrom([]interface{}{1, 2})
array2 := garray.NewFrom([]interface{}{3, 4})
slice1 := []interface{}{5, 6}
slice2 := []int{7, 8}
slice3 := []string{"9", "0"}
fmt.Println(array1.Slice())
array1.Merge(array1)
array1.Merge(array2)
array1.Merge(slice1)
array1.Merge(slice2)
array1.Merge(slice3)
fmt.Println(array1.Slice())

Output:

[1 2]
[1 2 1 2 3 4 5 6 7 8 9 0]

Code:

array := garray.NewFrom([]interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9})
fmt.Println(array.PopLeft())
fmt.Println(array.PopLefts(2))
fmt.Println(array.PopRight())
fmt.Println(array.PopRights(2))

Output:

1
[2 3]
9
[7 8]

Code:

array := garray.NewFrom([]interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9})
// 随机返回两个数据项(不删除)
fmt.Println(array.Rands(2))
fmt.Println(array.PopRand())

Index

Examples

Package Files

garray.go garray_func.go garray_normal_int.go garray_normal_interface.go garray_normal_string.go garray_sorted_int.go garray_sorted_interface.go garray_sorted_string.go

type Array Uses

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

func New Uses

func New(unsafe ...bool) *Array

Create an empty array. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

创建一个空的数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func NewArray Uses

func NewArray(unsafe ...bool) *Array

See New.

func NewArrayFrom Uses

func NewArrayFrom(array []interface{}, unsafe ...bool) *Array

Create an array with given slice <array>. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

通过给定的slice变量创建数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func NewArrayFromCopy Uses

func NewArrayFromCopy(array []interface{}, unsafe ...bool) *Array

Create an array from a copy of given slice <array>. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

通过给定的slice拷贝创建数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func NewArraySize Uses

func NewArraySize(size int, cap int, unsafe ...bool) *Array

Create an array with given size and cap. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

创建一个指定大小的数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func NewFrom Uses

func NewFrom(array []interface{}, unsafe ...bool) *Array

See NewArrayFrom.

func NewFromCopy Uses

func NewFromCopy(array []interface{}, unsafe ...bool) *Array

See NewArrayFromCopy.

func (*Array) Append Uses

func (a *Array) Append(value ...interface{}) *Array

See PushRight.

追加数据项, 等于: PushRight。

func (*Array) Chunk Uses

func (a *Array) Chunk(size int) [][]interface{}

Chunks an array into arrays with size elements. The last chunk may contain less than size elements.

将一个数组分割成多个数组,其中每个数组的单元数目由size决定。最后一个数组的单元数目可能会少于size个。

func (*Array) Clear Uses

func (a *Array) Clear() *Array

Clear array.

清空数据数组

func (*Array) Clone Uses

func (a *Array) Clone() (newArray *Array)

Return a new array, which is a copy of current array.

克隆当前数组,返回当前数组的一个拷贝。

func (*Array) Contains Uses

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

Check whether a value exists in the array.

查找指定数值是否存在

func (*Array) CountValues Uses

func (a *Array) CountValues() map[interface{}]int

Counts all the values of an array.

统计数组中所有的值出现的次数.

func (*Array) Fill Uses

func (a *Array) Fill(startIndex int, num int, value interface{}) *Array

Fills an array with num entries of the value of the value parameter, keys starting at the start_index parameter.

用value参数的值将数组填充num个条目,位置由startIndex参数指定的开始。

func (*Array) Get Uses

func (a *Array) Get(index int) interface{}

Get value by index.

获取指定索引的数据项, 调用方注意判断数组边界

func (*Array) InsertAfter Uses

func (a *Array) InsertAfter(index int, value interface{}) *Array

Insert the <value> to the back of <index>.

在当前索引位置前插入一个数据项, 调用方注意判断数组边界。

func (*Array) InsertBefore Uses

func (a *Array) InsertBefore(index int, value interface{}) *Array

Insert the <value> to the front of <index>.

在当前索引位置前插入一个数据项, 调用方注意判断数组边界。

func (*Array) Join Uses

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

Join array elements with a string.

使用glue字符串串连当前数组的元素项,构造成新的字符串返回。

func (*Array) Len Uses

func (a *Array) Len() int

Get the length of array.

数组长度。

func (*Array) LockFunc Uses

func (a *Array) LockFunc(f func(array []interface{})) *Array

Lock writing by callback function f.

使用自定义方法执行加锁修改操作

func (*Array) Merge Uses

func (a *Array) Merge(array interface{}) *Array

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

合并两个数组, 支持任意的garray数组类型及slice类型.

func (*Array) Pad Uses

func (a *Array) Pad(size int, val interface{}) *Array

Pad array to the specified length with a value. If size is positive then the array is padded on the right, if it's negative then 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.

返回数组的一个拷贝,并用value将其填补到size指定的长度。 如果size为正数,则填补到数组的右侧,如果为负数则从左侧开始填补。 如果size的绝对值小于或等于数组的长度则没有任何填补。

func (*Array) PopLeft Uses

func (a *Array) PopLeft() interface{}

Pop an item from the beginning of array.

将最左端(索引为0)的数据项移出数组,并返回该数据项。

func (*Array) PopLefts Uses

func (a *Array) PopLefts(size int) []interface{}

Pop <size> items from the beginning of array.

将最左端(首部)的size个数据项移出数组,并返回该数据项

func (*Array) PopRand Uses

func (a *Array) PopRand() interface{}

PopRand picks an random item out of array.

随机将一个数据项移出数组,并返回该数据项。

func (*Array) PopRands Uses

func (a *Array) PopRands(size int) []interface{}

PopRands picks <size> items out of array.

随机将size个数据项移出数组,并返回该数据项。

func (*Array) PopRight Uses

func (a *Array) PopRight() interface{}

Pop an item from the end of array.

将最右端(索引为length - 1)的数据项移出数组,并返回该数据项。

func (*Array) PopRights Uses

func (a *Array) PopRights(size int) []interface{}

Pop <size> items from the end of array.

将最右端(尾部)的size个数据项移出数组,并返回该数据项

func (*Array) PushLeft Uses

func (a *Array) PushLeft(value ...interface{}) *Array

Push new items to the beginning of array.

将数据项添加到数组的最左端(索引为0)。

func (*Array) PushRight Uses

func (a *Array) PushRight(value ...interface{}) *Array

Push new items to the end of array.

将数据项添加到数组的最右端(索引为length - 1), 等于: Append。

func (*Array) RLockFunc Uses

func (a *Array) RLockFunc(f func(array []interface{})) *Array

Lock reading by callback function f.

使用自定义方法执行加锁读取操作

func (*Array) Rand Uses

func (a *Array) Rand() interface{}

Rand gets one random entry from array.

从数组中随机获得1个元素项(不删除)。

func (*Array) Rands Uses

func (a *Array) Rands(size int) []interface{}

Rands gets one or more random entries from array(a copy).

从数组中随机拷贝size个元素项,构成slice返回。

func (*Array) Range Uses

func (a *Array) Range(start, end int) []interface{}

Get items by range, returns array[start:end]. Be aware that, if in concurrent-safe usage, it returns a copy of slice; else a pointer to the underlying data.

将最右端(尾部)的size个数据项移出数组,并返回该数据项

func (*Array) Remove Uses

func (a *Array) Remove(index int) interface{}

Remove an item by index.

删除指定索引的数据项, 调用方注意判断数组边界。

func (*Array) Replace Uses

func (a *Array) Replace(array []interface{}) *Array

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

使用指定数组替换到对应的索引元素值.

func (*Array) Reverse Uses

func (a *Array) Reverse() *Array

Make array with elements in reverse order.

将当前数组反转。

func (*Array) Search Uses

func (a *Array) Search(value interface{}) int

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

查找指定数值的索引位置,返回索引位置,如果查找不到则返回-1

func (*Array) Set Uses

func (a *Array) Set(index int, value interface{}) *Array

Set value by index.

设置指定索引的数据项, 调用方注意判断数组边界

func (*Array) SetArray Uses

func (a *Array) SetArray(array []interface{}) *Array

Set the underlying slice array with the given <array> param.

设置底层数组变量.

func (*Array) Shuffle Uses

func (a *Array) Shuffle() *Array

Randomly shuffles the array.

随机打乱当前数组。

func (*Array) Slice Uses

func (a *Array) Slice() []interface{}

Get the underlying data of array. Be aware that, if in concurrent-safe usage, it returns a copy of slice; else a pointer to the underlying data.

返回原始数据数组.

func (*Array) SortFunc Uses

func (a *Array) SortFunc(less func(v1, v2 interface{}) bool) *Array

Sort the array by custom function <less>.

使用自定义的排序函数将数组重新排序.

func (*Array) String Uses

func (a *Array) String() string

String returns current array as a string.

将当前数组转换为字符串返回。

func (*Array) SubSlice Uses

func (a *Array) SubSlice(offset, size int) []interface{}

Extract a slice of the array(If in concurrent safe usage, it returns a copy of the slice; else a pointer). It returns the sequence of elements from the array array as specified by the offset and length parameters.

返回根据offset和size参数所指定的数组中的一段序列。

func (*Array) Sum Uses

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

Calculate the sum of values in an array.

对数组中的元素项求和(将元素值转换为int类型后叠加)。

func (*Array) Unique Uses

func (a *Array) Unique() *Array

Unique the array, clear repeated values.

清理数组中重复的元素项

type IntArray Uses

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

func NewIntArray Uses

func NewIntArray(unsafe ...bool) *IntArray

Create an empty array. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

创建一个空的数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func NewIntArrayFrom Uses

func NewIntArrayFrom(array []int, unsafe ...bool) *IntArray

Create an array with given slice <array>. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

通过给定的slice变量创建数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func NewIntArrayFromCopy Uses

func NewIntArrayFromCopy(array []int, unsafe ...bool) *IntArray

Create an array from a copy of given slice <array>. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

通过给定的slice拷贝创建数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func NewIntArraySize Uses

func NewIntArraySize(size int, cap int, unsafe ...bool) *IntArray

Create an array with given size and cap. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

创建一个指定大小的数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func (*IntArray) Append Uses

func (a *IntArray) Append(value ...int) *IntArray

See PushRight.

追加数据项, 等于: PushRight。

func (*IntArray) Chunk Uses

func (a *IntArray) Chunk(size int) [][]int

Chunks an array into arrays with size elements. The last chunk may contain less than size elements.

将一个数组分割成多个数组,其中每个数组的单元数目由size决定。最后一个数组的单元数目可能会少于size个。

func (*IntArray) Clear Uses

func (a *IntArray) Clear() *IntArray

Clear array.

清空数据数组。

func (*IntArray) Clone Uses

func (a *IntArray) Clone() (newArray *IntArray)

Return a new array, which is a copy of current array.

克隆当前数组,返回当前数组的一个拷贝。

func (*IntArray) Contains Uses

func (a *IntArray) Contains(value int) bool

Check whether a value exists in the array.

查找指定数值是否存在。

func (*IntArray) Fill Uses

func (a *IntArray) Fill(startIndex int, num int, value int) *IntArray

Fills an array with num entries of the value of the value parameter, keys starting at the startIndex parameter.

用value参数的值将数组填充num个条目,位置由startIndex参数指定的开始。

func (*IntArray) Get Uses

func (a *IntArray) Get(index int) int

Get value by index.

获取指定索引的数据项, 调用方注意判断数组边界。

func (*IntArray) InsertAfter Uses

func (a *IntArray) InsertAfter(index int, value int) *IntArray

Insert the <value> to the back of <index>.

在当前索引位置前插入一个数据项, 调用方注意判断数组边界。

func (*IntArray) InsertBefore Uses

func (a *IntArray) InsertBefore(index int, value int) *IntArray

Insert the <value> to the front of <index>.

在当前索引位置前插入一个数据项, 调用方注意判断数组边界。

func (*IntArray) Join Uses

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

Join array elements with a string.

使用glue字符串串连当前数组的元素项,构造成新的字符串返回。

func (*IntArray) Len Uses

func (a *IntArray) Len() int

Get the length of array.

数组长度。

func (*IntArray) LockFunc Uses

func (a *IntArray) LockFunc(f func(array []int)) *IntArray

Lock writing by callback function f.

使用自定义方法执行加锁修改操作。

func (*IntArray) Merge Uses

func (a *IntArray) Merge(array interface{}) *IntArray

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

合并两个数组, 支持任意的garray数组类型及slice类型.

func (*IntArray) Pad Uses

func (a *IntArray) Pad(size int, value int) *IntArray

Pad array to the specified length with a 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.

返回数组的一个拷贝,并用value将其填补到size指定的长度。 如果size为正数,则填补到数组的右侧,如果为负数则从左侧开始填补。 如果size的绝对值小于或等于数组的长度则没有任何填补。

func (*IntArray) PopLeft Uses

func (a *IntArray) PopLeft() int

Pop an item from the beginning of array.

将最左端(索引为0)的数据项移出数组,并返回该数据项。

func (*IntArray) PopLefts Uses

func (a *IntArray) PopLefts(size int) []int

Pop <size> items from the beginning of array.

将最左端(首部)的size个数据项移出数组,并返回该数据项。

func (*IntArray) PopRand Uses

func (a *IntArray) PopRand() int

PopRand picks an random item out of array.

随机将一个数据项移出数组,并返回该数据项。

func (*IntArray) PopRands Uses

func (a *IntArray) PopRands(size int) []int

PopRands picks <size> items out of array.

随机将size个数据项移出数组,并返回该数据项。

func (*IntArray) PopRight Uses

func (a *IntArray) PopRight() int

Pop an item from the end of array.

将最右端(索引为length - 1)的数据项移出数组,并返回该数据项。

func (*IntArray) PopRights Uses

func (a *IntArray) PopRights(size int) []int

Pop <size> items from the end of array.

将最右端(尾部)的size个数据项移出数组,并返回该数据项

func (*IntArray) PushLeft Uses

func (a *IntArray) PushLeft(value ...int) *IntArray

Push new items to the beginning of array.

将数据项添加到数组的最左端(索引为0)。

func (*IntArray) PushRight Uses

func (a *IntArray) PushRight(value ...int) *IntArray

Push new items to the end of array.

将数据项添加到数组的最右端(索引为length - 1), 等于: Append。

func (*IntArray) RLockFunc Uses

func (a *IntArray) RLockFunc(f func(array []int)) *IntArray

Lock reading by callback function f.

使用自定义方法执行加锁读取操作。

func (*IntArray) Rand Uses

func (a *IntArray) Rand() int

Rand gets one random entry from array.

从数组中随机获得1个元素项(不删除)。

func (*IntArray) Rands Uses

func (a *IntArray) Rands(size int) []int

Rands gets one or more random entries from array(a copy).

从数组中随机拷贝size个元素项,构成slice返回。

func (*IntArray) Range Uses

func (a *IntArray) Range(start, end int) []int

Get items by range, returns array[start:end]. Be aware that, if in concurrent-safe usage, it returns a copy of slice; else a pointer to the underlying data.

将最右端(尾部)的size个数据项移出数组,并返回该数据项

func (*IntArray) Remove Uses

func (a *IntArray) Remove(index int) int

Remove an item by index.

删除指定索引的数据项, 调用方注意判断数组边界。

func (*IntArray) Replace Uses

func (a *IntArray) Replace(array []int) *IntArray

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

使用指定数组替换到对应的索引元素值.

func (*IntArray) Reverse Uses

func (a *IntArray) Reverse() *IntArray

Make array with elements in reverse order.

将当前数组反转。

func (*IntArray) Search Uses

func (a *IntArray) Search(value int) int

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

查找指定数值的索引位置,返回索引位置,如果查找不到则返回-1。

func (*IntArray) Set Uses

func (a *IntArray) Set(index int, value int) *IntArray

Set value by index.

设置指定索引的数据项, 调用方注意判断数组边界。

func (*IntArray) SetArray Uses

func (a *IntArray) SetArray(array []int) *IntArray

Set the underlying slice array with the given <array> param.

设置底层数组变量.

func (*IntArray) Shuffle Uses

func (a *IntArray) Shuffle() *IntArray

Randomly shuffles the array.

随机打乱当前数组。

func (*IntArray) Slice Uses

func (a *IntArray) Slice() []int

Get the underlying data of array. Be aware that, if in concurrent-safe usage, it returns a copy of slice; else a pointer to the underlying data.

返回原始数据数组.

func (*IntArray) Sort Uses

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

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

将数组排序(默认从低到高).

func (*IntArray) SortFunc Uses

func (a *IntArray) SortFunc(less func(v1, v2 int) bool) *IntArray

Sort the array by custom function <less>.

使用自定义的排序函数将数组重新排序.

func (*IntArray) SubSlice Uses

func (a *IntArray) SubSlice(offset, size int) []int

Extract a slice of the array(If in concurrent safe usage, it returns a copy of the slice; else a pointer). It returns the sequence of elements from the array array as specified by the offset and length parameters.

返回根据offset和size参数所指定的数组中的一段序列。

func (*IntArray) Sum Uses

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

Calculate the sum of values in an array.

对数组中的元素项求和。

func (*IntArray) Unique Uses

func (a *IntArray) Unique() *IntArray

Unique the array, clear repeated values.

清理数组中重复的元素项。

type SortedArray Uses

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

默认按照从小到大进行排序

func NewSortedArray Uses

func NewSortedArray(compareFunc func(v1, v2 interface{}) int, unsafe ...bool) *SortedArray

Create an empty sorted array. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default. The param <compareFunc> used to compare values to sort in array, if it returns value < 0, means v1 < v2; if it returns value = 0, means v1 = v2; if it returns value > 0, means v1 > v2;

创建一个空的排序数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。 参数compareFunc用于指定排序方法: 如果返回值 < 0, 表示 v1 < v2; 如果返回值 = 0, 表示 v1 = v2; 如果返回值 > 0, 表示 v1 > v2;

func NewSortedArrayFrom Uses

func NewSortedArrayFrom(array []interface{}, compareFunc func(v1, v2 interface{}) int, unsafe ...bool) *SortedArray

Create an array with given slice <array>. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

通过给定的slice变量创建排序数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func NewSortedArrayFromCopy Uses

func NewSortedArrayFromCopy(array []interface{}, unsafe ...bool) *SortedArray

Create an array from a copy of given slice <array>. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

通过给定的slice拷贝创建数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func NewSortedArraySize Uses

func NewSortedArraySize(cap int, compareFunc func(v1, v2 interface{}) int, unsafe ...bool) *SortedArray

Create a sorted array with given size and cap. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

创建一个指定大小的排序数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func (*SortedArray) Add Uses

func (a *SortedArray) Add(values ...interface{}) *SortedArray

And values to sorted array, the array always keeps sorted.

添加数据项.

func (*SortedArray) Chunk Uses

func (a *SortedArray) Chunk(size int) [][]interface{}

Chunks an array into arrays with size elements. The last chunk may contain less than size elements.

将一个数组分割成多个数组,其中每个数组的单元数目由size决定。最后一个数组的单元数目可能会少于size个。

func (*SortedArray) Clear Uses

func (a *SortedArray) Clear() *SortedArray

Clear array.

清空数据数组。

func (*SortedArray) Clone Uses

func (a *SortedArray) Clone() (newArray *SortedArray)

Return a new array, which is a copy of current array.

克隆当前数组,返回当前数组的一个拷贝。

func (*SortedArray) Contains Uses

func (a *SortedArray) Contains(value interface{}) bool

Check whether a value exists in the array.

查找指定数值是否存在。

func (*SortedArray) Get Uses

func (a *SortedArray) Get(index int) interface{}

Get value by index.

获取指定索引的数据项, 调用方注意判断数组边界。

func (*SortedArray) Join Uses

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

Join array elements with a string.

使用glue字符串串连当前数组的元素项,构造成新的字符串返回。

func (*SortedArray) Len Uses

func (a *SortedArray) Len() int

Get the length of array.

数组长度。

func (*SortedArray) LockFunc Uses

func (a *SortedArray) LockFunc(f func(array []interface{})) *SortedArray

Lock writing by callback function f.

使用自定义方法执行加锁修改操作。

func (*SortedArray) Merge Uses

func (a *SortedArray) Merge(array interface{}) *SortedArray

Merge two arrays. The parameter <array> can be any garray type or slice type. The difference between Merge and Add is Add supports only specified slice type, but Merge supports more variable types.

合并两个数组, 支持任意的garray数组类型及slice类型.

func (*SortedArray) PopLeft Uses

func (a *SortedArray) PopLeft() interface{}

Push new items to the beginning of array.

将数据项添加到数组的最左端(索引为0)。

func (*SortedArray) PopLefts Uses

func (a *SortedArray) PopLefts(size int) []interface{}

Pop <size> items from the beginning of array.

将最左端(首部)的size个数据项移出数组,并返回该数据项

func (*SortedArray) PopRand Uses

func (a *SortedArray) PopRand() interface{}

PopRand picks an random item out of array.

随机将一个数据项移出数组,并返回该数据项。

func (*SortedArray) PopRands Uses

func (a *SortedArray) PopRands(size int) []interface{}

PopRands picks <size> items out of array.

随机将size个数据项移出数组,并返回该数据项。

func (*SortedArray) PopRight Uses

func (a *SortedArray) PopRight() interface{}

Push new items to the end of array.

将数据项添加到数组的最右端(索引为length - 1)。

func (*SortedArray) PopRights Uses

func (a *SortedArray) PopRights(size int) []interface{}

Pop <size> items from the end of array.

将最右端(尾部)的size个数据项移出数组,并返回该数据项

func (*SortedArray) RLockFunc Uses

func (a *SortedArray) RLockFunc(f func(array []interface{})) *SortedArray

Lock reading by callback function f.

使用自定义方法执行加锁读取操作。

func (*SortedArray) Rand Uses

func (a *SortedArray) Rand() interface{}

Rand gets one random entry from array.

从数组中随机获得1个元素项(不删除)。

func (*SortedArray) Rands Uses

func (a *SortedArray) Rands(size int) []interface{}

Rands gets one or more random entries from array(a copy).

从数组中随机拷贝size个元素项,构成slice返回。

func (*SortedArray) Range Uses

func (a *SortedArray) Range(start, end int) []interface{}

Get items by range, returns array[start:end]. Be aware that, if in concurrent-safe usage, it returns a copy of slice; else a pointer to the underlying data.

将最右端(尾部)的size个数据项移出数组,并返回该数据项

func (*SortedArray) Remove Uses

func (a *SortedArray) Remove(index int) interface{}

Remove an item by index.

删除指定索引的数据项, 调用方注意判断数组边界。

func (*SortedArray) Search Uses

func (a *SortedArray) Search(value interface{}) (index int)

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

查找指定数值的索引位置,返回索引位置,如果查找不到则返回-1。

func (*SortedArray) SetArray Uses

func (a *SortedArray) SetArray(array []interface{}) *SortedArray

Set the underlying slice array with the given <array> param.

设置底层数组变量.

func (*SortedArray) SetUnique Uses

func (a *SortedArray) SetUnique(unique bool) *SortedArray

Set unique mark to the array, which means it does not contain any repeated items. It also do unique check, remove all repeated items.

设置是否允许数组唯一.

func (*SortedArray) Slice Uses

func (a *SortedArray) Slice() []interface{}

Get the underlying data of array. Be aware that, if in concurrent-safe usage, it returns a copy of slice; else a pointer to the underlying data.

返回原始数据数组.

func (*SortedArray) Sort Uses

func (a *SortedArray) Sort() *SortedArray

Sort the array by comparing function.

将数组按照比较方法进行排序.

func (*SortedArray) SubSlice Uses

func (a *SortedArray) SubSlice(offset, size int) []interface{}

Extract a slice of the array(If in concurrent safe usage, it returns a copy of the slice; else a pointer). It returns the sequence of elements from the array array as specified by the offset and length parameters.

返回根据offset和size参数所指定的数组中的一段序列。

func (*SortedArray) Sum Uses

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

Calculate the sum of values in an array.

对数组中的元素项求和(将元素值转换为int类型后叠加)。

func (*SortedArray) Unique Uses

func (a *SortedArray) Unique() *SortedArray

Do unique check, remove all repeated items.

清理数组中重复的元素项.

type SortedIntArray Uses

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

默认按照从小到大进行排序

func NewSortedIntArray Uses

func NewSortedIntArray(unsafe ...bool) *SortedIntArray

Create an empty sorted array. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

创建一个空的排序数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func NewSortedIntArrayFrom Uses

func NewSortedIntArrayFrom(array []int, unsafe ...bool) *SortedIntArray

Create an array with given slice <array>. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

通过给定的slice变量创建排序数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func NewSortedIntArrayFromCopy Uses

func NewSortedIntArrayFromCopy(array []int, unsafe ...bool) *SortedIntArray

Create an array from a copy of given slice <array>. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

通过给定的slice拷贝创建数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func NewSortedIntArraySize Uses

func NewSortedIntArraySize(cap int, unsafe ...bool) *SortedIntArray

Create a sorted array with given size and cap. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

创建一个指定大小的排序数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func (*SortedIntArray) Add Uses

func (a *SortedIntArray) Add(values ...int) *SortedIntArray

And values to sorted array, the array always keeps sorted.

添加数据项.

func (*SortedIntArray) Chunk Uses

func (a *SortedIntArray) Chunk(size int) [][]int

Chunks an array into arrays with size elements. The last chunk may contain less than size elements.

将一个数组分割成多个数组,其中每个数组的单元数目由size决定。最后一个数组的单元数目可能会少于size个。

func (*SortedIntArray) Clear Uses

func (a *SortedIntArray) Clear() *SortedIntArray

Clear array.

清空数据数组。

func (*SortedIntArray) Clone Uses

func (a *SortedIntArray) Clone() (newArray *SortedIntArray)

Return a new array, which is a copy of current array.

克隆当前数组,返回当前数组的一个拷贝。

func (*SortedIntArray) Contains Uses

func (a *SortedIntArray) Contains(value int) bool

Check whether a value exists in the array.

查找指定数值是否存在。

func (*SortedIntArray) Get Uses

func (a *SortedIntArray) Get(index int) int

Get value by index.

获取指定索引的数据项, 调用方注意判断数组边界。

func (*SortedIntArray) Join Uses

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

Join array elements with a string.

使用glue字符串串连当前数组的元素项,构造成新的字符串返回。

func (*SortedIntArray) Len Uses

func (a *SortedIntArray) Len() int

Get the length of array.

数组长度。

func (*SortedIntArray) LockFunc Uses

func (a *SortedIntArray) LockFunc(f func(array []int)) *SortedIntArray

Lock writing by callback function f.

使用自定义方法执行加锁修改操作。

func (*SortedIntArray) Merge Uses

func (a *SortedIntArray) Merge(array interface{}) *SortedIntArray

Merge two arrays. The parameter <array> can be any garray type or slice type. The difference between Merge and Add is Add supports only specified slice type, but Merge supports more variable types.

合并两个数组, 支持任意的garray数组类型及slice类型.

func (*SortedIntArray) PopLeft Uses

func (a *SortedIntArray) PopLeft() int

Push new items to the beginning of array.

将数据项添加到数组的最左端(索引为0)。

func (*SortedIntArray) PopLefts Uses

func (a *SortedIntArray) PopLefts(size int) []int

Pop <size> items from the beginning of array.

将最左端(首部)的size个数据项移出数组,并返回该数据项

func (*SortedIntArray) PopRand Uses

func (a *SortedIntArray) PopRand() int

PopRand picks an random item out of array.

随机将一个数据项移出数组,并返回该数据项。

func (*SortedIntArray) PopRands Uses

func (a *SortedIntArray) PopRands(size int) []int

PopRands picks <size> items out of array.

随机将size个数据项移出数组,并返回该数据项。

func (*SortedIntArray) PopRight Uses

func (a *SortedIntArray) PopRight() int

Push new items to the end of array.

将数据项添加到数组的最右端(索引为length - 1)。

func (*SortedIntArray) PopRights Uses

func (a *SortedIntArray) PopRights(size int) []int

Pop <size> items from the end of array.

将最右端(尾部)的size个数据项移出数组,并返回该数据项

func (*SortedIntArray) RLockFunc Uses

func (a *SortedIntArray) RLockFunc(f func(array []int)) *SortedIntArray

Lock reading by callback function f.

使用自定义方法执行加锁读取操作。

func (*SortedIntArray) Rand Uses

func (a *SortedIntArray) Rand() int

Rand gets one random entry from array.

从数组中随机获得1个元素项(不删除)。

func (*SortedIntArray) Rands Uses

func (a *SortedIntArray) Rands(size int) []int

Rands gets one or more random entries from array(a copy).

从数组中随机拷贝size个元素项,构成slice返回。

func (*SortedIntArray) Range Uses

func (a *SortedIntArray) Range(start, end int) []int

Get items by range, returns array[start:end]. Be aware that, if in concurrent-safe usage, it returns a copy of slice; else a pointer to the underlying data.

将最右端(尾部)的size个数据项移出数组,并返回该数据项

func (*SortedIntArray) Remove Uses

func (a *SortedIntArray) Remove(index int) int

Remove an item by index.

删除指定索引的数据项, 调用方注意判断数组边界。

func (*SortedIntArray) Search Uses

func (a *SortedIntArray) Search(value int) (index int)

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

查找指定数值的索引位置,返回索引位置,如果查找不到则返回-1。

func (*SortedIntArray) SetArray Uses

func (a *SortedIntArray) SetArray(array []int) *SortedIntArray

Set the underlying slice array with the given <array> param.

设置底层数组变量.

func (*SortedIntArray) SetUnique Uses

func (a *SortedIntArray) SetUnique(unique bool) *SortedIntArray

Set unique mark to the array, which means it does not contain any repeated items. It also do unique check, remove all repeated items.

设置是否允许数组唯一.

func (*SortedIntArray) Slice Uses

func (a *SortedIntArray) Slice() []int

Get the underlying data of array. Be aware that, if in concurrent-safe usage, it returns a copy of slice; else a pointer to the underlying data.

返回原始数据数组.

func (*SortedIntArray) Sort Uses

func (a *SortedIntArray) Sort() *SortedIntArray

Sort the array in increasing order.

将数组排序(默认从低到高).

func (*SortedIntArray) SubSlice Uses

func (a *SortedIntArray) SubSlice(offset, size int) []int

Extract a slice of the array(If in concurrent safe usage, it returns a copy of the slice; else a pointer). It returns the sequence of elements from the array array as specified by the offset and length parameters.

返回根据offset和size参数所指定的数组中的一段序列。

func (*SortedIntArray) Sum Uses

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

Calculate the sum of values in an array.

对数组中的元素项求和。

func (*SortedIntArray) Unique Uses

func (a *SortedIntArray) Unique() *SortedIntArray

Do unique check, remove all repeated items.

清理数组中重复的元素项.

type SortedStringArray Uses

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

默认按照从小到大进行排序

func NewSortedStringArray Uses

func NewSortedStringArray(unsafe ...bool) *SortedStringArray

Create an empty sorted array. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

创建一个空的排序数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func NewSortedStringArrayFrom Uses

func NewSortedStringArrayFrom(array []string, unsafe ...bool) *SortedStringArray

Create an array with given slice <array>. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

通过给定的slice变量创建排序数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func NewSortedStringArrayFromCopy Uses

func NewSortedStringArrayFromCopy(array []string, unsafe ...bool) *SortedStringArray

Create an array from a copy of given slice <array>. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

通过给定的slice拷贝创建数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func NewSortedStringArraySize Uses

func NewSortedStringArraySize(cap int, unsafe ...bool) *SortedStringArray

Create a sorted array with given size and cap. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

创建一个指定大小的排序数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func (*SortedStringArray) Add Uses

func (a *SortedStringArray) Add(values ...string) *SortedStringArray

And values to sorted array, the array always keeps sorted.

添加数据项.

func (*SortedStringArray) Chunk Uses

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

Chunks an array into arrays with size elements. The last chunk may contain less than size elements.

将一个数组分割成多个数组,其中每个数组的单元数目由size决定。最后一个数组的单元数目可能会少于size个。

func (*SortedStringArray) Clear Uses

func (a *SortedStringArray) Clear() *SortedStringArray

Clear array.

清空数据数组。

func (*SortedStringArray) Clone Uses

func (a *SortedStringArray) Clone() (newArray *SortedStringArray)

Return a new array, which is a copy of current array.

克隆当前数组,返回当前数组的一个拷贝。

func (*SortedStringArray) Contains Uses

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

Check whether a value exists in the array.

查找指定数值是否存在。

func (*SortedStringArray) Get Uses

func (a *SortedStringArray) Get(index int) string

Get value by index.

获取指定索引的数据项, 调用方注意判断数组边界。

func (*SortedStringArray) Join Uses

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

Join array elements with a string.

使用glue字符串串连当前数组的元素项,构造成新的字符串返回。

func (*SortedStringArray) Len Uses

func (a *SortedStringArray) Len() int

Get the length of array.

数组长度。

func (*SortedStringArray) LockFunc Uses

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

Lock writing by callback function f.

使用自定义方法执行加锁修改操作。

func (*SortedStringArray) Merge Uses

func (a *SortedStringArray) Merge(array interface{}) *SortedStringArray

Merge two arrays. The parameter <array> can be any garray type or slice type. The difference between Merge and Add is Add supports only specified slice type, but Merge supports more variable types.

合并两个数组, 支持任意的garray数组类型及slice类型.

func (*SortedStringArray) PopLeft Uses

func (a *SortedStringArray) PopLeft() string

Push new items to the beginning of array.

将数据项添加到数组的最左端(索引为0)。

func (*SortedStringArray) PopLefts Uses

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

Pop <size> items from the beginning of array.

将最左端(首部)的size个数据项移出数组,并返回该数据项

func (*SortedStringArray) PopRand Uses

func (a *SortedStringArray) PopRand() string

PopRand picks an random item out of array.

随机将一个数据项移出数组,并返回该数据项。

func (*SortedStringArray) PopRands Uses

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

PopRands picks <size> items out of array.

随机将size个数据项移出数组,并返回该数据项。

func (*SortedStringArray) PopRight Uses

func (a *SortedStringArray) PopRight() string

Push new items to the end of array.

将数据项添加到数组的最右端(索引为length - 1)。

func (*SortedStringArray) PopRights Uses

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

Pop <size> items from the end of array.

将最右端(尾部)的size个数据项移出数组,并返回该数据项

func (*SortedStringArray) RLockFunc Uses

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

Lock reading by callback function f.

使用自定义方法执行加锁读取操作。

func (*SortedStringArray) Rand Uses

func (a *SortedStringArray) Rand() string

Rand gets one random entry from array.

从数组中随机获得1个元素项(不删除)。

func (*SortedStringArray) Rands Uses

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

Rands gets one or more random entries from array(a copy).

从数组中随机拷贝size个元素项,构成slice返回。

func (*SortedStringArray) Range Uses

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

Get items by range, returns array[start:end]. Be aware that, if in concurrent-safe usage, it returns a copy of slice; else a pointer to the underlying data.

将最右端(尾部)的size个数据项移出数组,并返回该数据项

func (*SortedStringArray) Remove Uses

func (a *SortedStringArray) Remove(index int) string

Remove an item by index.

删除指定索引的数据项, 调用方注意判断数组边界。

func (*SortedStringArray) Search Uses

func (a *SortedStringArray) Search(value string) (index int)

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

查找指定数值的索引位置,返回索引位置,如果查找不到则返回-1。

func (*SortedStringArray) SetArray Uses

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

Set the underlying slice array with the given <array> param.

设置底层数组变量.

func (*SortedStringArray) SetUnique Uses

func (a *SortedStringArray) SetUnique(unique bool) *SortedStringArray

Set unique mark to the array, which means it does not contain any repeated items. It also do unique check, remove all repeated items.

设置是否允许数组唯一.

func (*SortedStringArray) Slice Uses

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

Get the underlying data of array. Be aware that, if in concurrent-safe usage, it returns a copy of slice; else a pointer to the underlying data.

返回原始数据数组.

func (*SortedStringArray) Sort Uses

func (a *SortedStringArray) Sort() *SortedStringArray

Sort the array in increasing order.

将数组排序(默认从低到高).

func (*SortedStringArray) SubSlice Uses

func (a *SortedStringArray) SubSlice(offset, size int) []string

Extract a slice of the array(If in concurrent safe usage, it returns a copy of the slice; else a pointer). It returns the sequence of elements from the array array as specified by the offset and length parameters.

返回根据offset和size参数所指定的数组中的一段序列。

func (*SortedStringArray) Sum Uses

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

Calculate the sum of values in an array.

对数组中的元素项求和(将元素值转换为int类型后叠加)。

func (*SortedStringArray) Unique Uses

func (a *SortedStringArray) Unique() *SortedStringArray

Do unique check, remove all repeated items.

清理数组中重复的元素项.

type StringArray Uses

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

func NewStringArray Uses

func NewStringArray(unsafe ...bool) *StringArray

Create an empty array. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

创建一个空的数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func NewStringArrayFrom Uses

func NewStringArrayFrom(array []string, unsafe ...bool) *StringArray

Create an array with given slice <array>. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

通过给定的slice变量创建数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func NewStringArrayFromCopy Uses

func NewStringArrayFromCopy(array []string, unsafe ...bool) *StringArray

Create an array from a copy of given slice <array>. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

通过给定的slice拷贝创建数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func NewStringArraySize Uses

func NewStringArraySize(size int, cap int, unsafe ...bool) *StringArray

Create an array with given size and cap. The param <unsafe> used to specify whether using array with un-concurrent-safety, which is false in default, means concurrent-safe in default.

创建一个指定大小的数组对象,参数unsafe用于指定是否用于非并发安全场景,默认为false,表示并发安全。

func (*StringArray) Append Uses

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

See PushRight.

追加数据项, 等于: PushRight。

func (*StringArray) Chunk Uses

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

Chunks an array into arrays with size elements. The last chunk may contain less than size elements.

将一个数组分割成多个数组,其中每个数组的单元数目由size决定。最后一个数组的单元数目可能会少于size个。

func (*StringArray) Clear Uses

func (a *StringArray) Clear() *StringArray

Clear array.

清空数据数组。

func (*StringArray) Clone Uses

func (a *StringArray) Clone() (newArray *StringArray)

Return a new array, which is a copy of current array.

克隆当前数组,返回当前数组的一个拷贝。

func (*StringArray) Contains Uses

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

Check whether a value exists in the array.

查找指定数值是否存在。

func (*StringArray) Fill Uses

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

Fills an array with num entries of the value of the value parameter, keys starting at the start_index parameter.

用value参数的值将数组填充num个条目,位置由startIndex参数指定的开始。

func (*StringArray) Get Uses

func (a *StringArray) Get(index int) string

Get value by index.

获取指定索引的数据项, 调用方注意判断数组边界。

func (*StringArray) InsertAfter Uses

func (a *StringArray) InsertAfter(index int, value string) *StringArray

Insert the <value> to the back of <index>.

在当前索引位置前插入一个数据项, 调用方注意判断数组边界。

func (*StringArray) InsertBefore Uses

func (a *StringArray) InsertBefore(index int, value string) *StringArray

Insert the <value> to the front of <index>.

在当前索引位置前插入一个数据项, 调用方注意判断数组边界。

func (*StringArray) Join Uses

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

Join array elements with a string.

使用glue字符串串连当前数组的元素项,构造成新的字符串返回。

func (*StringArray) Len Uses

func (a *StringArray) Len() int

Get the length of array.

数组长度。

func (*StringArray) LockFunc Uses

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

Lock writing by callback function f.

使用自定义方法执行加锁修改操作。

func (*StringArray) Merge Uses

func (a *StringArray) Merge(array interface{}) *StringArray

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

合并两个数组, 支持任意的garray数组类型及slice类型.

func (*StringArray) Pad Uses

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

Pad array to the specified length with a value. If size is positive then the array is padded on the right, if it's negative then 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.

返回数组的一个拷贝,并用value将其填补到size指定的长度。 如果size为正数,则填补到数组的右侧,如果为负数则从左侧开始填补。 如果size的绝对值小于或等于数组的长度则没有任何填补。

func (*StringArray) PopLeft Uses

func (a *StringArray) PopLeft() string

Pop an item from the beginning of array.

将最左端(索引为0)的数据项移出数组,并返回该数据项。

func (*StringArray) PopLefts Uses

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

Pop <size> items from the beginning of array.

将最左端(首部)的size个数据项移出数组,并返回该数据项

func (*StringArray) PopRand Uses

func (a *StringArray) PopRand() string

PopRand picks an random item out of array.

随机将一个数据项移出数组,并返回该数据项。

func (*StringArray) PopRands Uses

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

PopRands picks <size> items out of array.

随机将size个数据项移出数组,并返回该数据项。

func (*StringArray) PopRight Uses

func (a *StringArray) PopRight() string

Pop an item from the end of array.

将最右端(索引为length - 1)的数据项移出数组,并返回该数据项。

func (*StringArray) PopRights Uses

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

Pop <size> items from the end of array.

将最右端(尾部)的size个数据项移出数组,并返回该数据项

func (*StringArray) PushLeft Uses

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

Push new items to the beginning of array.

将数据项添加到数组的最左端(索引为0)。

func (*StringArray) PushRight Uses

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

Push new items to the end of array.

将数据项添加到数组的最右端(索引为length - 1), 等于: Append。

func (*StringArray) RLockFunc Uses

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

Lock reading by callback function f.

使用自定义方法执行加锁读取操作。

func (*StringArray) Rand Uses

func (a *StringArray) Rand() string

Rand gets one random entry from array.

从数组中随机获得1个元素项(不删除)。

func (*StringArray) Rands Uses

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

Rands gets one or more random entries from array(a copy).

从数组中随机拷贝size个元素项,构成slice返回。

func (*StringArray) Range Uses

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

Get items by range, returns array[start:end]. Be aware that, if in concurrent-safe usage, it returns a copy of slice; else a pointer to the underlying data.

将最右端(尾部)的size个数据项移出数组,并返回该数据项

func (*StringArray) Remove Uses

func (a *StringArray) Remove(index int) string

Remove an item by index.

删除指定索引的数据项, 调用方注意判断数组边界。

func (*StringArray) Replace Uses

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

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

使用指定数组替换到对应的索引元素值.

func (*StringArray) Reverse Uses

func (a *StringArray) Reverse() *StringArray

Make array with elements in reverse order.

将当前数组反转。

func (*StringArray) Search Uses

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

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

查找指定数值的索引位置,返回索引位置,如果查找不到则返回-1。

func (*StringArray) Set Uses

func (a *StringArray) Set(index int, value string) *StringArray

Set value by index.

设置指定索引的数据项, 调用方注意判断数组边界。

func (*StringArray) SetArray Uses

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

Set the underlying slice array with the given <array> param.

设置底层数组变量.

func (*StringArray) Shuffle Uses

func (a *StringArray) Shuffle() *StringArray

Randomly shuffles the array.

随机打乱当前数组。

func (*StringArray) Slice Uses

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

Get the underlying data of array. Be aware that, if in concurrent-safe usage, it returns a copy of slice; else a pointer to the underlying data.

返回原始数据数组.

func (*StringArray) Sort Uses

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

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

将数组排序(默认从低到高).

func (*StringArray) SortFunc Uses

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

Sort the array by custom function <less>.

使用自定义的排序函数将数组重新排序.

func (*StringArray) SubSlice Uses

func (a *StringArray) SubSlice(offset, size int) []string

Extract a slice of the array(If in concurrent safe usage, it returns a copy of the slice; else a pointer). It returns the sequence of elements from the array array as specified by the offset and length parameters.

返回根据offset和size参数所指定的数组中的一段序列。

func (*StringArray) Sum Uses

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

Calculate the sum of values in an array.

对数组中的元素项求和(将元素值转换为int类型后叠加)。

func (*StringArray) Unique Uses

func (a *StringArray) Unique() *StringArray

Unique the array, clear repeated values.

清理数组中重复的元素项。

Package garray imports 9 packages (graph). Updated 2019-03-22. Refresh now. Tools for package owners.