mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-02-19 10:09:39 +00:00
nonrecursive rewrite of unique_count()
This commit is contained in:
parent
8fc3af0264
commit
b2538b4b19
1 changed files with 5 additions and 11 deletions
16
arrays.scad
16
arrays.scad
|
@ -797,17 +797,11 @@ function unique(arr) =
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// arr = The list to analyze.
|
// arr = The list to analyze.
|
||||||
function unique_count(arr) =
|
function unique_count(arr) =
|
||||||
assert(is_list(arr)||is_string(list))
|
assert(is_list(arr) || is_string(arr))
|
||||||
len(arr)==0 ? [[],[]] :
|
let( arr=sort(arr) )
|
||||||
len(arr)==1 ? [arr,[1]] :
|
let(ind = [0,for(i=[1:1:len(arr)-1]) if (arr[i]!=arr[i-1]) i])
|
||||||
_unique_count(sort(arr), ulist=[], counts=[], ind=1, curtot=1);
|
[select(arr,ind),
|
||||||
|
deltas(concat(ind,[len(arr)]))];
|
||||||
function _unique_count(arr, ulist, counts, ind, curtot) =
|
|
||||||
ind == len(arr)+1 ? [ulist, counts] :
|
|
||||||
ind==len(arr) || arr[ind] != arr[ind-1] ? _unique_count(arr,concat(ulist,[arr[ind-1]]), concat(counts,[curtot]),ind+1,1) :
|
|
||||||
_unique_count(arr,ulist,counts,ind+1,curtot+1);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Section: List Iteration Helpers
|
// Section: List Iteration Helpers
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue