diff --git a/misc.go b/misc.go index 3f3ff02..282d65c 100644 --- a/misc.go +++ b/misc.go @@ -42,7 +42,7 @@ func assert(cond bool) { } func deleteFromSlice[T comparable](slc []T, val T) []T { - toReturn := make([]T, 0) + toReturn := make([]T, 0, len(slc)) for _, v := range slc { if v != val { toReturn = append(toReturn, v) @@ -77,7 +77,7 @@ func allEqual[T comparable](items ...T) bool { // Returns all elements in slice A that are NOT in slice B func setDifference[T comparable](s1 []T, s2 []T) []T { - toReturn := make([]T, 0) + toReturn := make([]T, 0, len(s1)) for _, val := range s1 { if !slices.Contains(s2, val) { toReturn = append(toReturn, val) @@ -110,3 +110,12 @@ func Reduce[T any](slc []T, fn func(T, T) T) T { } return slc[0] } + +// Generate numbers in a range - start (inclusive) to end (exclusive) +func genRange(start, end int) []int { + toRet := make([]int, end-start) + for i := start; i < end; i++ { + toRet[i-start] = i + } + return toRet +}