~ft/snippets

d70003df03613f39bcb8db0c0ecca0fcb1d5b58f — Sigrid Solveig Haflínudóttir 14 hours ago 4fb339c master
calculate strlen in qpget if not set; add more asserts; set value type to void ptr for qpget
2 files changed, 8 insertions(+), 2 deletions(-)

M qp.c
M qp.h
M qp.c => qp.c +7 -1
@@ 56,12 56,16 @@ popcount(u16int b)
}

int
qpget(Trie *t, char *k, int len, char **pk, char **pv)
qpget(Trie *t, char *k, int len, char **pk, void **pv)
{
	Tbitmap b;

	assert(k != nil && pk != nil && pv != nil);

	if(len < 1)
		len = strlen(k);
	if(t == nil)
		return -1;
	for(; isbranch(t); t = twig(t, twigoff(t, b))){
		b = twigbit(t, k, len);
		if(!hastwig(t, b))


@@ 119,6 123,7 @@ qpset(Trie *t, char *k, int len, void *v)

	if(t == nil){
		t = malloc(sizeof(*t));
		assert(t != nil);
		t->leaf.k = k;
		t->leaf.v = v;
		return t;


@@ 156,6 161,7 @@ qpset(Trie *t, char *k, int len, void *v)
	t2 = *t;
	b2 = nibbit(k2, f);
	t->branch.twigs = malloc(sizeof(*t)*2);
	assert(t->branch.twigs != nil);
	t->branch.x = (uvlong)f<<62 | (uvlong)i<<16 | b1 | b2;
	*twig(t, twigoff(t, b1)) = t1;
	*twig(t, twigoff(t, b2)) = t2;

M qp.h => qp.h +1 -1
@@ 1,6 1,6 @@
typedef union Trie Trie;
#pragma incomplete Trie

int qpget(Trie *t, char *k, int len, char **pk, char **pv);
int qpget(Trie *t, char *k, int len, char **pk, void **pv);
int qpnext(Trie *t, char **pk, int *plen, void **pv);
Trie *qpset(Trie *t, char *k, int len, void *v);