aboutsummaryrefslogtreecommitdiff
path: root/src/strview.c
blob: 70e78f01f6feb4e4252e92516586287bc567bda1 (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
#include <string.h>

#include "common.h"
#include "strview.h"
#include "types.h"

uint64_t
strview_hash(strview_t sv)
{
	uint64_t h = 0x100;
	for (size_t i = 0; likely(i < sv.len); i++) {
		h ^= sv.p[i];
		h *= 1111111111111111111u;
	}
	return h;
}

uchar *
svtocstr(uchar *dst, strview_t src)
{
	((uchar *)memcpy(dst, src.p, src.len))[src.len] = 0;
	return dst;
}