diff options
Diffstat (limited to 'bittorrent/mbtstr/src/cmp.c')
| -rw-r--r-- | bittorrent/mbtstr/src/cmp.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/bittorrent/mbtstr/src/cmp.c b/bittorrent/mbtstr/src/cmp.c new file mode 100644 index 0000000..58c12d8 --- /dev/null +++ b/bittorrent/mbtstr/src/cmp.c @@ -0,0 +1,18 @@ +#include <complex.h> +#include <stdbool.h> +#include <string.h> + +#include "mbtstr/view.h" + +int mbt_cview_cmp(struct mbt_cview lhs, struct mbt_cview rhs) +{ + size_t min = lhs.size > rhs.size ? rhs.size : lhs.size; + for (size_t i = 0; i < min; i++) + { + if (lhs.data[i] != rhs.data[i]) + return lhs.data[i] - rhs.data[i]; + } + if (rhs.size == lhs.size) + return 0; + return lhs.size - rhs.size; +} |
