ref: 10fcb3eade99dfc59043d3488375e863edb068ee
dir: /libstd/cmp.myr/
use "extremum.use" use "types.use" pkg std = type order = union `Before `Equal `After ;; generic numcmp : (a : @a, b : @a -> order) const strcmp : (a : byte[:], b : byte[:] -> order) const strncmp : (a : byte[:], b : byte[:], n : size -> order) ;; generic numcmp = {a, b if a < b -> `Before elif a == b -> `Equal else -> `After ;; } const strcmp = {a, b var l var i var v l = min(a.len, b.len) for i = 0; i < l; i++ v = a[i] - b[i] if v < 0 -> `Before elif v > 0 -> `After ;; ;; if a.len < b.len -> `Before elif a.len > b.len -> `After else -> `Equal ;; } const strncmp = {a, b, n a = a[:min(a.len, n)] b = b[:min(b.len, n)] -> strcmp(a, b) }