1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

refactoring: rename slice_parallel to slice_concurrent

This commit is contained in:
dudaodong
2024-08-14 10:52:36 +08:00
parent 5c53cb5867
commit 7f78a6b11e
5 changed files with 21 additions and 18 deletions

View File

@@ -41,7 +41,7 @@ func MapConcurrent[T any, U any](slice []T, numOfThreads int, iteratee func(inde
// If numOfThreads is less than or equal to 0, it will be set to 1
// The comparator function should return true if the two elements are equal
// Play: todo
func UniqueByParallel[T comparable](slice []T, numOfThreads int, comparator func(item T, other T) bool) []T {
func UniqueByConcurrent[T comparable](slice []T, numOfThreads int, comparator func(item T, other T) bool) []T {
if numOfThreads <= 0 {
numOfThreads = 1
} else if numOfThreads > len(slice) {

View File

@@ -1186,12 +1186,12 @@ func ExampleLeftPadding() {
// [0 0 0 1 2 3 4 5]
}
func ExampleUniqueByParallel() {
func ExampleUniqueByConcurrent() {
nums := []int{1, 2, 3, 1, 2, 4, 5, 6, 4, 7}
numOfThreads := 4
comparator := func(item int, other int) bool { return item == other }
result := UniqueByParallel(nums, numOfThreads, comparator)
result := UniqueByConcurrent(nums, numOfThreads, comparator)
fmt.Println(result)

View File

@@ -1503,16 +1503,16 @@ func TestRightPaddingAndLeftPadding(t *testing.T) {
assert.Equal([]int{0, 0, 0, 1, 2, 3, 4, 5, 0, 0, 0}, padded)
}
func TestUniqueByParallel(t *testing.T) {
func TestUniqueByConcurrent(t *testing.T) {
t.Parallel()
assert := internal.NewAssert(t, "TestUniqueByParallel")
assert := internal.NewAssert(t, "TestUniqueByConcurrent")
nums := []int{1, 2, 3, 1, 2, 4, 5, 6, 4, 7}
numOfThreads := 4
comparator := func(item int, other int) bool { return item == other }
result := UniqueByParallel(nums, numOfThreads, comparator)
result := UniqueByConcurrent(nums, numOfThreads, comparator)
assert.Equal([]int{1, 2, 3, 4, 5, 6, 7}, result)
}