diff options
author | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-19 10:42:21 +0000 |
---|---|---|
committer | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-19 10:42:21 +0000 |
commit | fbcb1cad3eca5ca670f623bdb25a78b8fe54af1b (patch) | |
tree | c99123e5ebf3ac3b964cc697f028d075bfd371a0 /array.c | |
parent | 5e5915618dbd52eb08f81b8d370fda8cb699dcb7 (diff) |
Add dyadic ≡ match
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -209,4 +209,42 @@ simplifyarray(Array *a) return b; }else return fnSame(a); +} + +int +comparearray(Array *a, Array *b) +{ + /* returns -1 if a < b, 0 if a == b and 1 if a > b. + Only correctly handles test for equality right now, + and returns 1 for unequal data. */ + + if(a->type != b->type) + return 1; + if(a->rank != b->rank) + return 1; + if(a->size != b->size) + return 1; + for(int i = 0; i < a->rank; i++) + if(a->shape[i] != b->shape[i]) + return 1; + for(int i = 0; i < a->size; i++){ + if(a->type == AtypeArray){ + /* do something recursive here */ + int sub = comparearray(a->arraydata[i], b->arraydata[i]); + if(sub != 0) + return sub; + }else{ + int sub = memcmp( + a->rawdata + i * datasizes[a->type], + b->rawdata + i * datasizes[a->type], + datasizes[a->type]); + if(sub < 0) + return -1; + else if(sub > 0) + return 1; + } + } + + /* if we get here, the arrays are equal */ + return 0; }
\ No newline at end of file |