Documentation ¶
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 (that *Array) Append(value ...interface{}) *Array
- func (that *Array) Chunk(size int) [][]interface{}
- func (that *Array) Clear() *Array
- func (that *Array) Clone() (newArray *Array)
- func (that *Array) Contains(value interface{}) bool
- func (that *Array) CountValues() map[interface{}]int
- func (that *Array) Fill(startIndex int, num int, value interface{}) error
- func (that *Array) FilterEmpty() *Array
- func (that *Array) FilterNil() *Array
- func (that *Array) Get(index int) (value interface{}, found bool)
- func (that *Array) InsertAfter(index int, value interface{}) error
- func (that *Array) InsertBefore(index int, value interface{}) error
- func (that *Array) Interfaces() []interface{}
- func (that *Array) IsEmpty() bool
- func (that *Array) Iterator(f func(k int, v interface{}) bool)
- func (that *Array) IteratorAsc(f func(k int, v interface{}) bool)
- func (that *Array) IteratorDesc(f func(k int, v interface{}) bool)
- func (that *Array) Join(glue string) string
- func (that *Array) Len() int
- func (that *Array) LockFunc(f func(array []interface{})) *Array
- func (that Array) MarshalJSON() ([]byte, error)
- func (that *Array) Merge(array interface{}) *Array
- func (that *Array) Pad(size int, val interface{}) *Array
- func (that *Array) PopLeft() (value interface{}, found bool)
- func (that *Array) PopLefts(size int) []interface{}
- func (that *Array) PopRand() (value interface{}, found bool)
- func (that *Array) PopRands(size int) []interface{}
- func (that *Array) PopRight() (value interface{}, found bool)
- func (that *Array) PopRights(size int) []interface{}
- func (that *Array) PushLeft(value ...interface{}) *Array
- func (that *Array) PushRight(value ...interface{}) *Array
- func (that *Array) RLockFunc(f func(array []interface{})) *Array
- func (that *Array) Rand() (value interface{}, found bool)
- func (that *Array) Rands(size int) []interface{}
- func (that *Array) Range(start int, end ...int) []interface{}
- func (that *Array) Remove(index int) (value interface{}, found bool)
- func (that *Array) RemoveValue(value interface{}) bool
- func (that *Array) Replace(array []interface{}) *Array
- func (that *Array) Reverse() *Array
- func (that *Array) Search(value interface{}) int
- func (that *Array) Set(index int, value interface{}) error
- func (that *Array) SetArray(array []interface{}) *Array
- func (that *Array) Shuffle() *Array
- func (that *Array) Slice() []interface{}
- func (that *Array) SortFunc(less func(v1, v2 interface{}) bool) *Array
- func (that *Array) String() string
- func (that *Array) SubSlice(offset int, length ...int) []interface{}
- func (that *Array) Sum() (sum int)
- func (that *Array) Unique() *Array
- func (that *Array) UnmarshalJSON(b []byte) error
- func (that *Array) UnmarshalValue(value interface{}) error
- func (that *Array) Walk(f func(value interface{}) interface{}) *Array
- type IntArray
- func (that *IntArray) Append(value ...int) *IntArray
- func (that *IntArray) Chunk(size int) [][]int
- func (that *IntArray) Clear() *IntArray
- func (that *IntArray) Clone() (newArray *IntArray)
- func (that *IntArray) Contains(value int) bool
- func (that *IntArray) CountValues() map[int]int
- func (that *IntArray) Fill(startIndex int, num int, value int) error
- func (that *IntArray) FilterEmpty() *IntArray
- func (that *IntArray) Get(index int) (value int, found bool)
- func (that *IntArray) InsertAfter(index int, value int) error
- func (that *IntArray) InsertBefore(index int, value int) error
- func (that *IntArray) Interfaces() []interface{}
- func (that *IntArray) IsEmpty() bool
- func (that *IntArray) Iterator(f func(k int, v int) bool)
- func (that *IntArray) IteratorAsc(f func(k int, v int) bool)
- func (that *IntArray) IteratorDesc(f func(k int, v int) bool)
- func (that *IntArray) Join(glue string) string
- func (that *IntArray) Len() int
- func (that *IntArray) LockFunc(f func(array []int)) *IntArray
- func (that IntArray) MarshalJSON() ([]byte, error)
- func (that *IntArray) Merge(array interface{}) *IntArray
- func (that *IntArray) Pad(size int, value int) *IntArray
- func (that *IntArray) PopLeft() (value int, found bool)
- func (that *IntArray) PopLefts(size int) []int
- func (that *IntArray) PopRand() (value int, found bool)
- func (that *IntArray) PopRands(size int) []int
- func (that *IntArray) PopRight() (value int, found bool)
- func (that *IntArray) PopRights(size int) []int
- func (that *IntArray) PushLeft(value ...int) *IntArray
- func (that *IntArray) PushRight(value ...int) *IntArray
- func (that *IntArray) RLockFunc(f func(array []int)) *IntArray
- func (that *IntArray) Rand() (value int, found bool)
- func (that *IntArray) Rands(size int) []int
- func (that *IntArray) Range(start int, end ...int) []int
- func (that *IntArray) Remove(index int) (value int, found bool)
- func (that *IntArray) RemoveValue(value int) bool
- func (that *IntArray) Replace(array []int) *IntArray
- func (that *IntArray) Reverse() *IntArray
- func (that *IntArray) Search(value int) int
- func (that *IntArray) Set(index int, value int) error
- func (that *IntArray) SetArray(array []int) *IntArray
- func (that *IntArray) Shuffle() *IntArray
- func (that *IntArray) Slice() []int
- func (that *IntArray) Sort(reverse ...bool) *IntArray
- func (that *IntArray) SortFunc(less func(v1, v2 int) bool) *IntArray
- func (that *IntArray) String() string
- func (that *IntArray) SubSlice(offset int, length ...int) []int
- func (that *IntArray) Sum() (sum int)
- func (that *IntArray) Unique() *IntArray
- func (that *IntArray) UnmarshalJSON(b []byte) error
- func (that *IntArray) UnmarshalValue(value interface{}) error
- func (that *IntArray) Walk(f func(value int) int) *IntArray
- 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) Append(values ...interface{}) *SortedArray
- func (a *SortedArray) At(index int) (value interface{})
- 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) (value interface{}, found bool)
- func (a *SortedArray) Interfaces() []interface{}
- func (a *SortedArray) IsEmpty() bool
- 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() (value interface{}, found bool)
- func (a *SortedArray) PopLefts(size int) []interface{}
- func (a *SortedArray) PopRand() (value interface{}, found bool)
- func (a *SortedArray) PopRands(size int) []interface{}
- func (a *SortedArray) PopRight() (value interface{}, found bool)
- func (a *SortedArray) PopRights(size int) []interface{}
- func (a *SortedArray) RLockFunc(f func(array []interface{})) *SortedArray
- func (a *SortedArray) Rand() (value interface{}, found bool)
- func (a *SortedArray) Rands(size int) []interface{}
- func (a *SortedArray) Range(start int, end ...int) []interface{}
- func (a *SortedArray) Remove(index int) (value interface{}, found bool)
- 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)
- func (a *SortedArray) Walk(f func(value interface{}) interface{}) *SortedArray
- 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 (that *SortedIntArray) Add(values ...int) *SortedIntArray
- func (that *SortedIntArray) Append(values ...int) *SortedIntArray
- func (that *SortedIntArray) Chunk(size int) [][]int
- func (that *SortedIntArray) Clear() *SortedIntArray
- func (that *SortedIntArray) Clone() (newArray *SortedIntArray)
- func (that *SortedIntArray) Contains(value int) bool
- func (that *SortedIntArray) CountValues() map[int]int
- func (that *SortedIntArray) FilterEmpty() *SortedIntArray
- func (that *SortedIntArray) Get(index int) (value int, found bool)
- func (that *SortedIntArray) Interfaces() []interface{}
- func (that *SortedIntArray) IsEmpty() bool
- func (that *SortedIntArray) Iterator(f func(k int, v int) bool)
- func (that *SortedIntArray) IteratorAsc(f func(k int, v int) bool)
- func (that *SortedIntArray) IteratorDesc(f func(k int, v int) bool)
- func (that *SortedIntArray) Join(glue string) string
- func (that *SortedIntArray) Len() int
- func (that *SortedIntArray) LockFunc(f func(array []int)) *SortedIntArray
- func (that SortedIntArray) MarshalJSON() ([]byte, error)
- func (that *SortedIntArray) Merge(array interface{}) *SortedIntArray
- func (that *SortedIntArray) PopLeft() (value int, found bool)
- func (that *SortedIntArray) PopLefts(size int) []int
- func (that *SortedIntArray) PopRand() (value int, found bool)
- func (that *SortedIntArray) PopRands(size int) []int
- func (that *SortedIntArray) PopRight() (value int, found bool)
- func (that *SortedIntArray) PopRights(size int) []int
- func (that *SortedIntArray) RLockFunc(f func(array []int)) *SortedIntArray
- func (that *SortedIntArray) Rand() (value int, found bool)
- func (that *SortedIntArray) Rands(size int) []int
- func (that *SortedIntArray) Range(start int, end ...int) []int
- func (that *SortedIntArray) Remove(index int) (value int, found bool)
- func (that *SortedIntArray) RemoveValue(value int) bool
- func (that *SortedIntArray) Search(value int) (index int)
- func (that *SortedIntArray) SetArray(array []int) *SortedIntArray
- func (that *SortedIntArray) SetUnique(unique bool) *SortedIntArray
- func (that *SortedIntArray) Slice() []int
- func (that *SortedIntArray) Sort() *SortedIntArray
- func (that *SortedIntArray) String() string
- func (that *SortedIntArray) SubSlice(offset int, length ...int) []int
- func (that *SortedIntArray) Sum() (sum int)
- func (that *SortedIntArray) Unique() *SortedIntArray
- func (that *SortedIntArray) UnmarshalJSON(b []byte) error
- func (that *SortedIntArray) UnmarshalValue(value interface{}) (err error)
- func (that *SortedIntArray) Walk(f func(value int) int) *SortedIntArray
- 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 (that *SortedStrArray) Add(values ...string) *SortedStrArray
- func (that *SortedStrArray) Append(values ...string) *SortedStrArray
- func (that *SortedStrArray) Chunk(size int) [][]string
- func (that *SortedStrArray) Clear() *SortedStrArray
- func (that *SortedStrArray) Clone() (newArray *SortedStrArray)
- func (that *SortedStrArray) Contains(value string) bool
- func (that *SortedStrArray) ContainsI(value string) bool
- func (that *SortedStrArray) CountValues() map[string]int
- func (that *SortedStrArray) FilterEmpty() *SortedStrArray
- func (that *SortedStrArray) Get(index int) (value string, found bool)
- func (that *SortedStrArray) Interfaces() []interface{}
- func (that *SortedStrArray) IsEmpty() bool
- func (that *SortedStrArray) Iterator(f func(k int, v string) bool)
- func (that *SortedStrArray) IteratorAsc(f func(k int, v string) bool)
- func (that *SortedStrArray) IteratorDesc(f func(k int, v string) bool)
- func (that *SortedStrArray) Join(glue string) string
- func (that *SortedStrArray) Len() int
- func (that *SortedStrArray) LockFunc(f func(array []string)) *SortedStrArray
- func (that SortedStrArray) MarshalJSON() ([]byte, error)
- func (that *SortedStrArray) Merge(array interface{}) *SortedStrArray
- func (that *SortedStrArray) PopLeft() (value string, found bool)
- func (that *SortedStrArray) PopLefts(size int) []string
- func (that *SortedStrArray) PopRand() (value string, found bool)
- func (that *SortedStrArray) PopRands(size int) []string
- func (that *SortedStrArray) PopRight() (value string, found bool)
- func (that *SortedStrArray) PopRights(size int) []string
- func (that *SortedStrArray) RLockFunc(f func(array []string)) *SortedStrArray
- func (that *SortedStrArray) Rand() (value string, found bool)
- func (that *SortedStrArray) Rands(size int) []string
- func (that *SortedStrArray) Range(start int, end ...int) []string
- func (that *SortedStrArray) Remove(index int) (value string, found bool)
- func (that *SortedStrArray) RemoveValue(value string) bool
- func (that *SortedStrArray) Search(value string) (index int)
- func (that *SortedStrArray) SetArray(array []string) *SortedStrArray
- func (that *SortedStrArray) SetUnique(unique bool) *SortedStrArray
- func (that *SortedStrArray) Slice() []string
- func (that *SortedStrArray) Sort() *SortedStrArray
- func (that *SortedStrArray) String() string
- func (that *SortedStrArray) SubSlice(offset int, length ...int) []string
- func (that *SortedStrArray) Sum() (sum int)
- func (that *SortedStrArray) Unique() *SortedStrArray
- func (that *SortedStrArray) UnmarshalJSON(b []byte) error
- func (that *SortedStrArray) UnmarshalValue(value interface{}) (err error)
- func (that *SortedStrArray) Walk(f func(value string) string) *SortedStrArray
- 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) ContainsI(value string) bool
- func (a *StrArray) CountValues() map[string]int
- func (a *StrArray) Fill(startIndex int, num int, value string) error
- func (a *StrArray) FilterEmpty() *StrArray
- func (a *StrArray) Get(index int) (value string, found bool)
- func (a *StrArray) InsertAfter(index int, value string) error
- func (a *StrArray) InsertBefore(index int, value string) error
- func (a *StrArray) Interfaces() []interface{}
- func (a *StrArray) IsEmpty() bool
- 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() (value string, found bool)
- func (a *StrArray) PopLefts(size int) []string
- func (a *StrArray) PopRand() (value string, found bool)
- func (a *StrArray) PopRands(size int) []string
- func (a *StrArray) PopRight() (value string, found bool)
- 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() (value string, found bool)
- func (a *StrArray) Rands(size int) []string
- func (a *StrArray) Range(start int, end ...int) []string
- func (a *StrArray) Remove(index int) (value string, found bool)
- 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) error
- 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
- func (a *StrArray) Walk(f func(value string) string) *StrArray
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
}
Array 自定义的的数组
func New ¶
New 创建一个不限制大小的数组
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/darray" ) func main() { // A normal array. a := darray.New() // Adding items. for i := 0; i < 10; i++ { a.Append(i) } // Print the array length. fmt.Println(a.Len()) // Print the array items. fmt.Println(a.Slice()) // Retrieve item by index. fmt.Println(a.Get(6)) // Check item existence. fmt.Println(a.Contains(6)) fmt.Println(a.Contains(100)) // Insert item before specified index. a.InsertAfter(9, 11) // Insert item after specified index. a.InsertBefore(10, 10) fmt.Println(a.Slice()) // Modify item by index. a.Set(0, 100) fmt.Println(a.Slice()) // Search item and return its index. fmt.Println(a.Search(5)) // Remove item by index. a.Remove(0) fmt.Println(a.Slice()) // Empty the array, removes all items of it. fmt.Println(a.Slice()) a.Clear() fmt.Println(a.Slice()) }
Output: 10 [0 1 2 3 4 5 6 7 8 9] 6 true 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] []
func NewArrayFrom ¶ added in v0.0.6
NewArrayFrom 从基础数据结构切片中创建自定义数组
func NewArrayFromCopy ¶ added in v0.0.6
NewArrayFromCopy 创建一个新的自定义数组,值是复制传入的切片
func NewArrayRange ¶ added in v0.0.6
NewArrayRange 创建一个切片,从start开始到end结束,步进未step
func NewArraySize ¶
NewArraySize 创建一个指定大小和上限的数组 size 数组大小 cap 数组元素上限 safe 是否并发安全
func NewFromCopy ¶ added in v0.0.6
NewFromCopy see NewArrayFromCopy
func (*Array) Chunk ¶ added in v0.0.6
Chunk 分片,使用size个数目分片成多个数组,返回二维数组
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/darray" "github.com/osgochina/donkeygo/frame/d" ) func main() { array := darray.NewFrom(d.Slice{1, 2, 3, 4, 5, 6, 7, 8, 9}) // 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. fmt.Println(array.Chunk(2)) }
Output: [[1 2] [3 4] [5 6] [7 8] [9]]
func (*Array) Contains ¶ added in v0.0.6
Contains 判断值在数组是否存在
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/darray" ) func main() { var array darray.StrArray array.Append("a") fmt.Println(array.Contains("a")) fmt.Println(array.Contains("A")) fmt.Println(array.ContainsI("A")) }
Output: true false true
func (*Array) CountValues ¶ added in v0.0.6
CountValues 计算数组各元素的数量
func (*Array) FilterEmpty ¶ added in v0.0.6
FilterEmpty 移除数组中的空元素 Values like: 0, nil, false, "", len(slice/map/chan) == 0 are considered empty.
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/darray" "github.com/osgochina/donkeygo/frame/d" ) func main() { array1 := darray.NewFrom(d.Slice{0, 1, 2, nil, "", d.Slice{}, "john"}) array2 := darray.NewFrom(d.Slice{0, 1, 2, nil, "", d.Slice{}, "john"}) fmt.Printf("%#v\n", array1.FilterNil().Slice()) fmt.Printf("%#v\n", array2.FilterEmpty().Slice()) }
Output: []interface {}{0, 1, 2, "", []interface {}{}, "john"} []interface {}{1, 2, "john"}
func (*Array) FilterNil ¶ added in v0.0.6
FilterNil 移除数组中的nil
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/darray" "github.com/osgochina/donkeygo/frame/d" ) func main() { array1 := darray.NewFrom(d.Slice{0, 1, 2, nil, "", d.Slice{}, "john"}) array2 := darray.NewFrom(d.Slice{0, 1, 2, nil, "", d.Slice{}, "john"}) fmt.Printf("%#v\n", array1.FilterNil().Slice()) fmt.Printf("%#v\n", array2.FilterEmpty().Slice()) }
Output: []interface {}{0, 1, 2, "", []interface {}{}, "john"} []interface {}{1, 2, "john"}
func (*Array) InsertAfter ¶ added in v0.0.6
InsertAfter 在指定的index之后插入值
func (*Array) InsertBefore ¶ added in v0.0.6
InsertBefore 在指定的index之前插入值
func (*Array) Interfaces ¶ added in v0.0.6
func (that *Array) Interfaces() []interface{}
Interfaces 返回数组的当前值
func (*Array) Iterator ¶ added in v0.0.6
Iterator 迭代
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/darray" "github.com/osgochina/donkeygo/frame/d" ) func main() { array := darray.NewArrayFrom(d.Slice{"a", "b", "c"}) // Iterator is alias of IteratorAsc, which iterates the array readonly in ascending order // with given callback function <f>. // If <f> returns true, then it continues iterating; or false to stop. array.Iterator(func(k int, v interface{}) bool { fmt.Println(k, v) return true }) // IteratorDesc iterates the array readonly in descending order with given callback function <f>. // If <f> returns true, then it continues iterating; or false to stop. array.IteratorDesc(func(k int, v interface{}) bool { fmt.Println(k, v) return true }) }
Output: 0 a 1 b 2 c 2 c 1 b 0 a
func (*Array) IteratorAsc ¶ added in v0.0.6
IteratorAsc 顺序迭代
func (*Array) IteratorDesc ¶ added in v0.0.6
IteratorDesc 反向迭代
func (*Array) Join ¶ added in v0.0.6
Join 把数组元素以 glue分隔符链接起来
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/darray" "github.com/osgochina/donkeygo/frame/d" ) func main() { array := darray.NewFrom(d.Slice{"a", "b", "c", "d"}) fmt.Println(array.Join(",")) }
Output: a,b,c,d
func (Array) MarshalJSON ¶ added in v0.0.6
MarshalJSON 序列化成json 这里的Array不能使用指针
func (*Array) Merge ¶ added in v0.0.6
Merge 合并两个数组
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/darray" "github.com/osgochina/donkeygo/frame/d" ) func main() { array1 := darray.NewFrom(d.Slice{1, 2}) array2 := darray.NewFrom(d.Slice{3, 4}) slice1 := d.Slice{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]
func (*Array) Pad ¶ added in v0.0.6
Pad 将数组用指定的值 val 填充到指定的长度 如果size是正的,则数组在右边填充,如果size是负数,则在左边填充。 如果的绝对值小于或等于数组的长度那么不填充。
func (*Array) PopLeft ¶ added in v0.0.6
PopLeft 从左边拿出一个值
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/darray" ) func main() { array := darray.NewFrom([]interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9}) // Any Pop* functions pick, delete and return the item from array. fmt.Println(array.PopLeft()) fmt.Println(array.PopLefts(2)) fmt.Println(array.PopRight()) fmt.Println(array.PopRights(2)) }
Output: 1 true [2 3] 9 true [7 8]
func (*Array) PopLefts ¶ added in v0.0.6
PopLefts 从左边拿出指定数量的值
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/darray" ) func main() { array := darray.NewFrom([]interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9}) // Any Pop* functions pick, delete and return the item from array. fmt.Println(array.PopLeft()) fmt.Println(array.PopLefts(2)) fmt.Println(array.PopRight()) fmt.Println(array.PopRights(2)) }
Output: 1 true [2 3] 9 true [7 8]
func (*Array) PopRand ¶ added in v0.0.6
PopRand 随机从数组中拿出一个值
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/darray" "github.com/osgochina/donkeygo/frame/d" ) func main() { array := darray.NewFrom(d.Slice{1, 2, 3, 4, 5, 6, 7, 8, 9}) // Randomly retrieve and return 2 items from the array. // It does not delete the items from array. fmt.Println(array.Rands(2)) // Randomly pick and return one item from the array. // It deletes the picked up item from array. fmt.Println(array.PopRand()) }
Output:
func (*Array) PopRight ¶ added in v0.0.6
PopRight 从右边拿出一个值
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/darray" ) func main() { array := darray.NewFrom([]interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9}) // Any Pop* functions pick, delete and return the item from array. fmt.Println(array.PopLeft()) fmt.Println(array.PopLefts(2)) fmt.Println(array.PopRight()) fmt.Println(array.PopRights(2)) }
Output: 1 true [2 3] 9 true [7 8]
func (*Array) PopRights ¶ added in v0.0.6
PopRights 从右边拿出指定数量的值
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/darray" ) func main() { array := darray.NewFrom([]interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9}) // Any Pop* functions pick, delete and return the item from array. fmt.Println(array.PopLeft()) fmt.Println(array.PopLefts(2)) fmt.Println(array.PopRight()) fmt.Println(array.PopRights(2)) }
Output: 1 true [2 3] 9 true [7 8]
func (*Array) Rands ¶ added in v0.0.6
Rands 随机返回指定 size 的数组元素
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/darray" "github.com/osgochina/donkeygo/frame/d" ) func main() { array := darray.NewFrom(d.Slice{1, 2, 3, 4, 5, 6, 7, 8, 9}) // Randomly retrieve and return 2 items from the array. // It does not delete the items from array. fmt.Println(array.Rands(2)) // Randomly pick and return one item from the array. // It deletes the picked up item from array. fmt.Println(array.PopRand()) }
Output:
func (*Array) RemoveValue ¶ added in v0.0.6
RemoveValue 查找指定的值,并从数组中移除它
func (*Array) Reverse ¶ added in v0.0.6
Reverse 反向排序数组
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/darray" "github.com/osgochina/donkeygo/frame/d" ) func main() { array := darray.NewFrom(d.Slice{1, 2, 3, 4, 5, 6, 7, 8, 9}) // Reverse makes array with elements in reverse order. fmt.Println(array.Reverse().Slice()) }
Output: [9 8 7 6 5 4 3 2 1]
func (*Array) Shuffle ¶ added in v0.0.6
Shuffle 随机打乱数组中的元素
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/darray" "github.com/osgochina/donkeygo/frame/d" ) func main() { array := darray.NewFrom(d.Slice{1, 2, 3, 4, 5, 6, 7, 8, 9}) // Shuffle randomly shuffles the array. fmt.Println(array.Shuffle().Slice()) }
Output:
func (*Array) UnmarshalJSON ¶ added in v0.0.6
UnmarshalJSON 把json序列化转成数组
func (*Array) UnmarshalValue ¶ added in v0.0.6
UnmarshalValue 把任意值转换成数组
type IntArray ¶ added in v0.0.6
type IntArray struct {
// contains filtered or unexported fields
}
IntArray int类型的数组
func NewIntArrayFrom ¶ added in v0.0.6
NewIntArrayFrom 从基础数据结构切片中创建自定义数组
func NewIntArrayFromCopy ¶ added in v0.0.6
NewIntArrayFromCopy 创建一个新的自定义数组,值是复制传入的切片
func NewIntArrayRange ¶ added in v0.0.6
NewIntArrayRange 创建一个切片,从start开始到end结束,步进未step
func NewIntArraySize ¶ added in v0.0.6
NewIntArraySize 创建指定长度的int类型的数组
func (*IntArray) Chunk ¶ added in v0.0.6
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) Clone ¶ added in v0.0.6
Clone returns a new array, which is a copy of current array.
func (*IntArray) CountValues ¶ added in v0.0.6
CountValues counts the number of occurrences of all values in the array.
func (*IntArray) Fill ¶ added in v0.0.6
Fill fills an array with num entries of the value <value>, keys starting at the <startIndex> parameter.
func (*IntArray) FilterEmpty ¶ added in v0.0.6
FilterEmpty removes all zero value of the array.
func (*IntArray) InsertAfter ¶ added in v0.0.6
InsertAfter 在数组index之后插入value
func (*IntArray) InsertBefore ¶ added in v0.0.6
InsertBefore 在指定index之前插入value
func (*IntArray) Interfaces ¶ added in v0.0.6
func (that *IntArray) Interfaces() []interface{}
Interfaces returns current array as []interface{}.
func (*IntArray) IteratorAsc ¶ added in v0.0.6
IteratorAsc iterates the array readonly in ascending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*IntArray) IteratorDesc ¶ added in v0.0.6
IteratorDesc iterates the array readonly in descending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (IntArray) MarshalJSON ¶ added in v0.0.6
MarshalJSON implements the interface MarshalJSON for json.Marshal. Note that do not use pointer as its receiver here.
func (*IntArray) Merge ¶ added in v0.0.6
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 ¶ added in v0.0.6
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 ¶ added in v0.0.6
PopLeft pops and returns an item from the beginning of array. Note that if the array is empty, the <found> is false.
func (*IntArray) PopLefts ¶ added in v0.0.6
PopLefts pops and returns <size> items from the beginning of array. If the given <size> is greater than size of the array, it returns all elements of the array. Note that if given <size> <= 0 or the array is empty, it returns nil.
func (*IntArray) PopRand ¶ added in v0.0.6
PopRand randomly pops and return thatn item out of array. Note that if the array is empty, the <found> is false.
func (*IntArray) PopRands ¶ added in v0.0.6
PopRands randomly pops and returns <size> items out of array. If the given <size> is greater than size of the array, it returns all elements of the array. Note that if given <size> <= 0 or the array is empty, it returns nil.
func (*IntArray) PopRight ¶ added in v0.0.6
PopRight pops and returns an item from the end of array. Note that if the array is empty, the <found> is false.
func (*IntArray) PopRights ¶ added in v0.0.6
PopRights pops and returns <size> items from the end of array. If the given <size> is greater than size of the array, it returns all elements of the array. Note that if given <size> <= 0 or the array is empty, it returns nil.
func (*IntArray) PushRight ¶ added in v0.0.6
PushRight pushes one or multiple items to the end of array. It equals to Append.
func (*IntArray) Rands ¶ added in v0.0.6
Rands randomly returns <size> items from array(no deleting).
func (*IntArray) Range ¶ added in v0.0.6
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 datthat.
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 v0.0.6
RemoveValue 查找指定的值,并从数组中移除它
func (*IntArray) Search ¶ added in v0.0.6
Search searches array by <value>, returns the index of <value>, or returns -1 if not exists.
func (*IntArray) Slice ¶ added in v0.0.6
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 datthat.
func (*IntArray) String ¶ added in v0.0.6
String returns current array as a string, which implements like json.Marshal does.
func (*IntArray) SubSlice ¶ added in v0.0.6
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) Unique ¶ added in v0.0.6
Unique uniques the array, clear repeated items. Example: [1,1,2,3,2] -> [1,2,3]
func (*IntArray) UnmarshalJSON ¶ added in v0.0.6
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (*IntArray) UnmarshalValue ¶ added in v0.0.6
UnmarshalValue is an interface implement which sets any type of value for array.
type SortedArray ¶
type SortedArray struct {
// contains filtered or unexported fields
}
SortedArray 是一个具有丰富功能的golang排序数组。 默认使用递增顺序,可以通过设置一个自定义比较器 来决定顺序。 它包含一个并行安全/不安全的开关,应该被设置 初始化时不能更改。
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; the v1 will be inserted before v2; if it returns value = 0, means v1 = v2; the v1 will be replaced by v2; if it returns value > 0, means v1 > v2; the v1 will be inserted after 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 ¶
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. It's alias of function Append, see Append.
func (*SortedArray) Append ¶
func (a *SortedArray) Append(values ...interface{}) *SortedArray
Append adds one or multiple values to sorted array, the array always keeps sorted.
func (*SortedArray) At ¶ added in v0.1.9
func (a *SortedArray) At(index int) (value interface{})
At returns the value by the specified index. If the given `index` is out of range of the array, it returns `nil`.
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 ¶
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 ¶
func (a *SortedArray) FilterNil() *SortedArray
FilterNil removes all nil value of the array.
func (*SortedArray) Get ¶
func (a *SortedArray) Get(index int) (value interface{}, found bool)
Get returns the value by the specified index. If the given `index` is out of range of the array, the `found` is false.
func (*SortedArray) Interfaces ¶
func (a *SortedArray) Interfaces() []interface{}
Interfaces returns current array as []interface{}.
func (*SortedArray) IsEmpty ¶
func (a *SortedArray) IsEmpty() bool
IsEmpty checks whether the array is empty.
func (*SortedArray) Iterator ¶
func (a *SortedArray) Iterator(f func(k int, v interface{}) bool)
Iterator is alias of IteratorAsc.
func (*SortedArray) IteratorAsc ¶
func (a *SortedArray) IteratorAsc(f func(k int, v interface{}) bool)
IteratorAsc iterates the array readonly in ascending order with given callback function `f`. If `f` returns true, then it continues iterating; or false to stop.
func (*SortedArray) IteratorDesc ¶
func (a *SortedArray) IteratorDesc(f func(k int, v interface{}) bool)
IteratorDesc iterates the array readonly in descending order with given callback function `f`. If `f` returns true, then it continues iterating; or false to stop.
func (*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. Note that do not use pointer as its receiver here.
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() (value interface{}, found bool)
PopLeft pops and returns an item from the beginning of array. Note that if the array is empty, the `found` is false.
func (*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() (value interface{}, found bool)
PopRand randomly pops and return an item out of array. Note that if the array is empty, the `found` is false.
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() (value interface{}, found bool)
PopRight pops and returns an item from the end of array. Note that if the array is empty, the `found` is false.
func (*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() (value interface{}, found bool)
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) (value interface{}, found bool)
Remove removes an item by index. If the given `index` is out of range of the array, the `found` is false.
func (*SortedArray) RemoveValue ¶
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 ¶
func (a *SortedArray) SetComparator(comparator func(a, b interface{}) int)
SetComparator sets/changes the comparator for sorting. It resorts the array as the comparator is changed.
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 ¶
func (a *SortedArray) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal. Note that the comparator is set as string comparator in default.
func (*SortedArray) UnmarshalValue ¶
func (a *SortedArray) UnmarshalValue(value interface{}) (err error)
UnmarshalValue is an interface implement which sets any type of value for array. Note that the comparator is set as string comparator in default.
func (*SortedArray) Walk ¶
func (a *SortedArray) Walk(f func(value interface{}) interface{}) *SortedArray
Walk applies a user supplied function `f` to every item of array.
type SortedIntArray ¶ added in v0.0.8
type SortedIntArray struct {
// contains filtered or unexported fields
}
SortedIntArray is a golang sorted int array with rich features. It is using increasing order in default, which can be changed by setting it a custom comparator. It contains a concurrent-safe/unsafe switch, which should be set when its initialization and cannot be changed then.
func NewSortedIntArray ¶ added in v0.0.8
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 ¶ added in v0.0.8
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 ¶ added in v0.0.8
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 ¶ added in v0.0.8
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 v0.0.8
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 ¶ added in v0.0.8
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 ¶ added in v0.0.8
func (that *SortedIntArray) Add(values ...int) *SortedIntArray
Add adds one or multiple values to sorted array, the array always keeps sorted. It's alias of function Append, see Append.
func (*SortedIntArray) Append ¶ added in v0.0.8
func (that *SortedIntArray) Append(values ...int) *SortedIntArray
Append adds one or multiple values to sorted array, the array always keeps sorted.
func (*SortedIntArray) Chunk ¶ added in v0.0.8
func (that *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 ¶ added in v0.0.8
func (that *SortedIntArray) Clear() *SortedIntArray
Clear deletes all items of current array.
func (*SortedIntArray) Clone ¶ added in v0.0.8
func (that *SortedIntArray) Clone() (newArray *SortedIntArray)
Clone returns a new array, which is a copy of current array.
func (*SortedIntArray) Contains ¶ added in v0.0.8
func (that *SortedIntArray) Contains(value int) bool
Contains checks whether a value exists in the array.
func (*SortedIntArray) CountValues ¶ added in v0.0.8
func (that *SortedIntArray) CountValues() map[int]int
CountValues counts the number of occurrences of all values in the array.
func (*SortedIntArray) FilterEmpty ¶ added in v0.0.8
func (that *SortedIntArray) FilterEmpty() *SortedIntArray
FilterEmpty removes all zero value of the array.
func (*SortedIntArray) Get ¶ added in v0.0.8
func (that *SortedIntArray) Get(index int) (value int, found bool)
Get returns the value by the specified index. If the given <index> is out of range of the array, the <found> is false.
func (*SortedIntArray) Interfaces ¶ added in v0.0.8
func (that *SortedIntArray) Interfaces() []interface{}
Interfaces returns current array as []interface{}.
func (*SortedIntArray) IsEmpty ¶ added in v0.0.8
func (that *SortedIntArray) IsEmpty() bool
IsEmpty checks whether the array is empty.
func (*SortedIntArray) Iterator ¶ added in v0.0.8
func (that *SortedIntArray) Iterator(f func(k int, v int) bool)
Iterator is alias of IteratorAsc.
func (*SortedIntArray) IteratorAsc ¶ added in v0.0.8
func (that *SortedIntArray) IteratorAsc(f func(k int, v int) bool)
IteratorAsc iterates the array readonly in ascending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*SortedIntArray) IteratorDesc ¶ added in v0.0.8
func (that *SortedIntArray) IteratorDesc(f func(k int, v int) bool)
IteratorDesc iterates the array readonly in descending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*SortedIntArray) Join ¶ added in v0.0.8
func (that *SortedIntArray) Join(glue string) string
Join joins array elements with a string <glue>.
func (*SortedIntArray) Len ¶ added in v0.0.8
func (that *SortedIntArray) Len() int
Len returns the length of array.
func (*SortedIntArray) LockFunc ¶ added in v0.0.8
func (that *SortedIntArray) LockFunc(f func(array []int)) *SortedIntArray
LockFunc locks writing by callback function <f>.
func (SortedIntArray) MarshalJSON ¶ added in v0.0.8
func (that SortedIntArray) MarshalJSON() ([]byte, error)
MarshalJSON implements the interface MarshalJSON for json.Marshal. Note that do not use pointer as its receiver here.
func (*SortedIntArray) Merge ¶ added in v0.0.8
func (that *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 ¶ added in v0.0.8
func (that *SortedIntArray) PopLeft() (value int, found bool)
PopLeft pops and returns an item from the beginning of array. Note that if the array is empty, the <found> is false.
func (*SortedIntArray) PopLefts ¶ added in v0.0.8
func (that *SortedIntArray) PopLefts(size int) []int
PopLefts pops and returns <size> items from the beginning of array. If the given <size> is greater than size of the array, it returns all elements of the array. Note that if given <size> <= 0 or the array is empty, it returns nil.
func (*SortedIntArray) PopRand ¶ added in v0.0.8
func (that *SortedIntArray) PopRand() (value int, found bool)
PopRand randomly pops and return an item out of array. Note that if the array is empty, the <found> is false.
func (*SortedIntArray) PopRands ¶ added in v0.0.8
func (that *SortedIntArray) PopRands(size int) []int
PopRands randomly pops and returns <size> items out of array. If the given <size> is greater than size of the array, it returns all elements of the array. Note that if given <size> <= 0 or the array is empty, it returns nil.
func (*SortedIntArray) PopRight ¶ added in v0.0.8
func (that *SortedIntArray) PopRight() (value int, found bool)
PopRight pops and returns an item from the end of array. Note that if the array is empty, the <found> is false.
func (*SortedIntArray) PopRights ¶ added in v0.0.8
func (that *SortedIntArray) PopRights(size int) []int
PopRights pops and returns <size> items from the end of array. If the given <size> is greater than size of the array, it returns all elements of the array. Note that if given <size> <= 0 or the array is empty, it returns nil.
func (*SortedIntArray) RLockFunc ¶ added in v0.0.8
func (that *SortedIntArray) RLockFunc(f func(array []int)) *SortedIntArray
RLockFunc locks reading by callback function <f>.
func (*SortedIntArray) Rand ¶ added in v0.0.8
func (that *SortedIntArray) Rand() (value int, found bool)
Rand randomly returns one item from array(no deleting).
func (*SortedIntArray) Rands ¶ added in v0.0.8
func (that *SortedIntArray) Rands(size int) []int
Rands randomly returns <size> items from array(no deleting).
func (*SortedIntArray) Range ¶ added in v0.0.8
func (that *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 ¶ added in v0.0.8
func (that *SortedIntArray) Remove(index int) (value int, found bool)
Remove removes an item by index. If the given <index> is out of range of the array, the <found> is false.
func (*SortedIntArray) RemoveValue ¶ added in v0.0.8
func (that *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 ¶ added in v0.0.8
func (that *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 ¶ added in v0.0.8
func (that *SortedIntArray) SetArray(array []int) *SortedIntArray
SetArray sets the underlying slice array with the given <array>.
func (*SortedIntArray) SetUnique ¶ added in v0.0.8
func (that *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 ¶ added in v0.0.8
func (that *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 ¶ added in v0.0.8
func (that *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 ¶ added in v0.0.8
func (that *SortedIntArray) String() string
String returns current array as a string, which implements like json.Marshal does.
func (*SortedIntArray) SubSlice ¶ added in v0.0.8
func (that *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 ¶ added in v0.0.8
func (that *SortedIntArray) Sum() (sum int)
Sum returns the sum of values in an array.
func (*SortedIntArray) Unique ¶ added in v0.0.8
func (that *SortedIntArray) Unique() *SortedIntArray
Unique uniques the array, clear repeated items.
func (*SortedIntArray) UnmarshalJSON ¶ added in v0.0.8
func (that *SortedIntArray) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (*SortedIntArray) UnmarshalValue ¶ added in v0.0.8
func (that *SortedIntArray) UnmarshalValue(value interface{}) (err error)
UnmarshalValue is an interface implement which sets any type of value for array.
func (*SortedIntArray) Walk ¶ added in v0.0.8
func (that *SortedIntArray) Walk(f func(value int) int) *SortedIntArray
Walk applies a user supplied function <f> to every item of array.
type SortedStrArray ¶ added in v0.0.8
type SortedStrArray struct {
// contains filtered or unexported fields
}
SortedStrArray is a golang sorted string array with rich features. It is using increasing order in default, which can be changed by setting it a custom comparator. It contains a concurrent-safe/unsafe switch, which should be set when its initialization and cannot be changed then.
func NewSortedStrArray ¶ added in v0.0.8
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 ¶ added in v0.0.8
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 ¶ added in v0.0.8
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 ¶ added in v0.0.8
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 ¶ added in v0.0.8
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 ¶ added in v0.0.8
func (that *SortedStrArray) Add(values ...string) *SortedStrArray
Add adds one or multiple values to sorted array, the array always keeps sorted. It's alias of function Append, see Append.
func (*SortedStrArray) Append ¶ added in v0.0.8
func (that *SortedStrArray) Append(values ...string) *SortedStrArray
Append adds one or multiple values to sorted array, the array always keeps sorted.
func (*SortedStrArray) Chunk ¶ added in v0.0.8
func (that *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 ¶ added in v0.0.8
func (that *SortedStrArray) Clear() *SortedStrArray
Clear deletes all items of current array.
func (*SortedStrArray) Clone ¶ added in v0.0.8
func (that *SortedStrArray) Clone() (newArray *SortedStrArray)
Clone returns a new array, which is a copy of current array.
func (*SortedStrArray) Contains ¶ added in v0.0.8
func (that *SortedStrArray) Contains(value string) bool
Contains checks whether a value exists in the array.
func (*SortedStrArray) ContainsI ¶ added in v0.0.8
func (that *SortedStrArray) ContainsI(value string) bool
ContainsI checks whether a value exists in the array with case-insensitively. Note that it internally iterates the whole array to do the comparison with case-insensitively.
func (*SortedStrArray) CountValues ¶ added in v0.0.8
func (that *SortedStrArray) CountValues() map[string]int
CountValues counts the number of occurrences of all values in the array.
func (*SortedStrArray) FilterEmpty ¶ added in v0.0.8
func (that *SortedStrArray) FilterEmpty() *SortedStrArray
FilterEmpty removes all empty string value of the array.
func (*SortedStrArray) Get ¶ added in v0.0.8
func (that *SortedStrArray) Get(index int) (value string, found bool)
Get returns the value by the specified index. If the given <index> is out of range of the array, the <found> is false.
func (*SortedStrArray) Interfaces ¶ added in v0.0.8
func (that *SortedStrArray) Interfaces() []interface{}
Interfaces returns current array as []interface{}.
func (*SortedStrArray) IsEmpty ¶ added in v0.0.8
func (that *SortedStrArray) IsEmpty() bool
IsEmpty checks whether the array is empty.
func (*SortedStrArray) Iterator ¶ added in v0.0.8
func (that *SortedStrArray) Iterator(f func(k int, v string) bool)
Iterator is alias of IteratorAsc.
func (*SortedStrArray) IteratorAsc ¶ added in v0.0.8
func (that *SortedStrArray) IteratorAsc(f func(k int, v string) bool)
IteratorAsc iterates the array readonly in ascending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*SortedStrArray) IteratorDesc ¶ added in v0.0.8
func (that *SortedStrArray) IteratorDesc(f func(k int, v string) bool)
IteratorDesc iterates the array readonly in descending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*SortedStrArray) Join ¶ added in v0.0.8
func (that *SortedStrArray) Join(glue string) string
Join joins array elements with a string <glue>.
func (*SortedStrArray) Len ¶ added in v0.0.8
func (that *SortedStrArray) Len() int
Len returns the length of array.
func (*SortedStrArray) LockFunc ¶ added in v0.0.8
func (that *SortedStrArray) LockFunc(f func(array []string)) *SortedStrArray
LockFunc locks writing by callback function <f>.
func (SortedStrArray) MarshalJSON ¶ added in v0.0.8
func (that SortedStrArray) MarshalJSON() ([]byte, error)
MarshalJSON implements the interface MarshalJSON for json.Marshal. Note that do not use pointer as its receiver here.
func (*SortedStrArray) Merge ¶ added in v0.0.8
func (that *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 ¶ added in v0.0.8
func (that *SortedStrArray) PopLeft() (value string, found bool)
PopLeft pops and returns an item from the beginning of array. Note that if the array is empty, the <found> is false.
func (*SortedStrArray) PopLefts ¶ added in v0.0.8
func (that *SortedStrArray) PopLefts(size int) []string
PopLefts pops and returns <size> items from the beginning of array. If the given <size> is greater than size of the array, it returns all elements of the array. Note that if given <size> <= 0 or the array is empty, it returns nil.
func (*SortedStrArray) PopRand ¶ added in v0.0.8
func (that *SortedStrArray) PopRand() (value string, found bool)
PopRand randomly pops and return an item out of array. Note that if the array is empty, the <found> is false.
func (*SortedStrArray) PopRands ¶ added in v0.0.8
func (that *SortedStrArray) PopRands(size int) []string
PopRands randomly pops and returns <size> items out of array. If the given <size> is greater than size of the array, it returns all elements of the array. Note that if given <size> <= 0 or the array is empty, it returns nil.
func (*SortedStrArray) PopRight ¶ added in v0.0.8
func (that *SortedStrArray) PopRight() (value string, found bool)
PopRight pops and returns an item from the end of array. Note that if the array is empty, the <found> is false.
func (*SortedStrArray) PopRights ¶ added in v0.0.8
func (that *SortedStrArray) PopRights(size int) []string
PopRights pops and returns <size> items from the end of array. If the given <size> is greater than size of the array, it returns all elements of the array. Note that if given <size> <= 0 or the array is empty, it returns nil.
func (*SortedStrArray) RLockFunc ¶ added in v0.0.8
func (that *SortedStrArray) RLockFunc(f func(array []string)) *SortedStrArray
RLockFunc locks reading by callback function <f>.
func (*SortedStrArray) Rand ¶ added in v0.0.8
func (that *SortedStrArray) Rand() (value string, found bool)
Rand randomly returns one item from array(no deleting).
func (*SortedStrArray) Rands ¶ added in v0.0.8
func (that *SortedStrArray) Rands(size int) []string
Rands randomly returns <size> items from array(no deleting).
func (*SortedStrArray) Range ¶ added in v0.0.8
func (that *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 datthat.
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 ¶ added in v0.0.8
func (that *SortedStrArray) Remove(index int) (value string, found bool)
Remove removes an item by index. If the given <index> is out of range of the array, the <found> is false.
func (*SortedStrArray) RemoveValue ¶ added in v0.0.8
func (that *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 ¶ added in v0.0.8
func (that *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 ¶ added in v0.0.8
func (that *SortedStrArray) SetArray(array []string) *SortedStrArray
SetArray sets the underlying slice array with the given <array>.
func (*SortedStrArray) SetUnique ¶ added in v0.0.8
func (that *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 ¶ added in v0.0.8
func (that *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 datthat.
func (*SortedStrArray) Sort ¶ added in v0.0.8
func (that *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 ¶ added in v0.0.8
func (that *SortedStrArray) String() string
String returns current array as a string, which implements like json.Marshal does.
func (*SortedStrArray) SubSlice ¶ added in v0.0.8
func (that *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 ¶ added in v0.0.8
func (that *SortedStrArray) Sum() (sum int)
Sum returns the sum of values in an array.
func (*SortedStrArray) Unique ¶ added in v0.0.8
func (that *SortedStrArray) Unique() *SortedStrArray
Unique uniques the array, clear repeated items.
func (*SortedStrArray) UnmarshalJSON ¶ added in v0.0.8
func (that *SortedStrArray) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (*SortedStrArray) UnmarshalValue ¶ added in v0.0.8
func (that *SortedStrArray) UnmarshalValue(value interface{}) (err error)
UnmarshalValue is an interface implement which sets any type of value for array.
func (*SortedStrArray) Walk ¶ added in v0.0.8
func (that *SortedStrArray) Walk(f func(value string) string) *SortedStrArray
Walk applies a user supplied function <f> to every item of array.
type StrArray ¶
type StrArray struct {
// contains filtered or unexported fields
}
StrArray is a golang string array with rich features. It contains a concurrent-safe/unsafe switch, which should be set when its initialization and cannot be changed then.
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) ContainsI ¶
ContainsI checks whether a value exists in the array with case-insensitively. Note that it internally iterates the whole array to do the comparison with case-insensitively.
func (*StrArray) CountValues ¶
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 ¶
FilterEmpty removes all empty string value of the array.
func (*StrArray) Get ¶
Get returns the value by the specified index. If the given <index> is out of range of the array, the <found> is false.
func (*StrArray) InsertAfter ¶
InsertAfter inserts the <value> to the back of <index>.
func (*StrArray) InsertBefore ¶
InsertBefore inserts the <value> to the front of <index>.
func (*StrArray) Interfaces ¶
func (a *StrArray) Interfaces() []interface{}
Interfaces returns current array as []interface{}.
func (*StrArray) IteratorAsc ¶
IteratorAsc iterates the array readonly in ascending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (*StrArray) IteratorDesc ¶
IteratorDesc iterates the array readonly in descending order with given callback function <f>. If <f> returns true, then it continues iterating; or false to stop.
func (StrArray) MarshalJSON ¶
MarshalJSON implements the interface MarshalJSON for json.Marshal. Note that do not use pointer as its receiver here.
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) PopLeft ¶
PopLeft pops and returns an item from the beginning of array. Note that if the array is empty, the <found> is false.
func (*StrArray) PopLefts ¶
PopLefts pops and returns <size> items from the beginning of array. If the given <size> is greater than size of the array, it returns all elements of the array. Note that if given <size> <= 0 or the array is empty, it returns nil.
func (*StrArray) PopRand ¶
PopRand randomly pops and return an item out of array. Note that if the array is empty, the <found> is false.
func (*StrArray) PopRands ¶
PopRands randomly pops and returns <size> items out of array. If the given <size> is greater than size of the array, it returns all elements of the array. Note that if given <size> <= 0 or the array is empty, it returns nil.
func (*StrArray) PopRight ¶
PopRight pops and returns an item from the end of array. Note that if the array is empty, the <found> is false.
func (*StrArray) PopRights ¶
PopRights pops and returns <size> items from the end of array. If the given <size> is greater than size of the array, it returns all elements of the array. Note that if given <size> <= 0 or the array is empty, it returns nil.
func (*StrArray) 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) Remove ¶
Remove removes an item by index. If the given <index> is out of range of the array, the <found> is false.
func (*StrArray) RemoveValue ¶
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) Unique ¶
Unique uniques the array, clear repeated items. Example: [1,1,2,3,2] -> [1,2,3]
func (*StrArray) UnmarshalJSON ¶
UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (*StrArray) UnmarshalValue ¶
UnmarshalValue is an interface implement which sets any type of value for array.
func (*StrArray) Walk ¶
Walk applies a user supplied function <f> to every item of array.
Example ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/container/darray" "github.com/osgochina/donkeygo/frame/d" ) func main() { var array darray.StrArray tables := d.SliceStr{"user", "user_detail"} prefix := "gf_" array.Append(tables...) // Add prefix for given table names. array.Walk(func(value string) string { return prefix + value }) fmt.Println(array.Slice()) }
Output: [gf_user gf_user_detail]