Documentation
¶
Index ¶
- func Sort(slice interface{}, less func(i, j int) bool)
- func Sort2(slice interface{}, less func(i, j int) bool, swap func(i, j int))
- func SortInterface(slice interface{}, less func(i, j int) bool) sort.Interface
- func SortInterface2(slice interface{}, less func(i, j int) bool, swap func(i, j int)) sort.Interface
- type Interfaces
- func (s *Interfaces) Append(data ...interface{})
- func (s Interfaces) Cap() int
- func (s Interfaces) Copy() Interfaces
- func (s *Interfaces) Insert(index int, data ...interface{})
- func (s Interfaces) Len() int
- func (s *Interfaces) Prepend(data ...interface{})
- func (s *Interfaces) Remove(index, num int) int
- func (s Interfaces) Shuffle() Interfaces
- func (s Interfaces) Swap(i, j int)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Sort ¶
Sort 方便对切片进行排序
Example ¶
package main
import (
"fmt"
"github.com/recallsong/go-utils/container/slice"
)
type Persion struct {
Name string
}
func main() {
ps := []Persion{
Persion{Name: "333"},
Persion{Name: "111"},
Persion{Name: "444"},
Persion{Name: "222"},
}
slice.Sort(ps, func(i, j int) bool { return ps[i].Name < ps[j].Name })
fmt.Println(ps)
}
Output: [{111} {222} {333} {444}]
func SortInterface ¶
SortInterface 返回可以排序的sort.Interface接口
Types ¶
type Interfaces ¶
type Interfaces []interface{}
Interfaces 定义方便操作[]interface{}的类型
Example ¶
package main
import (
"fmt"
"github.com/recallsong/go-utils/container/slice"
)
func main() {
s := slice.Interfaces{}
s.Append(1, 2)
s.Prepend(-4, -3, -2, -1, 0)
s.Insert(1, 3, 4, 5, 6)
fmt.Println(s, s.Len())
s1 := s.Copy()
removed := s1.Remove(3, 6)
fmt.Println(s1, s1.Len(), removed)
}
Output: [-4 3 4 5 6 -3 -2 -1 0 1 2] 11 [-4 3 4 1 2] 5 6
func (*Interfaces) Remove ¶
func (s *Interfaces) Remove(index, num int) int
Remove 从指定位置删除指定数量的数据,返回被删除的数据数量
Click to show internal directories.
Click to hide internal directories.