chore: update set/map parallel logic

This commit is contained in:
yusing 2025-04-04 00:46:24 +08:00
parent 8e37627371
commit fdac2853af
3 changed files with 8 additions and 2 deletions

View file

@ -0,0 +1,3 @@
package functional
const minParallelSize = 2

View file

@ -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...)}
}

View file

@ -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 {