gf: github.com/gogf/gf/g/container/garray Index | Examples | Files

package garray

import "github.com/gogf/gf/g/container/garray"

Package garray provides concurrent-safe/unsafe 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

New creates and returns an empty array. The param <unsafe> used to specify whether using array in un-concurrent-safety, which is false in default.

func NewArray Uses

func NewArray(unsafe ...bool) *Array

See New.

func NewArrayFrom Uses

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

NewArrayFrom creates and returns an array with given slice <array>. The param <unsafe> used to specify whether using array in un-concurrent-safety, which is false in default.

func NewArrayFromCopy Uses

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

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

func NewArraySize Uses

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

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

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.

func (*Array) Chunk Uses

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

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 (*Array) Clear Uses

func (a *Array) Clear() *Array

Clear deletes all items of current array.

func (*Array) Clone Uses

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

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

func (*Array) Contains Uses

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

Contains checks whether a value exists in the array.

func (*Array) CountValues Uses

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

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

func (*Array) Fill Uses

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

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

func (*Array) Get Uses

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

Get returns the value of the specified index, the caller should notice the boundary of the array.

func (*Array) InsertAfter Uses

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

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

func (*Array) InsertBefore Uses

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

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

func (*Array) Join Uses

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

Join joins array elements with a string <glue>.

func (*Array) Len Uses

func (a *Array) Len() int

Len returns the length of array.

func (*Array) LockFunc Uses

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

LockFunc locks writing by callback function <f>.

func (*Array) Merge Uses

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

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 (*Array) Pad Uses

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

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 (*Array) PopLeft Uses

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

PopLeft pops and returns an item from the beginning of array.

func (*Array) PopLefts Uses

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

PopLefts pops and returns <size> items from the beginning of array.

func (*Array) PopRand Uses

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

PopRand randomly pops and return an item out of array.

func (*Array) PopRands Uses

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

PopRands randomly pops and returns <size> items out of array.

func (*Array) PopRight Uses

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

PopRight pops and returns an item from the end of array.

func (*Array) PopRights Uses

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

PopRights pops and returns <size> items from the end of array.

func (*Array) PushLeft Uses

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

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

func (*Array) PushRight Uses

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

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

func (*Array) RLockFunc Uses

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

RLockFunc locks reading by callback function <f>.

func (*Array) Rand Uses

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

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

func (*Array) Rands Uses

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

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

func (*Array) Range Uses

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

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.

func (*Array) Remove Uses

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

Remove removes an item by index.

func (*Array) Replace Uses

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

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

func (*Array) Reverse Uses

func (a *Array) Reverse() *Array

Reverse makes array with elements in reverse order.

func (*Array) Search Uses

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

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

func (*Array) Set Uses

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

Set sets value to specified index.

func (*Array) SetArray Uses

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

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

func (*Array) Shuffle Uses

func (a *Array) Shuffle() *Array

Shuffle randomly shuffles the array.

func (*Array) Slice Uses

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

Slice returns the underlying data of array. Notice, 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

SortFunc sorts 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{}

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.

func (*Array) Sum Uses

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

Sum returns the sum of values in an array.

func (*Array) Unique Uses

func (a *Array) Unique() *Array

Unique uniques the array, clear repeated items.

type IntArray Uses

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

func NewIntArray Uses

func NewIntArray(unsafe ...bool) *IntArray

NewIntArray creates and returns an empty array. The param <unsafe> used to specify whether using array in un-concurrent-safety, which is false in default.

func NewIntArrayFrom Uses

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

NewIntArrayFrom creates and returns an array with given slice <array>. The param <unsafe> used to specify whether using array in un-concurrent-safety, which is false in default.

func NewIntArrayFromCopy Uses

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

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

func NewIntArraySize Uses

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

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

func (*IntArray) Append Uses

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

See PushRight.

func (*IntArray) Chunk Uses

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

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 (*IntArray) Clear Uses

func (a *IntArray) Clear() *IntArray

Clear deletes all items of current array.

func (*IntArray) Clone Uses

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

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

func (*IntArray) Contains Uses

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

Contains checks whether a value exists in the array.

func (*IntArray) CountValues Uses

func (a *IntArray) CountValues() map[int]int

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

func (*IntArray) Fill Uses

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

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

func (*IntArray) Get Uses

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

Get returns the value of the specified index, the caller should notice the boundary of the array.

