Documentation ¶
Index ¶
- func IndexAes[T constraints.Ordered](slice []T, elem T) int
- func IndexDesc[T constraints.Ordered](slice []T, elem T) int
- func IndexSet[T constraints.Ordered](slice []T, elem T) int
- func InsertAes[T constraints.Ordered](slice []T, elem T) []T
- func InsertDesc[T constraints.Ordered](slice []T, elem T) []T
- func Sort[T constraints.Ordered](elems []T)
- type Ordered
- type Set
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IndexAes ¶ added in v1.0.35
func IndexAes[T constraints.Ordered](slice []T, elem T) int
func IndexDesc ¶ added in v1.0.35
func IndexDesc[T constraints.Ordered](slice []T, elem T) int
func IndexSet ¶ added in v1.0.35
func IndexSet[T constraints.Ordered](slice []T, elem T) int
func InsertAes ¶ added in v1.0.35
func InsertAes[T constraints.Ordered](slice []T, elem T) []T
Example ¶
package main import ( "fmt" "github.com/xuender/kit/ordered" ) func main() { fmt.Println(ordered.InsertAes([]int{}, 1)) fmt.Println(ordered.InsertAes([]int{3}, 1)) fmt.Println(ordered.InsertAes([]int{3}, 5)) fmt.Println(ordered.InsertAes([]int{1, 3}, 2)) fmt.Println(ordered.InsertAes([]int{1, 1, 2, 3, 3, 3, 4}, 4)) }
Output: [1] [1 3] [3 5] [1 2 3] [1 1 2 3 3 3 4 4]
func InsertDesc ¶ added in v1.0.35
func InsertDesc[T constraints.Ordered](slice []T, elem T) []T
Example ¶
package main import ( "fmt" "github.com/xuender/kit/ordered" ) func main() { fmt.Println(ordered.InsertDesc([]int{}, 3)) fmt.Println(ordered.InsertDesc([]int{1}, 3)) fmt.Println(ordered.InsertDesc([]int{3}, 1)) fmt.Println(ordered.InsertDesc([]int{3, 1}, 2)) fmt.Println(ordered.InsertDesc([]int{4, 3, 3, 3, 2, 1, 1}, 4)) }
Output: [3] [3 1] [3 1] [3 2 1] [4 4 3 3 3 2 1 1]
func Sort ¶
func Sort[T constraints.Ordered](elems []T)
Sort ordered.
Example ¶
package main import ( "fmt" "github.com/xuender/kit/ordered" ) func main() { ints := []int{2, 1, 5, 4, 3} ordered.Sort(ints) fmt.Println(ints) uint32s := []uint32{2, 1, 5, 4, 3} ordered.Sort(uint32s) fmt.Println(uint32s) floats := []float32{2.2, 1.1, 5.5, 4.4, 3.3} ordered.Sort(floats) fmt.Println(floats) }
Output: [1 2 3 4 5] [1 2 3 4 5] [1.1 2.2 3.3 4.4 5.5]
Types ¶
type Ordered ¶
type Ordered[T constraints.Ordered] []T
type Set ¶ added in v1.0.35
type Set[T constraints.Ordered] []T
func NewSet ¶ added in v1.0.35
func NewSet[T constraints.Ordered](slice ...T) Set[T]
func (*Set[T]) Add ¶ added in v1.0.35
func (p *Set[T]) Add(elem T)
Example ¶
package main import ( "fmt" "github.com/xuender/kit/ordered" ) func main() { set := ordered.NewSet(1) set.Add(1) set.Add(2) set.Add(3) set.Add(2) fmt.Println(len(set)) fmt.Println(set) }
Output: 3 [1 2 3]
func (Set[T]) Has ¶ added in v1.0.35
Example ¶
package main import ( "fmt" "github.com/xuender/kit/ordered" ) func main() { set := ordered.NewSet(2, 1, 3) fmt.Println(set.Has(2)) fmt.Println(set.Has(1)) fmt.Println(set.Has(3)) fmt.Println(set.Has(0)) fmt.Println(set.Has(4)) }
Output: true true true false false
Click to show internal directories.
Click to hide internal directories.