Skip to content

Commit f6877d1

Browse files
committed
minor
1 parent 66b6bcc commit f6877d1

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

treap.go

+6-11
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,18 @@ func New(cidrs ...netip.Prefix) Tree {
4545
// Convenience function for initializing the cidrtree for large inputs (> 100_000).
4646
// A good value reference for jobs is the number of logical CPUs [runtine.NumCPU] usable by the current process.
4747
func NewConcurrent(jobs int, cidrs ...netip.Prefix) Tree {
48-
if jobs <= 1 {
49-
return New(cidrs...)
50-
}
48+
// define a min chunk size, don't split in too small chunks
49+
const minChunkSize = 25_000
5150

51+
// no fan-out for small input slice or just one job
5252
l := len(cidrs)
53-
54-
// define a min chunk size, don't split in too small chunks
55-
const minChunkSize = 10_000
53+
if l < minChunkSize || jobs <= 1 {
54+
return New(cidrs...)
55+
}
5656

5757
chunkSize := l/jobs + 1
5858
if chunkSize < minChunkSize {
5959
chunkSize = minChunkSize
60-
61-
// don't use go routine and result channel for just one chunk
62-
if l < chunkSize {
63-
return New(cidrs...)
64-
}
6560
}
6661

6762
var wg sync.WaitGroup

0 commit comments

Comments
 (0)