Optimizations to compare_vals()

This commit is contained in:
Revar Desmera 2019-04-01 23:40:15 -07:00
parent d97fd84de5
commit 229b9e1e3c

View File

@ -245,32 +245,24 @@ function sum_of_sines(a, sines) =
function mean(v) = sum(v)/len(v); function mean(v) = sum(v)/len(v);
// Section: Comparisons and Logic
// Function: compare_vals() // Function: compare_vals()
// Usage: // Usage:
// compare_vals(a, b); // compare_vals(a, b);
// Description: // Description:
// Compares two values. If types don't match, then // Compares two values. Lists are compared recursively.
// undef < boolean < scalar < string < list
// Lists are compared recursively.
// Arguments: // Arguments:
// a = First value to compare. // a = First value to compare.
// b = Second value to compare. // b = Second value to compare.
function compare_vals(a, b, n=0) = function compare_vals(a, b, n=0) =
(a == undef && b == undef)? 0 : (a==b)? 0 :
(a == undef)? -1 : (a==undef)? -1 :
(b == undef)? 1 : (b==undef)? 1 :
(is_boolean(a) && is_boolean(b))? ((a?1:0)-(b?1:0)) : ((a==[] || a=="" || a[0]!=undef) && (b==[] || b=="" || b[0]!=undef))? (
is_boolean(a)? -1 : let (cmp = compare_vals(a[n], b[n]))
is_boolean(b)? 1 : (cmp==0)? compare_vals(a,b,n+1) :
(is_scalar(a) && is_scalar(b))? (a-b) : cmp
is_scalar(a)? -1 : ) : (a<b)? -1 :
is_scalar(b)? 1 : (a>b)? 1 : 0;
(is_str(a) && is_str(b))? ((a<b)? -1 : ((a>b)? 1 : 0)) :
is_str(a)? -1 :
is_str(b)? 1 :
compare_lists(a,b);
// Function: compare_lists() // Function: compare_lists()