common.h (1077B)
1 #pragma once 2 3 typedef bool (*RTableEqFunc)(void *a, void *b, usize ksize); 4 typedef u64 (*RTableHashFunc)(void *k, u64 seed, usize ksize); 5 typedef void *(*RTableAlloczFunc)(usize size); 6 typedef void (*RTableFreeFunc)(void *p); 7 typedef struct r_table RTable; 8 9 struct r_table { 10 u8 b; /* Log2 of number of slots */ 11 u64 seed; 12 usize count; 13 usize ntombs; 14 void *mem; 15 void *data; /* Cache-aligned pointer into mem; see define.h for layout. */ 16 }; 17 18 static inline bool 19 r_table_mem_eq(void *a, void *b, usize ksize) { 20 return memcmp(a, b, ksize) == 0; 21 } 22 static inline u64 23 r_table_mem_hash(void *k, u64 seed, usize ksize) { 24 return r_hash(k, ksize, seed); 25 } 26 27 static inline bool 28 r_table_cstr_eq(char **a, char **b, usize ksize) { 29 return strcmp(*a, *b) == 0; 30 } 31 static inline u64 32 r_table_cstr_hash(char **k, u64 seed, usize ksize) { 33 return r_hash(*k, strlen(*k), seed); 34 } 35 36 static inline bool 37 r_table_rstr_eq(Str *a, Str *b, usize ksize) { 38 return str_eq(*a, *b); 39 } 40 static inline u64 41 r_table_rstr_hash(Str *k, u64 seed, usize ksize) { 42 return r_hash(str_bytes(*k), str_len(*k), seed); 43 }