diff options
Diffstat (limited to 'cstring/src/cstring.c')
-rw-r--r-- | cstring/src/cstring.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/cstring/src/cstring.c b/cstring/src/cstring.c index 832cb85..100c130 100644 --- a/cstring/src/cstring.c +++ b/cstring/src/cstring.c | |||
@@ -23,7 +23,7 @@ string string_new(const char* cstr) { | |||
23 | void string_del(string* str) { | 23 | void string_del(string* str) { |
24 | if (str->data) { | 24 | if (str->data) { |
25 | free((void*)str->data); | 25 | free((void*)str->data); |
26 | str->data = 0; | 26 | str->data = nullptr; |
27 | str->length = 0; | 27 | str->length = 0; |
28 | } | 28 | } |
29 | } | 29 | } |
@@ -101,3 +101,11 @@ string string_format_size(size_t size) { | |||
101 | .length = length, | 101 | .length = length, |
102 | }; | 102 | }; |
103 | } | 103 | } |
104 | |||
105 | uint64_t cstring_hash(const char* str) { | ||
106 | uint64_t hash = 0; | ||
107 | for (size_t i = 0; i < strlen(str); ++i) { | ||
108 | hash = (uint64_t)str[i] + (hash << 6) + (hash << 16) - hash; | ||
109 | } | ||
110 | return hash; | ||
111 | } | ||