mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 12:42:34 +02:00
chore: update set/map parallel logic
This commit is contained in:
parent
8e37627371
commit
fdac2853af
3 changed files with 8 additions and 2 deletions
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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue