aboutsummaryrefslogtreecommitdiff
path: root/src/basic_traits.c
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-06-08 21:11:11 +0800
committerMistivia <i@mistivia.com>2025-06-08 21:11:11 +0800
commit9b98985d16e92e728d28d6c8ce4294f8a7230d9d (patch)
treea706b6812711ba432e97ad326a8aa535dc9ee4c2 /src/basic_traits.c
parent445fe6e07e3b8f5343f4a728d7ad96fbbfd0345e (diff)
generic pq
Diffstat (limited to 'src/basic_traits.c')
-rw-r--r--src/basic_traits.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/basic_traits.c b/src/basic_traits.c
new file mode 100644
index 0000000..386c72f
--- /dev/null
+++ b/src/basic_traits.c
@@ -0,0 +1,42 @@
+#include "basic_traits.h"
+
+#include <string.h>
+
+#include "mmhash.h"
+
+#define BASIC_TRAITS_IMPL(T) \
+ bool T##_eq(T* lhs, T* rhs) { \
+ return *lhs == *rhs; \
+ } \
+ int T##_cmp(T* lhs, T* rhs) { \
+ if (*lhs == *rhs) return 0; \
+ if (*lhs < *rhs) return -1; \
+ return 1; \
+ } \
+ uint64_t T##_hash(T* x) { \
+ return mmhash(x, sizeof(T), 0); \
+ }
+
+BASIC_TRAITS_IMPL(Char);
+BASIC_TRAITS_IMPL(Bool);
+BASIC_TRAITS_IMPL(Int);
+BASIC_TRAITS_IMPL(Long);
+BASIC_TRAITS_IMPL(UInt);
+BASIC_TRAITS_IMPL(ULong);
+BASIC_TRAITS_IMPL(Double);
+BASIC_TRAITS_IMPL(Float);
+
+bool String_eq(String* lhs, String *rhs) {
+ return strcmp(*lhs, *rhs) == 0;
+}
+
+int String_cmp(String* lhs, String *rhs) {
+ return strcmp(*lhs, *rhs);
+}
+
+ULong String_hash(String *x) {
+ size_t len = strlen(*x);
+ return mmhash(*x, len, 0);
+}
+
+