mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-22 17:19:06 +01:00
chore: update set/map parallel logic
This commit is contained in:
3
internal/utils/functional/common.go
Normal file
3
internal/utils/functional/common.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package functional
|
||||
|
||||
const minParallelSize = 2
|
||||
@@ -11,8 +11,6 @@ type Map[KT comparable, VT any] struct {
|
||||
*xsync.MapOf[KT, VT]
|
||||
}
|
||||
|
||||
const minParallelSize = 4
|
||||
|
||||
func NewMapOf[KT comparable, VT any](options ...func(*xsync.MapConfig)) Map[KT, VT] {
|
||||
return Map[KT, VT]{xsync.NewMapOf[KT, VT](options...)}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,11 @@ func (set Set[T]) RangeAll(f func(T)) {
|
||||
}
|
||||
|
||||
func (set Set[T]) RangeAllParallel(f func(T)) {
|
||||
if set.Size() < minParallelSize {
|
||||
set.RangeAll(f)
|
||||
return
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
set.Range(func(k T) bool {
|
||||
|
||||
Reference in New Issue
Block a user