Files
obitools4/pkg/obiutils/slices.go
Eric Coissac 60c187404d Restore old obisort and add LCA functionnality to obiannotate.
Former-commit-id: aecaacc9dae49f74bd888a8eb8140822d31a42a6
2023-05-02 10:43:22 +02:00

37 lines
582 B
Go

package obiutils
func Contains[T comparable](arr []T, x T) bool {
for _, v := range arr {
if v == x {
return true
}
}
return false
}
func LookFor[T comparable](arr []T, x T) int {
for i, v := range arr {
if v == x {
return i
}
}
return -1
}
func RemoveIndex[T comparable](s []T, index int) []T {
return append(s[:index], s[index+1:]...)
}
func Reverse[S ~[]E, E any](s S, inplace bool) S {
if !inplace {
c := make([]E,len(s))
copy(c,s)
s = c
}
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
return s
}