Documentation ¶
Overview ¶
Package garray provides concurrent-safe/unsafe arrays.
Example (Basic) ¶
package main import ( "fmt" "github.com/gogf/gf/container/garray" ) func main() { // 创建普通的数组 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] []
Example (Merge) ¶
package main import ( "fmt" "github.com/gogf/gf/container/garray" ) func main() { 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]
Example (Pop) ¶
package main import ( "fmt" "github.com/gogf/gf/container/garray" ) func main() { 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]
Example (Rand) ¶
package main import ( "fmt" "github.com/gogf/gf/container/garray" ) func main() { array := garray.NewFrom([]interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9}) // 随机返回两个数据项(不删除) fmt.Println(array.Rands(2)) fmt.Println(array.PopRand()) }
Output:
Index ¶
- type Array
- func New(safe ...bool) *Array
- func NewArray(safe ...bool) *Array
- func NewArrayFrom(array []interface{}, safe ...bool) *Array
- func NewArrayFromCopy(array []interface{}, safe ...bool) *Array
- func NewArrayRange(start, end, step int, safe ...bool) *Array
- func NewArraySize(size int, cap int, safe ...bool) *Array
- func NewFrom(array []interface{}, safe ...bool) *Array
- func NewFromCopy(array []interface{}, safe ...bool) *Array
- func (a *Array) Append(value ...interface{}) *Array
- func (a *Array) Chunk(size int) [][]interface{}
- func (a *Array) Clear() *Array
- func (a *Array) Clone() (newArray *Array)
- func (a *Array) Contains(value interface{}) bool
- func (a *Array) CountValues() map[interface{}]int
- func (a *Array) Fill(startIndex int, num int, value interface{}) *Array
- func (a *Array) FilterEmpty() *Array
- func (a *Array) FilterNil() *Array
- func (a *Array) Get(index int) interface{}
- func (a *Array) InsertAfter(index int, value interface{}) *Array
- func (a *Array) InsertBefore(index int, value interface{}) *Array
- func (a *Array) Interfaces() []interface{}
- func (a *Array) Iterator(f func(k int, v interface{}) bool)
- func (a *Array) IteratorAsc(f func(k int, v interface{}) bool)
- func (a *Array) IteratorDesc(f func(k int, v interface{}) bool)
- func (a *Array) Join(glue string) string
- func (a *Array) Len() int
- func (a *Array) LockFunc(f func(array []interface{})) *Array
- func (a *Array) MarshalJSON() ([]byte, error)
- func (a *Array) Merge(array interface{}) *Array
- func (a *Array) Pad(size int, val interface{}) *Array
- func (a *Array) PopLeft() interface{}
- func (a *Array) PopLefts(size int) []interface{}
- func (a *Array) PopRand() interface{}
- func (a *Array) PopRands(size int) []interface{}
- func (a *Array) PopRight() interface{}
- func (a *Array) PopRights(size int) []interface{}
- func (a *Array) PushLeft(value ...interface{}) *Array
- func (a *Array) PushRight(value ...interface{}) *Array
- func (a *Array) RLockFunc(f func(array []interface{})) *Array
- func (a *Array) Rand() interface{}
- func (a *Array) Rands(size int) []interface{}
- func (a *Array) Range(start int, end ...int) []interface{}
- func (a *Array) Remove(index int) interface{}
- func (a *Array) RemoveValue(value interface{}) bool
- func (a *Array) Replace(array []interface{}) *Array
- func (a *Array) Reverse() *Array
- func (a *Array) Search(value interface{}) int
- func (a *Array) Set(index int, value interface{}) *Array
- func (a *Array) SetArray(array []interface{}) *Array
- func (a *Array) Shuffle() *Array
- func (a *Array) Slice() []interface{}
- func (a *Array) SortFunc(less func(v1, v2 interface{}) bool) *Array
- func (a *Array) String() string
- func (a *Array) SubSlice(offset int, length ...int) []interface{}
- func (a *Array) Sum() (sum int)
- func (a *Array) Unique() *Array
- func (a *Array) UnmarshalJSON(b []byte) error
- func (a *Array) UnmarshalValue(value interface{}) error
- type IntArray
- func (a *IntArray) Append(value ...int) *IntArray
- func (a *IntArray) Chunk(size int) [][]int
- func (a *IntArray) Clear() *IntArray
- func (a *IntArray) Clone() (newArray *IntArray)
- func (a *IntArray) Contains(value int) bool
- func (a *IntArray) CountValues() map[int]int
- func (a *IntArray) Fill(startIndex int, num int, value int) *IntArray
- func (a *IntArray) FilterEmpty() *IntArray
- func (a *IntArray) Get(index int) int
- func (a *IntArray) InsertAfter(index int, value int) *IntArray
- func (a *IntArray) InsertBefore(index int, value int) *IntArray
- func (a *IntArray) Interfaces() []interface{}
- func (a *IntArray) Iterator(f func(k int, v int) bool)
- func (a *IntArray) IteratorAsc(f func(k int, v int) bool)
- func (a *IntArray) IteratorDesc(f func(k int, v int) bool)
- func (a *IntArray) Join(glue string) string
- func (a *IntArray) Len() int
- func (a *IntArray) LockFunc(f func(array []int)) *IntArray
- func (a *IntArray) MarshalJSON() ([]byte, error)
- func (a *IntArray) Merge(array interface{}) *IntArray
- func (a *IntArray) Pad(size int, value int) *IntArray
- func (a *IntArray) PopLeft() int
- func (a *IntArray) PopLefts(size int) []int
- func (a *IntArray) PopRand() int
- func (a *IntArray) PopRands(size int) []int
- func (a *IntArray) PopRight() int
- func (a *IntArray) PopRights(size int) []int
- func (a *IntArray) PushLeft(value ...int) *IntArray
- func (a *IntArray) PushRight(value ...int) *IntArray
- func (a *IntArray) RLockFunc(f func(array []int)) *IntArray
- func (a *IntArray) Rand() int
- func (a *IntArray) Rands(size int) []int
- func (a *IntArray) Range(start int, end ...int) []int
- func (a *IntArray) Remove(index int) int
- func (a *IntArray) RemoveValue(value int) bool
- func (a *IntArray) Replace(array []int) *IntArray
- func (a *IntArray) Reverse() *IntArray
- func (a *IntArray) Search(value int) int
- func (a *IntArray) Set(index int, value int) *IntArray
- func (a *IntArray) SetArray(array []int) *IntArray
- func (a *IntArray) Shuffle() *IntArray
- func (a *IntArray) Slice() []int
- func (a *IntArray) Sort(reverse ...bool) *IntArray
- func (a *IntArray) SortFunc(less func(v1, v2 int) bool) *IntArray
- func (a *IntArray) String() string
- func (a *IntArray) SubSlice(offset int, length ...int) []int
- func (a *IntArray) Sum() (sum int)
- func (a *IntArray) Unique() *IntArray
- func (a *IntArray) UnmarshalJSON(b []byte) error
- func (a *IntArray) UnmarshalValue(value interface{}) error
- type SortedArray
- func NewSortedArray(comparator func(a, b interface{}) int, safe ...bool) *SortedArray
- func NewSortedArrayFrom(array []interface{}, comparator func(a, b interface{}) int, safe ...bool) *SortedArray
- func NewSortedArrayFromCopy(array []interface{}, comparator func(a, b interface{}) int, safe ...bool) *SortedArray
- func NewSortedArrayRange(start, end, step int, comparator func(a, b interface{}) int, safe ...bool) *SortedArray
- func NewSortedArraySize(cap int, comparator func(a, b interface{}) int, safe ...bool) *SortedArray
- func (a *SortedArray) Add(values ...interface{}) *SortedArray
- func (a *SortedArray) Chunk(size int) [][]interface{}
- func (a *SortedArray) Clear() *SortedArray
- func (a *SortedArray) Clone() (newArray *SortedArray)
- func (a *SortedArray) Contains(value interface{}) bool
- func (a *SortedArray) CountValues() map[interface{}]int
- func (a *SortedArray) FilterEmpty() *SortedArray
- func (a *SortedArray) FilterNil() *SortedArray
- func (a *SortedArray) Get(index int) interface{}
- func (a *SortedArray) Interfaces() []interface{}
- func (a *SortedArray) Iterator(f func(k int, v interface{}) bool)
- func (a *SortedArray) IteratorAsc(f func(k int, v interface{}) bool)
- func (a *SortedArray) IteratorDesc(f func(k int, v interface{}) bool)
- func (a *SortedArray) Join(glue string) string
- func (a *SortedArray) Len() int
- func (a *SortedArray) LockFunc(f func(array []interface{})) *SortedArray
- func (a *SortedArray) MarshalJSON() ([]byte, error)
- func (a *SortedArray) Merge(array interface{}) *SortedArray
- func (a *SortedArray) PopLeft() interface{}
- func (a *SortedArray) PopLefts(size int) []interface{}
- func (a *SortedArray) PopRand() interface{}
- func (a *SortedArray) PopRands(size int) []interface{}
- func (a *SortedArray) PopRight() interface{}
- func (a *SortedArray) PopRights(size int) []interface{}
- func (a *SortedArray) RLockFunc(f func(array []interface{})) *SortedArray
- func (a *SortedArray) Rand() interface{}
- func (a *SortedArray) Rands(size int) []interface{}
- func (a *SortedArray) Range(start int, end ...int) []interface{}
- func (a *SortedArray) Remove(index int) interface{}
- func (a *SortedArray) RemoveValue(value interface{}) bool
- func (a *SortedArray) Search(value interface{}) (index int)
- func (a *SortedArray) SetArray(array []interface{}) *SortedArray
- func (a *SortedArray) SetComparator(comparator func(a, b interface{}) int)
- func (a *SortedArray) SetUnique(unique bool) *SortedArray
- func (a *SortedArray) Slice() []interface{}
- func (a *SortedArray) Sort() *SortedArray
- func (a *SortedArray) String() string
- func (a *SortedArray) SubSlice(offset int, length ...int) []interface{}
- func (a *SortedArray) Sum() (sum int)
- func (a *SortedArray) Unique() *SortedArray
- func (a *SortedArray) UnmarshalJSON(b []byte) error
- func (a *SortedArray) UnmarshalValue(value interface{}) (err error)
- type SortedIntArray
- func NewSortedIntArray(safe ...bool) *SortedIntArray
- func NewSortedIntArrayComparator(comparator func(a, b int) int, safe ...bool) *SortedIntArray
- func NewSortedIntArrayFrom(array []int, safe ...bool) *SortedIntArray
- func NewSortedIntArrayFromCopy(array []int, safe ...bool) *SortedIntArray
- func NewSortedIntArrayRange(start, end, step int, safe ...bool) *SortedIntArray
- func NewSortedIntArraySize(cap int, safe ...bool) *SortedIntArray
- func (a *SortedIntArray) Add(values ...int) *SortedIntArray
- func (a *SortedIntArray) Chunk(size int) [][]int
- func (a *SortedIntArray) Clear() *SortedIntArray
- func (a *SortedIntArray) Clone() (newArray *SortedIntArray)
- func (a *SortedIntArray) Contains(value int) bool
- func (a *SortedIntArray) CountValues() map[int]int
- func (a *SortedIntArray) FilterEmpty() *SortedIntArray
- func (a *SortedIntArray) Get(index int) int
- func (a *SortedIntArray) Interfaces() []interface{}
- func (a *SortedIntArray) Iterator(f func(k int, v int) bool)
- func (a *SortedIntArray) IteratorAsc(f func(k int, v int) bool)
- func (a *SortedIntArray) IteratorDesc(f func(k int, v int) bool)
- func (a *SortedIntArray) Join(glue string) string
- func (a *SortedIntArray) Len() int
- func (a *SortedIntArray) LockFunc(f func(array []int)) *SortedIntArray
- func (a *SortedIntArray) MarshalJSON() ([]byte, error)
- func (a *SortedIntArray) Merge(array interface{}) *SortedIntArray
- func (a *SortedIntArray) PopLeft() int
- func (a *SortedIntArray) PopLefts(size int) []int
- func (a *SortedIntArray) PopRand() int
- func (a *SortedIntArray) PopRands(size int) []int
- func (a *SortedIntArray) PopRight() int
- func (a *SortedIntArray) PopRights(size int) []int
- func (a *SortedIntArray) RLockFunc(f func(array []int)) *SortedIntArray
- func (a *SortedIntArray) Rand() int
- func (a *SortedIntArray) Rands(size int) []int
- func (a *SortedIntArray) Range(start int, end ...int) []int
- func (a *SortedIntArray) Remove(index int) int
- func (a *SortedIntArray) RemoveValue(value int) bool
- func (a *SortedIntArray) Search(value int) (index int)
- func (a *SortedIntArray) SetArray(array []int) *SortedIntArray
- func (a *SortedIntArray) SetUnique(unique bool) *SortedIntArray
- func (a *SortedIntArray) Slice() []int
- func (a *SortedIntArray) Sort() *SortedIntArray
- func (a *SortedIntArray) String() string
- func (a *SortedIntArray) SubSlice(offset int, length ...int) []int
- func (a *SortedIntArray) Sum() (sum int)
- func (a *SortedIntArray) Unique() *SortedIntArray
- func (a *SortedIntArray) UnmarshalJSON(b []byte) error
- func (a *SortedIntArray) UnmarshalValue(value interface{}) (err error)
- type SortedStrArray
- func NewSortedStrArray(safe ...bool) *SortedStrArray
- func NewSortedStrArrayComparator(comparator func(a, b string) int, safe ...bool) *SortedStrArray
- func NewSortedStrArrayFrom(array []string, safe ...bool) *SortedStrArray
- func NewSortedStrArrayFromCopy(array []string, safe ...bool) *SortedStrArray
- func NewSortedStrArraySize(cap int, safe ...bool) *SortedStrArray
- func (a *SortedStrArray) Add(values ...string) *SortedStrArray
- func (a *SortedStrArray) Chunk(size int) [][]string
- func (a *SortedStrArray) Clear() *SortedStrArray
- func (a *SortedStrArray) Clone() (newArray *SortedStrArray)
- func (a *SortedStrArray) Contains(value string) bool
- func (a *SortedStrArray) CountValues() map[string]int
- func (a *SortedStrArray) FilterEmpty() *SortedStrArray
- func (a *SortedStrArray) Get(index int) string
- func (a *SortedStrArray) Interfaces() []interface{}
- func (a *SortedStrArray) Iterator(f func(k int, v string) bool)
- func (a *SortedStrArray) IteratorAsc(f func(k int, v string) bool)
- func (a *SortedStrArray) IteratorDesc(f func(k int, v string) bool)
- func (a *SortedStrArray) Join(glue string) string
- func (a *SortedStrArray) Len() int
- func (a *SortedStrArray) LockFunc(f func(array []string)) *SortedStrArray
- func (a *SortedStrArray) MarshalJSON() ([]byte, error)
- func (a *SortedStrArray) Merge(array interface{}) *SortedStrArray
- func (a *SortedStrArray) PopLeft() string
- func (a *SortedStrArray) PopLefts(size int) []string
- func (a *SortedStrArray) PopRand() string
- func (a *SortedStrArray) PopRands(size int) []string
- func (a *SortedStrArray) PopRight() string
- func (a *SortedStrArray) PopRights(size int) []string
- func (a *SortedStrArray) RLockFunc(f func(array []string)) *SortedStrArray
- func (a *SortedStrArray) Rand() string
- func (a *SortedStrArray) Rands(size int) []string
- func (a *SortedStrArray) Range(start int, end ...int) []string
- func (a *SortedStrArray) Remove(index int) string
- func (a *SortedStrArray) RemoveValue(value string) bool
- func (a *SortedStrArray) Search(value string) (index int)
- func (a *SortedStrArray) SetArray(array []string) *SortedStrArray
- func (a *SortedStrArray) SetUnique(unique bool) *SortedStrArray
- func (a *SortedStrArray) Slice() []string
- func (a *SortedStrArray) Sort() *SortedStrArray
- func (a *SortedStrArray) String() string
- func (a *SortedStrArray) SubSlice(offset int, length ...int) []string
- func (a *SortedStrArray) Sum() (sum int)
- func (a *SortedStrArray) Unique() *SortedStrArray
- func (a *SortedStrArray) UnmarshalJSON(b []byte) error
- func (a *SortedStrArray) UnmarshalValue(value interface{}) (err error)
- type StrArray
- func (a *StrArray) Append(value ...string) *StrArray
- func (a *StrArray) Chunk(size int) [][]string
- func (a *StrArray) Clear() *StrArray
- func (a *StrArray) Clone() (newArray *StrArray)
- func (a *StrArray) Contains(value string) bool
- func (a *StrArray) CountValues() map[string]int
- func (a *StrArray) Fill(startIndex int, num int, value string) *StrArray
- func (a *StrArray) FilterEmpty() *StrArray
- func (a *StrArray) Get(index int) string
- func (a *StrArray) InsertAfter(index int, value string) *StrArray
- func (a *StrArray) InsertBefore(index int, value string) *StrArray
- func (a *StrArray) Interfaces() []interface{}
- func (a *StrArray) Iterator(f func(k int, v string) bool)
- func (a *StrArray) IteratorAsc(f func(k int, v string) bool)
- func (a *StrArray) IteratorDesc(f func(k int, v string) bool)
- func (a *StrArray) Join(glue string) string
- func (a *StrArray) Len() int
- func (a *StrArray) LockFunc(f func(array []string)) *StrArray
- func (a *StrArray) MarshalJSON() ([]byte, error)
- func (a *StrArray) Merge(array interface{}) *StrArray
- func (a *StrArray) Pad(size int, value string) *StrArray
- func (a *StrArray) PopLeft() string
- func (a *StrArray) PopLefts(size int) []string
- func (a *StrArray) PopRand() string
- func (a *StrArray) PopRands(size int) []string
- func (a *StrArray) PopRight() string
- func (a *StrArray) PopRights(size int) []string
- func (a *StrArray) PushLeft(value ...string) *StrArray
- func (a *StrArray) PushRight(value ...string) *StrArray
- func (a *StrArray) RLockFunc(f func(array []string)) *StrArray
- func (a *StrArray) Rand() string
- func (a *StrArray) Rands(size int) []string
- func (a *StrArray) Range(start int, end ...int) []string
- func (a *StrArray) Remove(index int) string
- func (a *StrArray) RemoveValue(value string) bool
- func (a *StrArray) Replace(array []string) *StrArray
- func (a *StrArray) Reverse() *StrArray
- func (a *StrArray) Search(value string) int
- func (a *StrArray) Set(index int, value string) *StrArray
- func (a *StrArray) SetArray(array []string) *StrArray
- func (a *StrArray) Shuffle() *StrArray
- func (a *StrArray) Slice() []string
- func (a *StrArray) Sort(reverse ...bool) *StrArray
- func (a *StrArray) SortFunc(less func(v1, v2 string) bool) *StrArray
- func (a *StrArray) String() string
- func (a *StrArray) SubSlice(offset int, length ...int) []string
- func (a *StrArray) Sum() (sum int)
- func (a *StrArray) Unique() *StrArray
- func (a *StrArray) UnmarshalJSON(b []byte) error
- func (a *StrArray) UnmarshalValue(value interface{}) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Array ¶
type Array struct {
// contains filtered or unexported fields
}
func New ¶
New creates and returns an empty array. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewArrayFrom ¶
NewArrayFrom creates and returns an array with given slice <array>. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewArrayFromCopy ¶
NewArrayFromCopy creates and returns an array from a copy of given slice <array>. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewArrayRange ¶ added in v1.10.1
NewArrayRange creates and returns a array by a range from <start> to <end> with step value <step>.
func NewArraySize ¶
NewArraySize create and returns an array with given size and cap. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func (*Array) Chunk ¶
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) CountValues ¶
CountValues counts the number of occurrences of all values in the array.
func (*Array) Fill ¶
Fill fills an array with num entries of the value <value>, keys starting at the <startIndex> parameter.
func (*Array) FilterEmpty ¶ added in v1.11.5
FilterEmpty removes all empty value of the array. Values like: 0, nil, false, "", len(slice/map/chan) == 0 are considered empty.
func (*Array) Get ¶
Get returns the value of the specified index, the caller should notice the boundary of the array.
func (*Array) InsertAfter ¶
InsertAfter inserts the <value> to the back of <index>.
func (*Array) InsertBefore ¶
InsertBefore inserts the <value> to the front of <index>.
func (*Array) Interfaces ¶ added in v1.9.10
func (a *Array) Interfaces() []interface{}
Interfaces returns current array as []interface{}.
func (*Array) IteratorAsc ¶ added in v1.11.0
IteratorAsc iterates the array in ascending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*Array) IteratorDesc ¶ added in v1.11.0
IteratorDesc iterates the array in descending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*Array) MarshalJSON ¶
MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (*Array) Merge ¶
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 ¶
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 ¶
func (a *Array) PopLeft() interface{}
PopLeft pops and returns an item from the beginning of array.
func (*Array) PopRand ¶
func (a *Array) PopRand() interface{}
PopRand randomly pops and return an item out of array.
func (*Array) PopRight ¶
func (a *Array) PopRight() interface{}
PopRight pops and returns an item from the end of array.
func (*Array) PushRight ¶
PushRight pushes one or multiple items to the end of array. It equals to Append.
func (*Array) Rand ¶
func (a *Array) Rand() interface{}
Rand randomly returns one item from array(no deleting).
func (*Array) Range ¶
Range picks and returns items by range, like array[start:end]. Notice, if in concurrent-safe usage, it returns a copy of slice; else a pointer to the underlying data.
If <end> is negative, then the offset will start from the end of array. If <end> is omitted, then the sequence will have everything from start up until the end of the array.
func (*Array) RemoveValue ¶ added in v1.11.4
RemoveValue removes an item by value. It returns true if value is found in the array, or else false if not found.
func (*Array) Replace ¶
Replace replaces the array items by given <array> from the beginning of array.
func (*Array) Search ¶
Search searches array by <value>, returns the index of <value>, or returns -1 if not exists.
func (*Array) Slice ¶
func (a *Array) Slice() []interface{}
Slice returns the underlying data of array. Note that, if it's in concurrent-safe usage, it returns a copy of underlying data, or else a pointer to the underlying data.
func (*Array) String ¶
String returns current array as a string, which implements like json.Marshal does.
func (*Array) SubSlice ¶
SubSlice returns a slice of elements from the array as specified by the <offset> and <size> parameters. If in concurrent safe usage, it returns a copy of the slice; else a pointer.
If offset is non-negative, the sequence will start at that offset in the array. If offset is negative, the sequence will start that far from the end of the array.
If length is given and is positive, then the sequence will have up to that many elements in it. If the array is shorter than the length, then only the available array elements will be present. If length is given and is negative then the sequence will stop that many elements from the end of the array. If it is omitted, then the sequence will have everything from offset up until the end of the array.
Any possibility crossing the left border of array, it will fail.
func (*Array) UnmarshalJSON ¶ added in v1.9.7
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (*Array) UnmarshalValue ¶ added in v1.11.5
UnmarshalValue is an interface implement which sets any type of value for array.
type IntArray ¶
type IntArray struct {
// contains filtered or unexported fields
}
func NewIntArray ¶
NewIntArray creates and returns an empty array. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewIntArrayFrom ¶
NewIntArrayFrom creates and returns an array with given slice <array>. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewIntArrayFromCopy ¶
NewIntArrayFromCopy creates and returns an array from a copy of given slice <array>. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewIntArrayRange ¶ added in v1.10.1
NewIntArrayRange creates and returns a array by a range from <start> to <end> with step value <step>.
func NewIntArraySize ¶
NewIntArraySize create and returns an array with given size and cap. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func (*IntArray) Chunk ¶
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) CountValues ¶
CountValues counts the number of occurrences of all values in the array.
func (*IntArray) Fill ¶
Fill fills an array with num entries of the value <value>, keys starting at the <startIndex> parameter.
func (*IntArray) FilterEmpty ¶ added in v1.11.5
FilterEmpty removes all zero value of the array.
func (*IntArray) Get ¶
Get returns the value of the specified index, the caller should notice the boundary of the array.
func (*IntArray) InsertAfter ¶
InsertAfter inserts the <value> to the back of <index>.
func (*IntArray) InsertBefore ¶
InsertBefore inserts the <value> to the front of <index>.
func (*IntArray) Interfaces ¶ added in v1.9.10
func (a *IntArray) Interfaces() []interface{}
Interfaces returns current array as []interface{}.
func (*IntArray) IteratorAsc ¶ added in v1.11.0
IteratorAsc iterates the array in ascending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*IntArray) IteratorDesc ¶ added in v1.11.0
IteratorDesc iterates the array in descending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*IntArray) MarshalJSON ¶
MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (*IntArray) Merge ¶
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 ¶
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) PushRight ¶
PushRight pushes one or multiple items to the end of array. It equals to Append.
func (*IntArray) Range ¶
Range picks and returns items by range, like array[start:end]. Notice, if in concurrent-safe usage, it returns a copy of slice; else a pointer to the underlying data.
If <end> is negative, then the offset will start from the end of array. If <end> is omitted, then the sequence will have everything from start up until the end of the array.
func (*IntArray) RemoveValue ¶ added in v1.11.4
RemoveValue removes an item by value. It returns true if value is found in the array, or else false if not found.
func (*IntArray) Replace ¶
Replace replaces the array items by given <array> from the beginning of array.
func (*IntArray) Search ¶
Search searches array by <value>, returns the index of <value>, or returns -1 if not exists.
func (*IntArray) Slice ¶
Slice returns the underlying data of array. Note that, if it's in concurrent-safe usage, it returns a copy of underlying data, or else a pointer to the underlying data.
func (*IntArray) Sort ¶
Sort sorts the array in increasing order. The parameter <reverse> controls whether sort in increasing order(default) or decreasing order
func (*IntArray) String ¶
String returns current array as a string, which implements like json.Marshal does.
func (*IntArray) SubSlice ¶
SubSlice returns a slice of elements from the array as specified by the <offset> and <size> parameters. If in concurrent safe usage, it returns a copy of the slice; else a pointer.
If offset is non-negative, the sequence will start at that offset in the array. If offset is negative, the sequence will start that far from the end of the array.
If length is given and is positive, then the sequence will have up to that many elements in it. If the array is shorter than the length, then only the available array elements will be present. If length is given and is negative then the sequence will stop that many elements from the end of the array. If it is omitted, then the sequence will have everything from offset up until the end of the array.
Any possibility crossing the left border of array, it will fail.
func (*IntArray) UnmarshalJSON ¶ added in v1.9.7
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (*IntArray) UnmarshalValue ¶ added in v1.11.5
UnmarshalValue is an interface implement which sets any type of value for array.
type SortedArray ¶
type SortedArray struct {
// contains filtered or unexported fields
}
It's using increasing order in default.
func NewSortedArray ¶
func NewSortedArray(comparator func(a, b interface{}) int, safe ...bool) *SortedArray
NewSortedArray creates and returns an empty sorted array. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default. The parameter <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 ¶
func NewSortedArrayFrom(array []interface{}, comparator func(a, b interface{}) int, safe ...bool) *SortedArray
NewSortedArrayFrom creates and returns an sorted array with given slice <array>. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewSortedArrayFromCopy ¶
func NewSortedArrayFromCopy(array []interface{}, comparator func(a, b interface{}) int, safe ...bool) *SortedArray
NewSortedArrayFromCopy creates and returns an sorted array from a copy of given slice <array>. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewSortedArrayRange ¶ added in v1.10.1
func NewSortedArrayRange(start, end, step int, comparator func(a, b interface{}) int, safe ...bool) *SortedArray
NewSortedArrayRange creates and returns a array by a range from <start> to <end> with step value <step>.
func NewSortedArraySize ¶
func NewSortedArraySize(cap int, comparator func(a, b interface{}) int, safe ...bool) *SortedArray
NewSortedArraySize create and returns an sorted array with given size and cap. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func (*SortedArray) Add ¶
func (a *SortedArray) Add(values ...interface{}) *SortedArray
Add adds one or multiple values to sorted array, the array always keeps sorted.
func (*SortedArray) Chunk ¶
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 ¶
func (a *SortedArray) Clear() *SortedArray
Clear deletes all items of current array.
func (*SortedArray) Clone ¶
func (a *SortedArray) Clone() (newArray *SortedArray)
Clone returns a new array, which is a copy of current array.
func (*SortedArray) Contains ¶
func (a *SortedArray) Contains(value interface{}) bool
Contains checks whether a value exists in the array.
func (*SortedArray) CountValues ¶
func (a *SortedArray) CountValues() map[interface{}]int
CountValues counts the number of occurrences of all values in the array.
func (*SortedArray) FilterEmpty ¶ added in v1.11.5
func (a *SortedArray) FilterEmpty() *SortedArray
FilterEmpty removes all empty value of the array. Values like: 0, nil, false, "", len(slice/map/chan) == 0 are considered empty.
func (*SortedArray) FilterNil ¶ added in v1.11.5
func (a *SortedArray) FilterNil() *SortedArray
FilterNil removes all nil value of the array.
func (*SortedArray) Get ¶
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) Interfaces ¶ added in v1.9.10
func (a *SortedArray) Interfaces() []interface{}
Interfaces returns current array as []interface{}.
func (*SortedArray) Iterator ¶ added in v1.11.0
func (a *SortedArray) Iterator(f func(k int, v interface{}) bool)
Iterator is alias of IteratorAsc.
func (*SortedArray) IteratorAsc ¶ added in v1.11.0
func (a *SortedArray) IteratorAsc(f func(k int, v interface{}) bool)
IteratorAsc iterates the array in ascending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*SortedArray) IteratorDesc ¶ added in v1.11.0
func (a *SortedArray) IteratorDesc(f func(k int, v interface{}) bool)
IteratorDesc iterates the array in descending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*SortedArray) Join ¶
func (a *SortedArray) Join(glue string) string
Join joins array elements with a string <glue>.
func (*SortedArray) LockFunc ¶
func (a *SortedArray) LockFunc(f func(array []interface{})) *SortedArray
LockFunc locks writing by callback function <f>.
func (*SortedArray) MarshalJSON ¶
func (a *SortedArray) MarshalJSON() ([]byte, error)
MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (*SortedArray) Merge ¶
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 ¶
func (a *SortedArray) PopLeft() interface{}
PopLeft pops and returns an item from the beginning of array.
func (*SortedArray) PopLefts ¶
func (a *SortedArray) PopLefts(size int) []interface{}
PopLefts pops and returns <size> items from the beginning of array.
func (*SortedArray) PopRand ¶
func (a *SortedArray) PopRand() interface{}
PopRand randomly pops and return an item out of array.
func (*SortedArray) PopRands ¶
func (a *SortedArray) PopRands(size int) []interface{}
PopRands randomly pops and returns <size> items out of array.
func (*SortedArray) PopRight ¶
func (a *SortedArray) PopRight() interface{}
PopRight pops and returns an item from the end of array.
func (*SortedArray) PopRights ¶
func (a *SortedArray) PopRights(size int) []interface{}
PopRights pops and returns <size> items from the end of array.
func (*SortedArray) RLockFunc ¶
func (a *SortedArray) RLockFunc(f func(array []interface{})) *SortedArray
RLockFunc locks reading by callback function <f>.
func (*SortedArray) Rand ¶
func (a *SortedArray) Rand() interface{}
Rand randomly returns one item from array(no deleting).
func (*SortedArray) Rands ¶
func (a *SortedArray) Rands(size int) []interface{}
Rands randomly returns <size> items from array(no deleting).
func (*SortedArray) Range ¶
func (a *SortedArray) Range(start int, 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.
If <end> is negative, then the offset will start from the end of array. If <end> is omitted, then the sequence will have everything from start up until the end of the array.
func (*SortedArray) Remove ¶
func (a *SortedArray) Remove(index int) interface{}
Remove removes an item by index.
func (*SortedArray) RemoveValue ¶ added in v1.11.4
func (a *SortedArray) RemoveValue(value interface{}) bool
RemoveValue removes an item by value. It returns true if value is found in the array, or else false if not found.
func (*SortedArray) Search ¶
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 ¶
func (a *SortedArray) SetArray(array []interface{}) *SortedArray
SetArray sets the underlying slice array with the given <array>.
func (*SortedArray) SetComparator ¶ added in v1.9.7
func (a *SortedArray) SetComparator(comparator func(a, b interface{}) int)
SetComparator sets/changes the comparator for sorting.
func (*SortedArray) SetUnique ¶
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 ¶
func (a *SortedArray) Slice() []interface{}
Slice returns the underlying data of array. Note that, if it's in concurrent-safe usage, it returns a copy of underlying data, or else a pointer to the underlying data.
func (*SortedArray) Sort ¶
func (a *SortedArray) Sort() *SortedArray
Sort sorts the array in increasing order. The parameter <reverse> controls whether sort in increasing order(default) or decreasing order
func (*SortedArray) String ¶
func (a *SortedArray) String() string
String returns current array as a string, which implements like json.Marshal does.
func (*SortedArray) SubSlice ¶
func (a *SortedArray) SubSlice(offset int, length ...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.
If offset is non-negative, the sequence will start at that offset in the array. If offset is negative, the sequence will start that far from the end of the array.
If length is given and is positive, then the sequence will have up to that many elements in it. If the array is shorter than the length, then only the available array elements will be present. If length is given and is negative then the sequence will stop that many elements from the end of the array. If it is omitted, then the sequence will have everything from offset up until the end of the array.
Any possibility crossing the left border of array, it will fail.
func (*SortedArray) Sum ¶
func (a *SortedArray) Sum() (sum int)
Sum returns the sum of values in an array.
func (*SortedArray) Unique ¶
func (a *SortedArray) Unique() *SortedArray
Unique uniques the array, clear repeated items.
func (*SortedArray) UnmarshalJSON ¶ added in v1.9.7
func (a *SortedArray) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (*SortedArray) UnmarshalValue ¶ added in v1.11.5
func (a *SortedArray) UnmarshalValue(value interface{}) (err error)
UnmarshalValue is an interface implement which sets any type of value for array.
type SortedIntArray ¶
type SortedIntArray struct {
// contains filtered or unexported fields
}
It's using increasing order in default.
func NewSortedIntArray ¶
func NewSortedIntArray(safe ...bool) *SortedIntArray
NewSortedIntArray creates and returns an empty sorted array. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewSortedIntArrayComparator ¶
func NewSortedIntArrayComparator(comparator func(a, b int) int, safe ...bool) *SortedIntArray
NewSortedIntArrayComparator creates and returns an empty sorted array with specified comparator. The parameter <safe> is used to specify whether using array in concurrent-safety which is false in default.
func NewSortedIntArrayFrom ¶
func NewSortedIntArrayFrom(array []int, safe ...bool) *SortedIntArray
NewIntArrayFrom creates and returns an sorted array with given slice <array>. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewSortedIntArrayFromCopy ¶
func NewSortedIntArrayFromCopy(array []int, safe ...bool) *SortedIntArray
NewSortedIntArrayFromCopy creates and returns an sorted array from a copy of given slice <array>. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewSortedIntArrayRange ¶ added in v1.10.1
func NewSortedIntArrayRange(start, end, step int, safe ...bool) *SortedIntArray
NewSortedIntArrayRange creates and returns a array by a range from <start> to <end> with step value <step>.
func NewSortedIntArraySize ¶
func NewSortedIntArraySize(cap int, safe ...bool) *SortedIntArray
NewSortedIntArraySize create and returns an sorted array with given size and cap. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func (*SortedIntArray) Add ¶
func (a *SortedIntArray) Add(values ...int) *SortedIntArray
Add adds one or multiple values to sorted array, the array always keeps sorted.
func (*SortedIntArray) Chunk ¶
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 ¶
func (a *SortedIntArray) Clear() *SortedIntArray
Clear deletes all items of current array.
func (*SortedIntArray) Clone ¶
func (a *SortedIntArray) Clone() (newArray *SortedIntArray)
Clone returns a new array, which is a copy of current array.
func (*SortedIntArray) Contains ¶
func (a *SortedIntArray) Contains(value int) bool
Contains checks whether a value exists in the array.
func (*SortedIntArray) CountValues ¶
func (a *SortedIntArray) CountValues() map[int]int
CountValues counts the number of occurrences of all values in the array.
func (*SortedIntArray) FilterEmpty ¶ added in v1.11.5
func (a *SortedIntArray) FilterEmpty() *SortedIntArray
FilterEmpty removes all zero value of the array.
func (*SortedIntArray) Get ¶
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) Interfaces ¶ added in v1.9.10
func (a *SortedIntArray) Interfaces() []interface{}
Interfaces returns current array as []interface{}.
func (*SortedIntArray) Iterator ¶ added in v1.11.0
func (a *SortedIntArray) Iterator(f func(k int, v int) bool)
Iterator is alias of IteratorAsc.
func (*SortedIntArray) IteratorAsc ¶ added in v1.11.0
func (a *SortedIntArray) IteratorAsc(f func(k int, v int) bool)
IteratorAsc iterates the array in ascending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*SortedIntArray) IteratorDesc ¶ added in v1.11.0
func (a *SortedIntArray) IteratorDesc(f func(k int, v int) bool)
IteratorDesc iterates the array in descending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*SortedIntArray) Join ¶
func (a *SortedIntArray) Join(glue string) string
Join joins array elements with a string <glue>.
func (*SortedIntArray) LockFunc ¶
func (a *SortedIntArray) LockFunc(f func(array []int)) *SortedIntArray
LockFunc locks writing by callback function <f>.
func (*SortedIntArray) MarshalJSON ¶
func (a *SortedIntArray) MarshalJSON() ([]byte, error)
MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (*SortedIntArray) Merge ¶
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 ¶
func (a *SortedIntArray) PopLeft() int
PopLeft pops and returns an item from the beginning of array.
func (*SortedIntArray) PopLefts ¶
func (a *SortedIntArray) PopLefts(size int) []int
PopLefts pops and returns <size> items from the beginning of array.
func (*SortedIntArray) PopRand ¶
func (a *SortedIntArray) PopRand() int
PopRand randomly pops and return an item out of array.
func (*SortedIntArray) PopRands ¶
func (a *SortedIntArray) PopRands(size int) []int
PopRands randomly pops and returns <size> items out of array.
func (*SortedIntArray) PopRight ¶
func (a *SortedIntArray) PopRight() int
PopRight pops and returns an item from the end of array.
func (*SortedIntArray) PopRights ¶
func (a *SortedIntArray) PopRights(size int) []int
PopRights pops and returns <size> items from the end of array.
func (*SortedIntArray) RLockFunc ¶
func (a *SortedIntArray) RLockFunc(f func(array []int)) *SortedIntArray
RLockFunc locks reading by callback function <f>.
func (*SortedIntArray) Rand ¶
func (a *SortedIntArray) Rand() int
Rand randomly returns one item from array(no deleting).
func (*SortedIntArray) Rands ¶
func (a *SortedIntArray) Rands(size int) []int
Rands randomly returns <size> items from array(no deleting).
func (*SortedIntArray) Range ¶
func (a *SortedIntArray) Range(start int, 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.
If <end> is negative, then the offset will start from the end of array. If <end> is omitted, then the sequence will have everything from start up until the end of the array.
func (*SortedIntArray) Remove ¶
func (a *SortedIntArray) Remove(index int) int
Remove removes an item by index.
func (*SortedIntArray) RemoveValue ¶ added in v1.11.4
func (a *SortedIntArray) RemoveValue(value int) bool
RemoveValue removes an item by value. It returns true if value is found in the array, or else false if not found.
func (*SortedIntArray) Search ¶
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 ¶
func (a *SortedIntArray) SetArray(array []int) *SortedIntArray
SetArray sets the underlying slice array with the given <array>.
func (*SortedIntArray) SetUnique ¶
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 ¶
func (a *SortedIntArray) Slice() []int
Slice returns the underlying data of array. Note that, if it's in concurrent-safe usage, it returns a copy of underlying data, or else a pointer to the underlying data.
func (*SortedIntArray) Sort ¶
func (a *SortedIntArray) Sort() *SortedIntArray
Sort sorts the array in increasing order. The parameter <reverse> controls whether sort in increasing order(default) or decreasing order.
func (*SortedIntArray) String ¶
func (a *SortedIntArray) String() string
String returns current array as a string, which implements like json.Marshal does.
func (*SortedIntArray) SubSlice ¶
func (a *SortedIntArray) SubSlice(offset int, length ...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.
If offset is non-negative, the sequence will start at that offset in the array. If offset is negative, the sequence will start that far from the end of the array.
If length is given and is positive, then the sequence will have up to that many elements in it. If the array is shorter than the length, then only the available array elements will be present. If length is given and is negative then the sequence will stop that many elements from the end of the array. If it is omitted, then the sequence will have everything from offset up until the end of the array.
Any possibility crossing the left border of array, it will fail.
func (*SortedIntArray) Sum ¶
func (a *SortedIntArray) Sum() (sum int)
Sum returns the sum of values in an array.
func (*SortedIntArray) Unique ¶
func (a *SortedIntArray) Unique() *SortedIntArray
Unique uniques the array, clear repeated items.
func (*SortedIntArray) UnmarshalJSON ¶ added in v1.9.7
func (a *SortedIntArray) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (*SortedIntArray) UnmarshalValue ¶ added in v1.11.5
func (a *SortedIntArray) UnmarshalValue(value interface{}) (err error)
UnmarshalValue is an interface implement which sets any type of value for array.
type SortedStrArray ¶
type SortedStrArray struct {
// contains filtered or unexported fields
}
It's using increasing order in default.
func NewSortedStrArray ¶
func NewSortedStrArray(safe ...bool) *SortedStrArray
NewSortedStrArray creates and returns an empty sorted array. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewSortedStrArrayComparator ¶
func NewSortedStrArrayComparator(comparator func(a, b string) int, safe ...bool) *SortedStrArray
NewSortedStrArrayComparator creates and returns an empty sorted array with specified comparator. The parameter <safe> is used to specify whether using array in concurrent-safety which is false in default.
func NewSortedStrArrayFrom ¶
func NewSortedStrArrayFrom(array []string, safe ...bool) *SortedStrArray
NewSortedStrArrayFrom creates and returns an sorted array with given slice <array>. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewSortedStrArrayFromCopy ¶
func NewSortedStrArrayFromCopy(array []string, safe ...bool) *SortedStrArray
NewSortedStrArrayFromCopy creates and returns an sorted array from a copy of given slice <array>. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewSortedStrArraySize ¶
func NewSortedStrArraySize(cap int, safe ...bool) *SortedStrArray
NewSortedStrArraySize create and returns an sorted array with given size and cap. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func (*SortedStrArray) Add ¶
func (a *SortedStrArray) Add(values ...string) *SortedStrArray
Add adds one or multiple values to sorted array, the array always keeps sorted.
func (*SortedStrArray) Chunk ¶
func (a *SortedStrArray) 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 (*SortedStrArray) Clear ¶
func (a *SortedStrArray) Clear() *SortedStrArray
Clear deletes all items of current array.
func (*SortedStrArray) Clone ¶
func (a *SortedStrArray) Clone() (newArray *SortedStrArray)
Clone returns a new array, which is a copy of current array.
func (*SortedStrArray) Contains ¶
func (a *SortedStrArray) Contains(value string) bool
Contains checks whether a value exists in the array.
func (*SortedStrArray) CountValues ¶
func (a *SortedStrArray) CountValues() map[string]int
CountValues counts the number of occurrences of all values in the array.
func (*SortedStrArray) FilterEmpty ¶ added in v1.11.5
func (a *SortedStrArray) FilterEmpty() *SortedStrArray
FilterEmpty removes all empty string value of the array.
func (*SortedStrArray) Get ¶
func (a *SortedStrArray) Get(index int) string
Get returns the value of the specified index, the caller should notice the boundary of the array.
func (*SortedStrArray) Interfaces ¶ added in v1.9.10
func (a *SortedStrArray) Interfaces() []interface{}
Interfaces returns current array as []interface{}.
func (*SortedStrArray) Iterator ¶ added in v1.11.0
func (a *SortedStrArray) Iterator(f func(k int, v string) bool)
Iterator is alias of IteratorAsc.
func (*SortedStrArray) IteratorAsc ¶ added in v1.11.0
func (a *SortedStrArray) IteratorAsc(f func(k int, v string) bool)
IteratorAsc iterates the array in ascending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*SortedStrArray) IteratorDesc ¶ added in v1.11.0
func (a *SortedStrArray) IteratorDesc(f func(k int, v string) bool)
IteratorDesc iterates the array in descending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*SortedStrArray) Join ¶
func (a *SortedStrArray) Join(glue string) string
Join joins array elements with a string <glue>.
func (*SortedStrArray) LockFunc ¶
func (a *SortedStrArray) LockFunc(f func(array []string)) *SortedStrArray
LockFunc locks writing by callback function <f>.
func (*SortedStrArray) MarshalJSON ¶
func (a *SortedStrArray) MarshalJSON() ([]byte, error)
MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (*SortedStrArray) Merge ¶
func (a *SortedStrArray) Merge(array interface{}) *SortedStrArray
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 (*SortedStrArray) PopLeft ¶
func (a *SortedStrArray) PopLeft() string
PopLeft pops and returns an item from the beginning of array.
func (*SortedStrArray) PopLefts ¶
func (a *SortedStrArray) PopLefts(size int) []string
PopLefts pops and returns <size> items from the beginning of array.
func (*SortedStrArray) PopRand ¶
func (a *SortedStrArray) PopRand() string
PopRand randomly pops and return an item out of array.
func (*SortedStrArray) PopRands ¶
func (a *SortedStrArray) PopRands(size int) []string
PopRands randomly pops and returns <size> items out of array.
func (*SortedStrArray) PopRight ¶
func (a *SortedStrArray) PopRight() string
PopRight pops and returns an item from the end of array.
func (*SortedStrArray) PopRights ¶
func (a *SortedStrArray) PopRights(size int) []string
PopRights pops and returns <size> items from the end of array.
func (*SortedStrArray) RLockFunc ¶
func (a *SortedStrArray) RLockFunc(f func(array []string)) *SortedStrArray
RLockFunc locks reading by callback function <f>.
func (*SortedStrArray) Rand ¶
func (a *SortedStrArray) Rand() string
Rand randomly returns one item from array(no deleting).
func (*SortedStrArray) Rands ¶
func (a *SortedStrArray) Rands(size int) []string
Rands randomly returns <size> items from array(no deleting).
func (*SortedStrArray) Range ¶
func (a *SortedStrArray) Range(start int, end ...int) []string
Range picks and returns items by range, like array[start:end]. Notice, if in concurrent-safe usage, it returns a copy of slice; else a pointer to the underlying data.
If <end> is negative, then the offset will start from the end of array. If <end> is omitted, then the sequence will have everything from start up until the end of the array.
func (*SortedStrArray) Remove ¶
func (a *SortedStrArray) Remove(index int) string
Remove removes an item by index.
func (*SortedStrArray) RemoveValue ¶ added in v1.11.4
func (a *SortedStrArray) RemoveValue(value string) bool
RemoveValue removes an item by value. It returns true if value is found in the array, or else false if not found.
func (*SortedStrArray) Search ¶
func (a *SortedStrArray) Search(value string) (index int)
Search searches array by <value>, returns the index of <value>, or returns -1 if not exists.
func (*SortedStrArray) SetArray ¶
func (a *SortedStrArray) SetArray(array []string) *SortedStrArray
SetArray sets the underlying slice array with the given <array>.
func (*SortedStrArray) SetUnique ¶
func (a *SortedStrArray) SetUnique(unique bool) *SortedStrArray
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 (*SortedStrArray) Slice ¶
func (a *SortedStrArray) Slice() []string
Slice returns the underlying data of array. Note that, if it's in concurrent-safe usage, it returns a copy of underlying data, or else a pointer to the underlying data.
func (*SortedStrArray) Sort ¶
func (a *SortedStrArray) Sort() *SortedStrArray
Sort sorts the array in increasing order. The parameter <reverse> controls whether sort in increasing order(default) or decreasing order.
func (*SortedStrArray) String ¶
func (a *SortedStrArray) String() string
String returns current array as a string, which implements like json.Marshal does.
func (*SortedStrArray) SubSlice ¶
func (a *SortedStrArray) SubSlice(offset int, length ...int) []string
SubSlice returns a slice of elements from the array as specified by the <offset> and <size> parameters. If in concurrent safe usage, it returns a copy of the slice; else a pointer.
If offset is non-negative, the sequence will start at that offset in the array. If offset is negative, the sequence will start that far from the end of the array.
If length is given and is positive, then the sequence will have up to that many elements in it. If the array is shorter than the length, then only the available array elements will be present. If length is given and is negative then the sequence will stop that many elements from the end of the array. If it is omitted, then the sequence will have everything from offset up until the end of the array.
Any possibility crossing the left border of array, it will fail.
func (*SortedStrArray) Sum ¶
func (a *SortedStrArray) Sum() (sum int)
Sum returns the sum of values in an array.
func (*SortedStrArray) Unique ¶
func (a *SortedStrArray) Unique() *SortedStrArray
Unique uniques the array, clear repeated items.
func (*SortedStrArray) UnmarshalJSON ¶ added in v1.9.7
func (a *SortedStrArray) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (*SortedStrArray) UnmarshalValue ¶ added in v1.11.5
func (a *SortedStrArray) UnmarshalValue(value interface{}) (err error)
UnmarshalValue is an interface implement which sets any type of value for array.
type StrArray ¶
type StrArray struct {
// contains filtered or unexported fields
}
func NewStrArray ¶
NewStrArray creates and returns an empty array. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewStrArrayFrom ¶
NewStrArrayFrom creates and returns an array with given slice <array>. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewStrArrayFromCopy ¶
NewStrArrayFromCopy creates and returns an array from a copy of given slice <array>. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func NewStrArraySize ¶
NewStrArraySize create and returns an array with given size and cap. The parameter <safe> is used to specify whether using array in concurrent-safety, which is false in default.
func (*StrArray) Chunk ¶
Chunk splits an array into multiple arrays, the size of each array is determined by <size>. The last chunk may contain less than size elements.
func (*StrArray) CountValues ¶
CountValues counts the number of occurrences of all values in the array.
func (*StrArray) Fill ¶
Fill fills an array with num entries of the value <value>, keys starting at the <startIndex> parameter.
func (*StrArray) FilterEmpty ¶ added in v1.11.5
FilterEmpty removes all empty string value of the array.
func (*StrArray) Get ¶
Get returns the value of the specified index, the caller should notice the boundary of the array.
func (*StrArray) InsertAfter ¶
InsertAfter inserts the <value> to the back of <index>.
func (*StrArray) InsertBefore ¶
InsertBefore inserts the <value> to the front of <index>.
func (*StrArray) Interfaces ¶ added in v1.9.10
func (a *StrArray) Interfaces() []interface{}
Interfaces returns current array as []interface{}.
func (*StrArray) IteratorAsc ¶ added in v1.11.0
IteratorAsc iterates the array in ascending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*StrArray) IteratorDesc ¶ added in v1.11.0
IteratorDesc iterates the array in descending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*StrArray) MarshalJSON ¶
MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (*StrArray) Merge ¶
Merge merges <array> into current array. The parameter <array> can be any garray or slice type. The difference between Merge and Append is Append supports only specified slice type, but Merge supports more parameter types.
func (*StrArray) Pad ¶
Pad pads array to the specified length with <value>. If size is positive then the array is padded on the right, or negative on the left. If the absolute value of <size> is less than or equal to the length of the array then no padding takes place.
func (*StrArray) PushRight ¶
PushRight pushes one or multiple items to the end of array. It equals to Append.
func (*StrArray) Range ¶
Range picks and returns items by range, like array[start:end]. Notice, if in concurrent-safe usage, it returns a copy of slice; else a pointer to the underlying data.
If <end> is negative, then the offset will start from the end of array. If <end> is omitted, then the sequence will have everything from start up until the end of the array.
func (*StrArray) RemoveValue ¶ added in v1.11.4
RemoveValue removes an item by value. It returns true if value is found in the array, or else false if not found.
func (*StrArray) Replace ¶
Replace replaces the array items by given <array> from the beginning of array.
func (*StrArray) Search ¶
Search searches array by <value>, returns the index of <value>, or returns -1 if not exists.
func (*StrArray) Slice ¶
Slice returns the underlying data of array. Note that, if it's in concurrent-safe usage, it returns a copy of underlying data, or else a pointer to the underlying data.
func (*StrArray) Sort ¶
Sort sorts the array in increasing order. The parameter <reverse> controls whether sort in increasing order(default) or decreasing order
func (*StrArray) String ¶
String returns current array as a string, which implements like json.Marshal does.
func (*StrArray) SubSlice ¶
SubSlice returns a slice of elements from the array as specified by the <offset> and <size> parameters. If in concurrent safe usage, it returns a copy of the slice; else a pointer.
If offset is non-negative, the sequence will start at that offset in the array. If offset is negative, the sequence will start that far from the end of the array.
If length is given and is positive, then the sequence will have up to that many elements in it. If the array is shorter than the length, then only the available array elements will be present. If length is given and is negative then the sequence will stop that many elements from the end of the array. If it is omitted, then the sequence will have everything from offset up until the end of the array.
Any possibility crossing the left border of array, it will fail.
func (*StrArray) UnmarshalJSON ¶ added in v1.9.7
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (*StrArray) UnmarshalValue ¶ added in v1.11.5
UnmarshalValue is an interface implement which sets any type of value for array.