项目作者: go-flip

项目描述 :
Routines for flipping slices in Go.
高级语言: Go
项目地址: git://github.com/go-flip/flip.git
创建时间: 2020-09-21T17:42:43Z
项目社区:https://github.com/go-flip/flip

开源协议:MIT License

下载


flip

buddy pipeline
Go Report Card
PkgGoDev

Routines for flipping slices in Go.

Usage

  1. package main
  2. import "github.com/go-flip/flip"
  3. // IntSlice is equivalent to flip.IntSlice.
  4. type IntSlice []int
  5. // Len returns the length of the slice.
  6. func (p IntSlice) Len() int {
  7. return len(p)
  8. }
  9. // Swap swaps the elements at the given indices.
  10. func (p IntSlice) Swap(i, j int) {
  11. p[i], p[j] = p[j], p[i]
  12. }
  13. func main() {
  14. p := []int{1, 2, 3, 4}
  15. flip.Flip(IntSlice(p))
  16. fmt.Println(p)
  17. }

flip can flip the contents of a slice by using the Len() and Swap() methods provided.
If a type already satisfies sort.Interface, it can be passed directly to flip.Flip.
Some interfaces for primitive slice types are implemented in the module.
See the documentation for available types.