From f61694fb3b600fd7ab119519c27b32946cb88c3e Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Fri, 5 Mar 2021 09:32:17 +0800 Subject: [PATCH] re-calculate b_numbers --- src/collection/hashset.scad | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/collection/hashset.scad b/src/collection/hashset.scad index 47c08575..f3d46021 100644 --- a/src/collection/hashset.scad +++ b/src/collection/hashset.scad @@ -4,10 +4,11 @@ use <_impl/_hashset_add_impl.scad>; function hashset(lt, eq = function(e1, e2) e1 == e2, hash = function(e) _str_hash(e), bucket_numbers) = let( + leng_lt = len(lt), lt_undef = is_undef(lt), bucket_numbers_undef = is_undef(bucket_numbers), b_numbers = bucket_numbers_undef ? - (lt_undef ? 16 : len(lt)) : bucket_numbers, + (lt_undef ? 16 : ceil(sqrt(leng_lt))) : bucket_numbers, buckets = [for(i = [0:b_numbers - 1]) []] ) - lt_undef ? buckets : _hashset(lt, len(lt), buckets, eq, hash); \ No newline at end of file + lt_undef ? buckets : _hashset(lt, leng_lt, buckets, eq, hash); \ No newline at end of file