func (*IntArray) InsertAfter Uses

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

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

func (*IntArray) InsertBefore Uses

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

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

func (*IntArray) Join Uses

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

Join joins array elements with a string <glue>.

func (*IntArray) Len Uses

func (a *IntArray) Len() int

Len returns the length of array.

func (*IntArray) LockFunc Uses

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

LockFunc locks writing by callback function <f>.

func (*IntArray) Merge Uses

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

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 (*IntArray) Pad Uses

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

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 (*IntArray) PopLeft Uses

func (a *IntArray) PopLeft() int

PopLeft pops and returns an item from the beginning of array.

func (*IntArray) PopLefts Uses

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

PopLefts pops and returns <size> items from the beginning of array.

func (*IntArray) PopRand Uses

func (a *IntArray) PopRand() int

PopRand randomly pops and return an item out of array.

func (*IntArray) PopRands Uses

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

PopRands randomly pops and returns <size> items out of array.

func (*IntArray) PopRight Uses

func (a *IntArray) PopRight() int

PopRight pops and returns an item from the end of array.

func (*IntArray) PopRights Uses

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

PopRights pops and returns <size> items from the end of array.

func (*IntArray) PushLeft Uses

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

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

func (*IntArray) PushRight Uses

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

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

func (*IntArray) RLockFunc Uses

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

RLockFunc locks reading by callback function <f>.

func (*IntArray) Rand Uses

func (a *IntArray) Rand() int

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

func (*IntArray) Rands Uses

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

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

func (*IntArray) Range Uses

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

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.

func (*IntArray) Remove Uses

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

Remove removes an item by index.

func (*IntArray) Replace Uses

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

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

func (*IntArray) Reverse Uses

func (a *IntArray) Reverse() *IntArray

Reverse makes array with elements in reverse order.

func (*IntArray) Search Uses

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

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

func (*IntArray) Set Uses

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

Set sets value to specified index.

func (*IntArray) SetArray Uses

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

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

func (*IntArray) Shuffle Uses

func (a *IntArray) Shuffle() *IntArray

Shuffle randomly shuffles the array.

func (*IntArray) Slice Uses

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

Slice returns the underlying data of array. Notice, 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 sorts 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

SortFunc sorts the array by custom function <less>.

func (*IntArray) String Uses

func (a *IntArray) String() string

String returns current array as a string.

func (*IntArray) SubSlice Uses

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

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.

func (*IntArray) Sum Uses

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

Sum returns the sum of values in an array.

func (*IntArray) Unique Uses

func (a *IntArray) Unique() *IntArray

Unique uniques the array, clear repeated items.

type SortedArray Uses

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

It's using increasing order in default.

func NewSortedArray Uses

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

NewSortedArray creates and returns an empty sorted array. The param <unsafe> used to specify whether using array in un-concurrent-safety, which is false in default. The param <comparator> 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;

func NewSortedArrayFrom Uses

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

NewSortedArrayFrom creates and returns an sorted array with given slice <array>. The param <unsafe> used to specify whether using array in un-concurrent-safety, which is false in default.

func NewSortedArrayFromCopy Uses

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

NewSortedArrayFromCopy creates and returns an sorted array from a copy of given slice <array>. The param <unsafe> used to specify whether using array in un-concurrent-safety, which is false in default.

func NewSortedArraySize Uses

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

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

func (*SortedArray) Add Uses

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

Add adds one or multiple values to sorted array, the array always keeps sorted.

func (*SortedArray) Chunk Uses

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

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 (*SortedArray) Clear Uses

func (a *SortedArray) Clear() *SortedArray

Clear deletes all items of current array.

func (*SortedArray) Clone Uses

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

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

func (*SortedArray) Contains Uses

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

Contains checks whether a value exists in the array.

func (*SortedArray) CountValues Uses

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

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

func (*SortedArray) Get Uses

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

Get returns the value of the specified index, the caller should notice the boundary of the array.

func (*SortedArray) Join Uses

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

Join joins array elements with a string <glue>.

func (*SortedArray) Len Uses

func (a *SortedArray) Len() int

Len returns the length of array.

func (*SortedArray) LockFunc Uses

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

LockFunc locks writing by callback function <f>.

func (*SortedArray) Merge Uses

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

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 (*SortedArray) PopLeft Uses

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

