~sircmpwn/harec unlisted

c20949d002c58a4b98e8f8120f087f2df7675fd5 — Eyal Sawady a month ago 2a741ed
Add fnv1a_{u64,size} and use when appropriate

Signed-off-by: Eyal Sawady <ecs@d2evs.net>
4 files changed, 32 insertions(+), 6 deletions(-)

M include/types.h
M include/util.h
M src/types.c
M src/util.c
M include/types.h => include/types.h +2 -2
@@ 60,8 60,8 @@ struct type_enum_value {
	char *name;
	struct type_enum_value *next;
	union {
		intmax_t ival;
		uintmax_t uval;
		int64_t ival;
		uint64_t uval;
	};
};


M include/util.h => include/util.h +3 -1
@@ 6,7 6,9 @@
#define FNV1A_INIT 2166136261u

uint32_t fnv1a(uint32_t hash, unsigned char c);
uint32_t fnv1a_u32(uint32_t hash, uint32_t c);
uint32_t fnv1a_u32(uint32_t hash, uint32_t u32);
uint32_t fnv1a_u64(uint32_t hash, uint64_t u64);
uint32_t fnv1a_size(uint32_t hash, size_t sz);
uint32_t fnv1a_s(uint32_t hash, const char *str);
void *xcalloc(size_t n, size_t s);
void *xrealloc(void *p, size_t s);

M src/types.c => src/types.c +3 -3
@@ 385,7 385,7 @@ type_hash(const struct type *type)
		break;
	case STORAGE_ARRAY:
		hash = fnv1a_u32(hash, type_hash(type->array.members));
		hash = fnv1a_u32(hash, type->array.length);
		hash = fnv1a_size(hash, type->array.length);
		break;
	case STORAGE_FUNCTION:
		hash = fnv1a_u32(hash, type_hash(type->func.result));


@@ 401,7 401,7 @@ type_hash(const struct type *type)
		for (struct type_enum_value *value = type->_enum.values; value;
				value = value->next) {
			hash = fnv1a_s(hash, value->name);
			hash = fnv1a(hash, value->uval);
			hash = fnv1a_u64(hash, value->uval);
		}
		break;
	case STORAGE_POINTER:


@@ 417,7 417,7 @@ type_hash(const struct type *type)
				field; field = field->next) {
			hash = fnv1a_s(hash, field->name);
			hash = fnv1a_u32(hash, type_hash(field->type));
			hash = fnv1a_u32(hash, field->offset);
			hash = fnv1a_size(hash, field->offset);
		}
		break;
	case STORAGE_TAGGED:

M src/util.c => src/util.c +24 -0
@@ 24,6 24,30 @@ fnv1a_u32(uint32_t hash, uint32_t u32)
}

uint32_t
fnv1a_u64(uint32_t hash, uint64_t u64)
{
	hash = fnv1a(hash, (u64) & 0xFF);
	hash = fnv1a(hash, (u64 >> 8) & 0xFF);
	hash = fnv1a(hash, (u64 >> 16) & 0xFF);
	hash = fnv1a(hash, (u64 >> 24) & 0xFF);
	hash = fnv1a(hash, (u64 >> 32) & 0xFF);
	hash = fnv1a(hash, (u64 >> 40) & 0xFF);
	hash = fnv1a(hash, (u64 >> 48) & 0xFF);
	hash = fnv1a(hash, (u64 >> 54) & 0xFF);
	return hash;
}

uint32_t
fnv1a_size(uint32_t hash, size_t sz)
{
	for (size_t i = 0; i < sizeof(sz); i++) {
		hash = fnv1a(hash, sz & 0xFF);
		sz >>= 8;
	}
	return hash;
}

uint32_t
fnv1a_s(uint32_t hash, const char *str)
{
	unsigned char c;