diff options
| author | Shulhan <ms@kilabit.info> | 2024-12-28 23:46:40 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2024-12-29 00:06:17 +0700 |
| commit | 5b18bbf05850851db2c655762d1b55bd093ffcd7 (patch) | |
| tree | e82cc53b42629c7a38dd2e6a19343f289ec8a026 | |
| parent | ec3fac32072a396a02b699065cb091ab292b9381 (diff) | |
| download | pakakeh.go-5b18bbf05850851db2c655762d1b55bd093ffcd7.tar.xz | |
lib/numbers: fix package documentation that should be lib/slices
| -rw-r--r-- | lib/numbers/numbers.go | 18 | ||||
| -rw-r--r-- | lib/slices/slices.go | 16 |
2 files changed, 16 insertions, 18 deletions
diff --git a/lib/numbers/numbers.go b/lib/numbers/numbers.go index 196142ef..8d097746 100644 --- a/lib/numbers/numbers.go +++ b/lib/numbers/numbers.go @@ -2,20 +2,6 @@ // // SPDX-License-Identifier: BSD-3-Clause -// Package numbers provide miscellaneous functions for working with integer, -// float, slice of integer, and slice of floats. -// -// # Features -// -// List of current features, -// -// - sort slice of floats using in-place mergesort algorithm. -// - sort slice of integer/floats by predefined index -// - count number of value occurrence in slice of integer/float -// - find minimum or maximum value in slice of integer/float -// - sum slice of integer/float +// Package numbers provide miscellaneous functions for working with integer +// and float. package numbers - -// SortThreshold when the data less than SortThreshold, insertion sort -// will be used to replace mergesort. -const SortThreshold = 7 diff --git a/lib/slices/slices.go b/lib/slices/slices.go index 40c80629..70bfb7d7 100644 --- a/lib/slices/slices.go +++ b/lib/slices/slices.go @@ -3,7 +3,15 @@ // SPDX-License-Identifier: BSD-3-Clause // Package slices complement the standard [slices] package for working with -// slices with type that is comparable. +// slices comparable and [cmp.Ordered] types. +// +// List of current features, +// +// - sort slice of [cmp.Ordered] types using in-place mergesort algorithm. +// - sort slice of [cmp.Ordered] types by predefined index. +// - count number of value occurrence in slice of [comparable] types. +// - find minimum or maximum value in slice of [cmp.Ordered] types. +// - sum slice of [constraints.Integer] or [constraints.Float] types. package slices import ( @@ -12,6 +20,10 @@ import ( "golang.org/x/exp/constraints" ) +// sortThreshold when the data less than sortThreshold, insertion sort +// will be used to replace mergesort. +const sortThreshold = 7 + // Count the number of occurence of val in slice. func Count[S []E, E comparable](slice S, val E) (count int) { if len(slice) == 0 { @@ -91,7 +103,7 @@ func InplaceInsertionSort[S []E, E cmp.Ordered]( func InplaceMergesort[S []E, E cmp.Ordered]( slice S, ids []int, l, r int, isAsc bool, ) { - if l+7 >= r { + if r-l <= sortThreshold { // If data length <= Threshold, then use insertion sort. InplaceInsertionSort(slice, ids, l, r, isAsc) return |
