Skip to content

Commit

Permalink
define minChunkSize
Browse files Browse the repository at this point in the history
  • Loading branch information
gaissmai committed Feb 6, 2023
1 parent 89d0e1f commit 562cdd3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions treap.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,17 @@ func NewTreeConcurrent[T any](jobs int, cmp func(a, b T) (ll, rr, lr, rl int), i

l := len(items)

// define a min chunk size, don't split in too small chunks
const minChunkSize = 10_000

chunkSize := l/jobs + 1
if chunkSize < 10_000 {
chunkSize = 10_000
if chunkSize < minChunkSize {
chunkSize = minChunkSize

// don't use go routine and result channel for just one chunk
if l < chunkSize {
return NewTree[T](cmp, items...)
}
}

var wg sync.WaitGroup
Expand Down

0 comments on commit 562cdd3

Please sign in to comment.