aboutsummaryrefslogtreecommitdiffstats
path: root/src/common/hmap_s.c
blob: 7abe975ea05222c511124523632e4a40908b27b1 (plain) (blame)
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
#include "hmap_s.h"
#include "vec.h"
#include <stdint.h>

uint32_t
vec2i_hmap_hash(struct hmap_key key)
{
	const struct vec2i *v = key.p;

	return (uint32_t) v->x + (uint32_t) v->y * 1337;
}

bool
vec2i_hmap_keycmp(struct hmap_key k1, struct hmap_key k2)
{
	const struct vec2i *v1 = k1.p, *v2 = k2.p;

	return vec2i_eql(v1, v2);
}

uint32_t
vec3i_hmap_hash(struct hmap_key key)
{
	const struct vec3i *v = key.p;

	return (uint32_t) v->x + (uint32_t) v->y * 1337
		+ (uint32_t) v->z * 1337 * 1337;
}

bool
vec3i_hmap_keycmp(struct hmap_key k1, struct hmap_key k2)
{
	const struct vec3i *v1 = k1.p, *v2 = k2.p;

	return vec3i_eql(v1, v2);
}

uint32_t
ssizet_hmap_hash(struct hmap_key key)
{
	return (uint32_t) (key.s * 1737);
}

bool
ssizet_hmap_keycmp(struct hmap_key k1, struct hmap_key k2)
{
	return k1.ss == k2.ss;
}