Unit testing framework and devicetree framework refactoring (#50)
[lunaix-os.git] / lunaix-os / includes / lunaix / ds / hstr.h
index 48640529680ce270fbb68c0c41580acc31337be9..77096aa8a845f6c35dbb0d0152bb94f61734dd1c 100644 (file)
@@ -1,25 +1,42 @@
 #ifndef __LUNAIX_HSTR_H
 #define __LUNAIX_HSTR_H
 
-#include <lib/hash.h>
+#include <klibc/hash.h>
+
+#define HSTR_FULL_HASH 32
 
 struct hstr
 {
     unsigned int hash;
     unsigned int len;
-    char* value;
+    const char* value;
 };
 
 #define HSTR(str, length)                                                      \
     (struct hstr)                                                              \
     {                                                                          \
-        .len = length, .value = str                                            \
+        .len = (length), .value = (str)                                        \
+    }
+
+#define HHSTR(str, length, strhash)                                            \
+    (struct hstr)                                                              \
+    {                                                                          \
+        .len = (length), .value = (str), .hash = (strhash)                     \
     }
 
-inline void
-hstr_rehash(struct hstr* hash_str, unsigned int truncate_to)
+#define HSTR_EQ(str1, str2) ((str1)->hash == (str2)->hash)
+
+#define HSTR_VAL(hstr)  ((hstr).value)
+#define HSTR_LEN(hstr)  ((hstr).len)
+#define HSTR_HASH(hstr) ((hstr).hash)
+
+static inline void
+hstr_rehash(struct hstr* hash_str, u32_t truncate_to)
 {
     hash_str->hash = strhash_32(hash_str->value, truncate_to);
 }
 
+void
+hstrcpy(struct hstr* dest, struct hstr* src);
+
 #endif /* __LUNAIX_HSTR_H */