summaryrefslogtreecommitdiff
path: root/src/runtime/c/gu/hash.c
blob: 1666263e64346ed7496cc82a36c5c30cce4cae89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <gu/hash.h>

GuHash
gu_hash_bytes(GuHash h, const uint8_t* buf, size_t len)
{
	for (size_t n = 0; n < len; n++) {
		h = gu_hash_byte(h, buf[n]);
	}
	return h;
}

static bool
gu_int_eq_fn(GuEquality* self, const void* p1, const void* p2)
{
	(void) self;
	const int* ip1 = p1;
	const int* ip2 = p2;
	return *ip1 == *ip2;
}

static GuHash
gu_int_hash_fn(GuHasher* self, const void* p)
{
	(void) self;
	return (GuHash) *(const int*) p;
}

GuHasher gu_int_hasher[1] = {
	{
		{ gu_int_eq_fn },
		gu_int_hash_fn
	}
};

static bool
gu_addr_eq_fn(GuEquality* self, const void* p1, const void* p2)
{
	(void) self;
	return (p1 == p2);
}

static GuHash
gu_addr_hash_fn(GuHasher* self, const void* p)
{
	(void) self;
	return (GuHash) (uintptr_t) p;
}

GuHasher gu_addr_hasher[1] = {
	{
		{ gu_addr_eq_fn },
		gu_addr_hash_fn
	}
};

static bool
gu_word_eq_fn(GuEquality* self, const void* p1, const void* p2)
{
	(void) self;
	const GuWord* wp1 = p1;
	const GuWord* wp2 = p2;
	return (*wp1 == *wp2);
}

static GuHash
gu_word_hash_fn(GuHasher* self, const void* p)
{
	(void) self;
	return (GuHash) (uintptr_t) p;
}

GuHasher gu_word_hasher[1] = {
	{
		{ gu_word_eq_fn },
		gu_word_hash_fn
	}
};