PopLeft pops and returns an item from the beginning of array.

func (*SortedArray) PopLefts Uses

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

PopLefts pops and returns <size> items from the beginning of array.

func (*SortedArray) PopRand Uses

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

PopRand randomly pops and return an item out of array.

func (*SortedArray) PopRands Uses

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

PopRands randomly pops and returns <size> items out of array.

func (*SortedArray) PopRight Uses

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

PopRight pops and returns an item from the end of array.

func (*SortedArray) PopRights Uses

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

PopRights pops and returns <size> items from the end of array.

func (*SortedArray) RLockFunc Uses

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

RLockFunc locks reading by callback function <f>.

func (*SortedArray) Rand Uses

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

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

func (*SortedArray) Rands Uses

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

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

func (*SortedArray) Range Uses

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

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.

func (*SortedArray) Remove Uses

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

Remove removes an item by index.

func (*SortedArray) Search Uses

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

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

func (*SortedArray) SetArray Uses

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

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

func (*SortedArray) SetUnique Uses

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

SetUnique sets 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{}

Slice returns the underlying data of array. Notice, 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 sorts the array in increasing order. The param <reverse> controls whether sort in increasing order(default) or decreasing order

func (*SortedArray) String Uses

func (a *SortedArray) String() string

String returns current array as a string.

func (*SortedArray) SubSlice Uses

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

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.

func (*SortedArray) Sum Uses

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

Sum returns the sum of values in an array.

func (*SortedArray) Unique Uses

func (a *SortedArray) Unique() *SortedArray

Unique uniques the array, clear repeated items.

type SortedIntArray Uses

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

It's using increasing order in default.

func NewSortedIntArray Uses

func NewSortedIntArray(unsafe ...bool) *SortedIntArray

NewSortedIntArray creates and returns an empty sorted array. The param <unsafe> used to specify whether using array in un-concurrent-safety, which is false in default.

func NewSortedIntArrayFrom Uses

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

NewIntArrayFrom creates and returns an sorted array with given slice <array>. The param <unsafe> used to specify whether using array in un-concurrent-safety, which is false in default.

func NewSortedIntArrayFromCopy Uses

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

NewSortedIntArrayFromCopy creates and returns an sorted array from a copy of given slice <array>. The param <unsafe> used to specify whether using array in un-concurrent-safety, which is false in default.

func NewSortedIntArraySize Uses

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

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

func (*SortedIntArray) Add Uses

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

Add adds one or multiple values to sorted array, the array always keeps sorted.

func (*SortedIntArray) Chunk Uses

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

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 (*SortedIntArray) Clear Uses

func (a *SortedIntArray) Clear() *SortedIntArray

Clear deletes all items of current array.

func (*SortedIntArray) Clone Uses

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

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

func (*SortedIntArray) Contains Uses

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

Contains checks whether a value exists in the array.

func (*SortedIntArray) CountValues Uses

func (a *SortedIntArray) CountValues() map[int]int

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

func (*SortedIntArray) Get Uses

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

Get returns the value of the specified index, the caller should notice the boundary of the array.

func (*SortedIntArray) Join Uses

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

Join joins array elements with a string <glue>.

func (*SortedIntArray) Len Uses

func (a *SortedIntArray) Len() int

Len returns the length of array.

func (*SortedIntArray) LockFunc Uses

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

LockFunc locks writing by callback function <f>.

func (*SortedIntArray) Merge Uses

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

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 (*SortedIntArray) PopLeft Uses

func (a *SortedIntArray) PopLeft() int

PopLeft pops and returns an item from the beginning of array.

func (*SortedIntArray) PopLefts Uses

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

PopLefts pops and returns <size> items from the beginning of array.

func (*SortedIntArray) PopRand Uses

func (a *SortedIntArray) PopRand() int

PopRand randomly pops and return an item out of array.

func (*SortedIntArray) PopRands Uses

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

PopRands randomly pops and returns <size> items out of array.

func (*SortedIntArray) PopRight Uses

func (a *SortedIntArray) PopRight() int

PopRight pops and returns an item from the end of array.

func (*SortedIntArray) PopRights Uses

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

PopRights pops and returns <size> items from the end of array.

func (*SortedIntArray) RLockFunc Uses

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

RLockFunc locks reading by callback function <f>.

func (*SortedIntArray) Rand Uses

func (a *SortedIntArray) Rand() int

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

