summaryrefslogtreecommitdiff
path: root/source/kit/array_ref.c
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2023-12-29 06:21:33 +0100
committerMitya Selivanov <automainint@guattari.tech>2023-12-29 06:21:33 +0100
commit2d6c8fec45b23a8a28668ecf3ef281139ab778a7 (patch)
tree75d2a8538992129a83c0c2b83688289443d697e5 /source/kit/array_ref.c
parent820b171245f2f14766f3accdb0246a4e2c0d596a (diff)
downloadsaw-2d6c8fec45b23a8a28668ecf3ef281139ab778a7.zip
refactor dependencies; include dependencies source code
Diffstat (limited to 'source/kit/array_ref.c')
-rw-r--r--source/kit/array_ref.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/source/kit/array_ref.c b/source/kit/array_ref.c
new file mode 100644
index 0000000..a9df2c4
--- /dev/null
+++ b/source/kit/array_ref.c
@@ -0,0 +1,41 @@
+#include "array_ref.h"
+
+#include <string.h>
+
+i8 kit_ar_equal_bytes(i64 left_element_size, i64 left_size,
+ void *left_data, i64 right_element_size,
+ i64 right_size, void *right_data) {
+ i64 i;
+ if (left_element_size != right_element_size)
+ return 0;
+ if (left_size != right_size)
+ return 0;
+ for (i = 0; i < left_size; i++)
+ if (memcmp((u8 *) left_data + i * left_element_size,
+ (u8 *) right_data + i * left_element_size,
+ left_element_size) != 0)
+ return 0;
+ return 1;
+}
+
+i8 kit_ar_compare(i64 left_element_size, i64 left_size,
+ void *left_data, i64 right_element_size,
+ i64 right_size, void *right_data,
+ kit_ar_compare_fn compare) {
+ i64 i;
+ if (left_element_size < right_element_size)
+ return -1;
+ if (left_element_size > right_element_size)
+ return 1;
+ for (i = 0; i < left_size && i < right_size; i++) {
+ i8 c = compare((u8 *) left_data + i * left_element_size,
+ (u8 *) right_data + i * left_element_size);
+ if (c != 0)
+ return c;
+ }
+ if (left_size < right_size)
+ return -1;
+ if (left_size > right_size)
+ return 1;
+ return 0;
+}