From f6877d151069c53ce4a97a7d057308bd7a53b2b1 Mon Sep 17 00:00:00 2001 From: Karl Gaissmaier Date: Mon, 6 Feb 2023 12:17:51 +0100 Subject: [PATCH] minor --- treap.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/treap.go b/treap.go index 6bf3836..33334f7 100644 --- a/treap.go +++ b/treap.go @@ -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