diff --git a/check.bat b/check.bat new file mode 100644 index 0000000..3733f87 --- /dev/null +++ b/check.bat @@ -0,0 +1,9 @@ +go build + +go test ./... -coverprofile=coverage.out + +golint + +gosec . + +go tool cover -html=coverage.out diff --git a/generated_doc.md b/generated_doc.md index 4ebc35b..7fb4131 100755 --- a/generated_doc.md +++ b/generated_doc.md @@ -433,7 +433,7 @@ Fill fills each element in slice a with new value v. Complexity: O\(len\(a\)\). -## func [FillPattern]() +## func [FillPattern]() ```go func FillPattern[T any](a []T, pattern []T) @@ -444,13 +444,13 @@ FillPattern fills elements in slice a with specified pattern. Complexity: O\(len\(a\)\). -## func [FillZero]() +## func [FillZero]() ```go func FillZero[T any](a []T) ``` -Fill fills each element in slice a with zero value. +FillZero fills each element in slice a with zero value. Complexity: O\(len\(a\)\). @@ -750,7 +750,7 @@ Range make a \[\]T filled with values in the \`\[first, last\)\` sequence. NOTE: Complexity: O\(last\-first\). -## func [Remove]() +## func [Remove]() ```go func Remove[T comparable](a []T, x T) []T @@ -761,7 +761,7 @@ Remove remove the elements which equals to x from the input slice. return the pr Complexity: O\(len\(a\)\). -## func [RemoveCopy]() +## func [RemoveCopy]() ```go func RemoveCopy[T comparable](a []T, x T) []T @@ -783,7 +783,7 @@ RemoveHeapFunc removes and returns the element at index i from the heap. Complexity: is O\(log\(n\)\) where n = len\(\*heap\). -## func [RemoveIf]() +## func [RemoveIf]() ```go func RemoveIf[T any](a []T, cond func(T) bool) []T @@ -794,7 +794,7 @@ RemoveIf remove each element which make cond\(x\) returns true from the input sl Complexity: O\(len\(a\)\). -## func [RemoveIfCopy]() +## func [RemoveIfCopy]() ```go func RemoveIfCopy[T any](a []T, cond func(T) bool) []T @@ -816,7 +816,7 @@ RemoveMinHeap removes and returns the element at index i from the min heap. Complexity: is O\(log\(n\)\) where n = len\(\*heap\). -## func [Replace]() +## func [Replace]() ```go func Replace[T comparable](a []T, old, new T) @@ -827,7 +827,7 @@ Replace replaces every element that equals to old with new. Complexity: O\(len\(a\)\). -## func [ReplaceIf]() +## func [ReplaceIf]() ```go func ReplaceIf[T any](a []T, pred func(v T) bool, new T) @@ -838,7 +838,7 @@ ReplaceIf replaces every element that make preq returns true with new. Complexity: O\(len\(a\)\). -## func [Reverse]() +## func [Reverse]() ```go func Reverse[T any](a []T) @@ -849,7 +849,7 @@ Reverse reverses the order of the elements in the slice a. Complexity: O\(len\(a\)\). -## func [ReverseCopy]() +## func [ReverseCopy]() ```go func ReverseCopy[T any](a []T) []T @@ -860,7 +860,7 @@ ReverseCopy returns a reversed copy of slice a. Complexity: O\(len\(a\)\). -## func [Shuffle]() +## func [Shuffle]() ```go func Shuffle[T any](a []T) @@ -933,7 +933,7 @@ func SumAs[R, T Numeric](a []T) R SumAs summarize all elements in a. returns the result as type R, this is useful when T is too small to hold the result. Complexity: O\(len\(a\)\). -## func [Transform]() +## func [Transform]() ```go func Transform[T any](a []T, op func(T) T) @@ -944,7 +944,7 @@ Transform applies the function op to each element in slice a and set it back to Complexity: O\(len\(a\)\). -## func [TransformCopy]() +## func [TransformCopy]() ```go func TransformCopy[R any, T any](a []T, op func(T) R) []R @@ -955,7 +955,7 @@ TransformCopy applies the function op to each element in slice a and return all Complexity: O\(len\(a\)\). -## func [TransformTo]() +## func [TransformTo]() ```go func TransformTo[R any, T any](a []T, op func(T) R, b []R) []R @@ -966,7 +966,7 @@ TransformTo applies the function op to each element in slice a and fill it to sl Complexity: O\(len\(a\)\). -## func [Unique]() +## func [Unique]() ```go func Unique[T comparable](a []T) []T @@ -977,7 +977,7 @@ Unique remove adjacent repeated elements from the input slice. return the proces Complexity: O\(len\(a\)\). -## func [UniqueCopy]() +## func [UniqueCopy]() ```go func UniqueCopy[T comparable](a []T) []T diff --git a/transform.go b/transform.go index 3dbc92e..9123527 100644 --- a/transform.go +++ b/transform.go @@ -36,14 +36,6 @@ func Fill[T any](a []T, v T) { } } -// FillZero fills each element in slice a with zero value. -// -// Complexity: O(len(a)). -func FillZero[T any](a []T) { - var zero T - Fill(a, zero) -} - // FillPattern fills elements in slice a with specified pattern. // // Complexity: O(len(a)). diff --git a/transform_fillzero_clear.go b/transform_fillzero_clear.go new file mode 100644 index 0000000..0152bd3 --- /dev/null +++ b/transform_fillzero_clear.go @@ -0,0 +1,11 @@ +//go:build go1.21 +// +build go1.21 + +package stl4go + +// FillZero fills each element in slice a with zero value. +// +// Complexity: O(len(a)). +func FillZero[T any](a []T) { + clear(a) +} diff --git a/transform_fillzero_old.go b/transform_fillzero_old.go new file mode 100644 index 0000000..6a01d01 --- /dev/null +++ b/transform_fillzero_old.go @@ -0,0 +1,12 @@ +//go:build !go1.21 +// +build !go1.21 + +package stl4go + +// FillZero fills each element in slice a with zero value. +// +// Complexity: O(len(a)). +func FillZero[T any](a []T) { + var zero T + Fill(a, zero) +} diff --git a/updatedoc.bat b/updatedoc.bat new file mode 100644 index 0000000..7d83fd1 --- /dev/null +++ b/updatedoc.bat @@ -0,0 +1,3 @@ +@echo off + +gomarkdoc -o generated_doc.md -e .