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 66b6bcc commit f6877d1
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 @@ -45,23 +45,18 @@ func New(cidrs ...netip.Prefix) Tree {
// Convenience function for initializing the cidrtree for large inputs (> 100_000).
// A good value reference for jobs is the number of logical CPUs [runtine.NumCPU] usable by the current process.
func NewConcurrent(jobs int, cidrs ...netip.Prefix) Tree {
if jobs <= 1 {
return New(cidrs...)
}
// 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(cidrs)

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

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 New(cidrs...)
}
}

var wg sync.WaitGroup
Expand Down

0 comments on commit f6877d1

Please sign in to comment.