func (*SortedIntArray) Rands Uses

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

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

func (*SortedIntArray) Range Uses

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

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.

func (*SortedIntArray) Remove Uses

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

Remove removes an item by index.

func (*SortedIntArray) Search Uses

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

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

func (*SortedIntArray) SetArray Uses

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

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

func (*SortedIntArray) SetUnique Uses

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

SetUnique sets 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

Slice returns the underlying data of array. Notice, 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 sorts the array in increasing order. The param <reverse> controls whether sort in increasing order(default) or decreasing order.

func (*SortedIntArray) String Uses

func (a *SortedIntArray) String() string

String returns current array as a string.

func (*SortedIntArray) SubSlice Uses

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

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.

func (*SortedIntArray) Sum Uses

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

Sum returns the sum of values in an array.

func (*SortedIntArray) Unique Uses

func (a *SortedIntArray) Unique() *SortedIntArray

Unique uniques the array, clear repeated items.

type SortedStringArray Uses

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

It's using increasing order in default.

func NewSortedStringArray Uses

func NewSortedStringArray(unsafe ...bool) *SortedStringArray

NewSortedStringArray creates and returns an empty sorted array. The param <unsafe> used to specify whether using array in un-concurrent-safety, which is false in default.

func NewSortedStringArrayFrom Uses

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

NewSortedStringArrayFrom creates and returns an sorted array with given slice <array>. The param <unsafe> used to specify whether using array in un-concurrent-safety, which is false in default.

func NewSortedStringArrayFromCopy Uses

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

NewSortedStringArrayFromCopy creates and returns an sorted array from a copy of given slice <array>. The param <unsafe> used to specify whether using array in un-concurrent-safety, which is false in default.

func NewSortedStringArraySize Uses

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

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

func (*SortedStringArray) Add Uses

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

Add adds one or multiple values to sorted array, the array always keeps sorted.

func (*SortedStringArray) Chunk Uses

func (a *SortedStringArray) 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 (*SortedStringArray) Clear Uses

func (a *SortedStringArray) Clear() *SortedStringArray

Clear deletes all items of current array.

func (*SortedStringArray) Clone Uses

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

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

func (*SortedStringArray) Contains Uses

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

Contains checks whether a value exists in the array.

func (*SortedStringArray) CountValues Uses

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

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

func (*SortedStringArray) Get Uses

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

Get returns the value of the specified index, the caller should notice the boundary of the array.

func (*SortedStringArray) Join Uses

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

Join joins array elements with a string <glue>.

func (*SortedStringArray) Len Uses

func (a *SortedStringArray) Len() int

Len returns the length of array.

func (*SortedStringArray) LockFunc Uses

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

LockFunc locks writing by callback function <f>.

func (*SortedStringArray) Merge Uses

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

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 (*SortedStringArray) PopLeft Uses

func (a *SortedStringArray) PopLeft() string

PopLeft pops and returns an item from the beginning of array.

func (*SortedStringArray) PopLefts Uses

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

PopLefts pops and returns <size> items from the beginning of array.

func (*SortedStringArray) PopRand Uses

func (a *SortedStringArray) PopRand() string

PopRand randomly pops and return an item out of array.

func (*SortedStringArray) PopRands Uses

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

PopRands randomly pops and returns <size> items out of array.

func (*SortedStringArray) PopRight Uses

func (a *SortedStringArray) PopRight() string

PopRight pops and returns an item from the end of array.

func (*SortedStringArray) PopRights Uses

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

PopRights pops and returns <size> items from the end of array.

func (*SortedStringArray) RLockFunc Uses

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

RLockFunc locks reading by callback function <f>.

func (*SortedStringArray) Rand Uses

func (a *SortedStringArray) Rand() string

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

func (*SortedStringArray) Rands Uses

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

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

func (*SortedStringArray) Range Uses

