factor analysis code out of codegen
This commit is contained in:
@@ -45,3 +45,20 @@ void buf_appendf(Buf *buf, const char *format, ...) {
|
||||
va_end(ap2);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
// these functions are not static inline so they can be better used as template parameters
|
||||
bool buf_eql_buf(Buf *buf, Buf *other) {
|
||||
assert(buf->list.length);
|
||||
return buf_eql_mem(buf, buf_ptr(other), buf_len(other));
|
||||
}
|
||||
|
||||
uint32_t buf_hash(Buf *buf) {
|
||||
assert(buf->list.length);
|
||||
// FNV 32-bit hash
|
||||
uint32_t h = 2166136261;
|
||||
for (int i = 0; i < buf_len(buf); i += 1) {
|
||||
h = h ^ ((uint8_t)buf->list.at(i));
|
||||
h = h * 16777619;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user