mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-11 09:14:29 +02:00
refactor: sort and get elem
This commit is contained in:
@@ -31,4 +31,15 @@ _dedup_add_search = function(buckets, i_elem, eq, hash, bucket_numbers)
|
|||||||
|
|
||||||
function _add(buckets, bucket, i_elem, b_idx) =
|
function _add(buckets, bucket, i_elem, b_idx) =
|
||||||
let(leng = len(buckets))
|
let(leng = len(buckets))
|
||||||
[for(i = 0; i < leng; i = i + 1) i == b_idx ? [each bucket, i_elem] : buckets[i]];
|
[for(i = 0; i < leng; i = i + 1) i == b_idx ? [each bucket, i_elem] : buckets[i]];
|
||||||
|
|
||||||
|
function _sort(lt) =
|
||||||
|
let(leng = len(lt))
|
||||||
|
leng == 0 ? [] :
|
||||||
|
leng == 1 ? [lt[0][1]] :
|
||||||
|
let(
|
||||||
|
pivot = lt[0],
|
||||||
|
before = [for(j = 1; j < leng; j = j + 1) if(lt[j][0] < pivot[0]) lt[j]],
|
||||||
|
after = [for(j = 1; j < leng; j = j + 1) if(lt[j][0] >= pivot[0]) lt[j]]
|
||||||
|
)
|
||||||
|
[each _sort(before), pivot[1], each _sort(after)];
|
@@ -10,15 +10,13 @@
|
|||||||
|
|
||||||
use <../__comm__/_str_hash.scad>;
|
use <../__comm__/_str_hash.scad>;
|
||||||
use <_impl/_dedup_impl.scad>;
|
use <_impl/_dedup_impl.scad>;
|
||||||
use <sort.scad>;
|
|
||||||
|
|
||||||
function dedup(lt, eq = undef, hash = function(e) _str_hash(e), number_of_buckets) =
|
function dedup(lt, eq = undef, hash = function(e) _str_hash(e), number_of_buckets) =
|
||||||
let(leng_lt = len(lt))
|
let(leng_lt = len(lt))
|
||||||
leng_lt < 2 ? lt :
|
leng_lt < 2 ? lt :
|
||||||
let(
|
let(
|
||||||
b_numbers = is_undef(number_of_buckets) ? ceil(sqrt(leng_lt)) : number_of_buckets,
|
b_numbers = is_undef(number_of_buckets) ? ceil(sqrt(leng_lt)) : number_of_buckets,
|
||||||
buckets = [for(i = [0:b_numbers - 1]) []],
|
buckets = [for(i = [0:b_numbers - 1]) []],
|
||||||
deduped = _dedup(lt, leng_lt, buckets, eq, hash, b_numbers),
|
deduped = _dedup(lt, leng_lt, buckets, eq, hash, b_numbers)
|
||||||
sorted = sort([for(bucket = deduped) each bucket], by = function(e1, e2) e1[0] - e2[0])
|
|
||||||
)
|
)
|
||||||
[for(i_elem = sorted) i_elem[1]];
|
_sort([for(bucket = deduped) each bucket]);
|
||||||
|
Reference in New Issue
Block a user