Skip to content

Commit

Permalink
fix: fix compile error (duke-git#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
yguilai committed Oct 17, 2024
1 parent 213e2b4 commit 50c0994
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 2 additions & 6 deletions slice/slice_concurrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,14 @@ func UniqueByConcurrent[T comparable](slice []T, comparator func(item T, other T
chunks = append(chunks, slice[i:end])
}

type resultChunk struct {
index int
data []T
}
resultCh := make(chan resultChunk, numThreads)
resultCh := make(chan resultChunk[T], numThreads)
var wg sync.WaitGroup

for i, chunk := range chunks {
wg.Add(1)
go func(index int, chunk []T) {
defer wg.Done()
resultCh <- resultChunk{index, removeDuplicate(chunk, comparator)}
resultCh <- resultChunk[T]{index, removeDuplicate(chunk, comparator)}
}(i, chunk)
}

Expand Down
7 changes: 7 additions & 0 deletions slice/slice_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import (
"golang.org/x/exp/constraints"
)

// resultChunk is used to store the intermediate results of UniqueByConcurrent.
// It is defined separately to be compatible with versions of go up to 1.20.
type resultChunk[T comparable] struct {
index int
data []T
}

// sliceValue return the reflect value of a slice
func sliceValue(slice any) reflect.Value {
v := reflect.ValueOf(slice)
Expand Down

0 comments on commit 50c0994

Please sign in to comment.