#include "memory.h" #include "str.h" uint64_t fnv1a64(uint8_t* buf, size_t size) { size_t i; uint64_t hash = 0xcbf29ce484222325; for (i = 0; i < size; i++, buf++) { hash ^= *buf; hash *= 0x100000001b3; } return hash; } uint64_t fnv1a64_2(uint64_t hash, uint8_t* buf, size_t size) { size_t i; for (i = 0; i < size; i++, buf++) { hash ^= *buf; hash *= 0x100000001b3; } return hash; } uint32_t hash_string(const char* s) { uint32_t h = 2166136261u; for (; *s; s++) { h ^= *(uint8_t*)s; h *= 16777619; } return h; } int string_equal(const char* a, const char* b) { while (*a && *b) { if (*a != *b) { return 0; } a++; b++; } return 1; } int string_copy(char* dst, const char* src) { int i; for (i = 0; *src; src++, dst++, i++) *dst = *src; *dst = 0; return i; } int string_len(const char* s) { int l; for (l = 0; *s; s++, l++); return l; } char* dup_string(Arena* a, const char* s) { int size = string_len(s) + 1; char* d = arena_alloc_aligned(a, size, 1); string_copy(d, s); return d; } char* dup_stringh(struct Heap* h, const char* s) { int size = string_len(s) + 1; char* d = heap_alloc_aligned(h, size, 1); string_copy(d, s); return d; } const char* next_line(const char* line) { const char* c; for (c = line; *c != '\n'; c++) { if (!*c) return 0; } return c + 1; }