Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
gaissmai committed Feb 6, 2023
1 parent 562cdd3 commit befa5d8
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions treap.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,18 @@ func NewTree[T any](cmp func(a, b T) (ll, rr, lr, rl int), items ...T) Tree[T] {
// NewTreeConcurrent, convenience function for initializing the interval tree for large inputs (> 100_000).
// A good value reference for jobs is the number of logical CPUs usable by the current process.
func NewTreeConcurrent[T any](jobs int, cmp func(a, b T) (ll, rr, lr, rl int), items ...T) Tree[T] {
if jobs <= 1 {
return NewTree[T](cmp, items...)
}
// define a min chunk size, don't split in too small chunks
const minChunkSize = 25_000

// no fan-out for small input slice or just one job
l := len(items)

// define a min chunk size, don't split in too small chunks
const minChunkSize = 10_000
if l <= minChunkSize || jobs <= 1 {
return NewTree[T](cmp, items...)
}

chunkSize := l/jobs + 1
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 befa5d8

Please sign in to comment.