mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-12 17:54:18 +02:00
add number_of_buckets
This commit is contained in:
@@ -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
|
||||
|
||||
|
@@ -12,13 +12,13 @@ use <../__comm__/_str_hash.scad>;
|
||||
use <_impl/_dedup_impl.scad>;
|
||||
use <sort.scad>;
|
||||
|
||||
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)
|
||||
|
Reference in New Issue
Block a user