func (a *SortedStringArray) Range(start, 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.

func (*SortedStringArray) Remove Uses

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

Remove removes an item by index.

func (*SortedStringArray) Search Uses

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

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

func (*SortedStringArray) SetArray Uses

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

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

func (*SortedStringArray) SetUnique Uses

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

SetUnique sets 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

Slice returns the underlying data of array. Notice, 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 sorts the array in increasing order. The param <reverse> controls whether sort in increasing order(default) or decreasing order.

func (*SortedStringArray) String Uses

func (a *SortedStringArray) String() string

String returns current array as a string.

func (*SortedStringArray) SubSlice Uses

func (a *SortedStringArray) SubSlice(offset, size 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.

func (*SortedStringArray) Sum Uses

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

Sum returns the sum of values in an array.

func (*SortedStringArray) Unique Uses

func (a *SortedStringArray) Unique() *SortedStringArray

Unique uniques the array, clear repeated items.

type StringArray Uses

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

func NewStringArray Uses

func NewStringArray(unsafe ...bool) *StringArray

NewStringArray creates and returns an empty array. The param <unsafe> used to specify whether using array in un-concurrent-safety, which is false in default.

func NewStringArrayFrom Uses

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

NewStringArrayFrom creates and returns an array with given slice <array>. The param <unsafe> used to specify whether using array in un-concurrent-safety, which is false in default.

func NewStringArrayFromCopy Uses

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

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

func NewStringArraySize Uses

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

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

func (*StringArray) Append Uses

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

See PushRight.

func (*StringArray) Chunk Uses

func (a *StringArray) 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 (*StringArray) Clear Uses

func (a *StringArray) Clear() *StringArray

Clear deletes all items of current array.

func (*StringArray) Clone Uses

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

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

func (*StringArray) Contains Uses

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

Contains checks whether a value exists in the array.

func (*StringArray) CountValues Uses

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

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

func (*StringArray) Fill Uses

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

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

func (*StringArray) Get Uses

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

Get returns the value of the specified index, the caller should notice the boundary of the array.

func (*StringArray) InsertAfter Uses

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

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

func (*StringArray) InsertBefore Uses

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

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

func (*StringArray) Join Uses

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

Join joins array elements with a string <glue>.

func (*StringArray) Len Uses

func (a *StringArray) Len() int

Len returns the length of array.

func (*StringArray) LockFunc Uses

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

LockFunc locks writing by callback function <f>.

func (*StringArray) Merge Uses

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

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 (*StringArray) Pad Uses

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

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 (*StringArray) PopLeft Uses

func (a *StringArray) PopLeft() string

PopLeft pops and returns an item from the beginning of array.

func (*StringArray) PopLefts Uses

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

PopLefts pops and returns <size> items from the beginning of array.

func (*StringArray) PopRand Uses

func (a *StringArray) PopRand() string

PopRand randomly pops and return an item out of array.

func (*StringArray) PopRands Uses

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

PopRands randomly pops and returns <size> items out of array.

func (*StringArray) PopRight Uses

func (a *StringArray) PopRight() string

PopRight pops and returns an item from the end of array.

func (*StringArray) PopRights Uses

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

PopRights pops and returns <size> items from the end of array.

func (*StringArray) PushLeft Uses

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

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

func (*StringArray) PushRight Uses

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

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

func (*StringArray) RLockFunc Uses

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

RLockFunc locks reading by callback function <f>.

func (*StringArray) Rand Uses

func (a *StringArray) Rand() string

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

func (*StringArray) Rands Uses

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

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

func (*StringArray) Range Uses

func (a *StringArray) Range(start, 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.

func (*StringArray) Remove Uses

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

Remove removes an item by index.

func (*StringArray) Replace Uses

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

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

func (*StringArray) Reverse Uses

func (a *StringArray) Reverse() *StringArray

Reverse makes array with elements in reverse order.

func (*StringArray) Search Uses

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

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

func (*StringArray) Set Uses

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

Set sets value to specified index.

func (*StringArray) SetArray Uses

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

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

func (*StringArray) Shuffle Uses

func (a *StringArray) Shuffle() *StringArray

Shuffle randomly shuffles the array.

func (*StringArray) Slice Uses

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

Slice returns the underlying data of array. Notice, 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 sorts 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

SortFunc sorts the array by custom function <less>.

func (*StringArray) String Uses

func (a *StringArray) String() string

String returns current array as a string.

func (*StringArray) SubSlice Uses

func (a *StringArray) SubSlice(offset, size 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.

func (*StringArray) Sum Uses

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

Sum returns the sum of values in an array.

func (*StringArray) Unique Uses

func (a *StringArray) Unique() *StringArray

Unique uniques the array, clear repeated items.

Package garray imports 9 packages (graph) and is imported by 12 packages. Updated 2019-05-11. Refresh now. Tools for package owners.