diff --git a/docs/lib3x-dedup.md b/docs/lib3x-dedup.md index ecc6441d..abddf146 100644 --- a/docs/lib3x-dedup.md +++ b/docs/lib3x-dedup.md @@ -9,6 +9,7 @@ Eliminating duplicate copies of repeating vectors. - `lt` : A list of vectors. - `eq` : A equality function. If it's ignored, use `==` to compare elements. **Since: ** 3.0 - `hash` : A hash function. If it's ignored, convert each element to a string and hash it. **Since: ** 3.0 +- `number_of_buckets` : The function uses a hash table internally. Change the number of buckets if you're trying to do optimization. **Since: ** 3.0 ## Examples diff --git a/src/util/dedup.scad b/src/util/dedup.scad index 246fdbfb..717d18cd 100644 --- a/src/util/dedup.scad +++ b/src/util/dedup.scad @@ -12,13 +12,13 @@ use <../__comm__/_str_hash.scad>; use <_impl/_dedup_impl.scad>; use ; -function dedup(lt, eq = function(e1, e2) e1 == e2, hash = function(e) _str_hash(e)) = +function dedup(lt, eq = function(e1, e2) e1 == e2, hash = function(e) _str_hash(e), number_of_buckets) = let(leng_lt = len(lt)) leng_lt < 2 ? lt : let( - bucket_numbers = ceil(sqrt(leng_lt)), - buckets = [for(i = [0:bucket_numbers - 1]) []], - deduped = _dedup(lt, leng_lt, buckets, eq, hash, bucket_numbers), + b_numbers = is_undef(number_of_buckets) ? ceil(sqrt(leng_lt)) : number_of_buckets, + buckets = [for(i = [0:b_numbers - 1]) []], + deduped = _dedup(lt, leng_lt, buckets, eq, hash, b_numbers), i_elem_lt = [ for(bucket = deduped) for(i_elem = bucket)