proper hash values for derived functions
This commit is contained in:
parent
ab5b8f92b4
commit
92763fa8b2
@ -3,7 +3,8 @@
|
||||
#include "hash.h"
|
||||
#include "time.h"
|
||||
|
||||
NOINLINE u64 bqn_hashArr(B x, const u64 secret[4]) { // TODO manual separation of atom & arr probably won't be worth it when there are actually sane typed array hashing things
|
||||
NOINLINE u64 bqn_hashObj(B x, const u64 secret[4]) { // TODO manual separation of atom & arr probably won't be worth it when there are actually sane typed array hashing things
|
||||
if (isArr(x)) {
|
||||
usz xia = IA(x);
|
||||
if (xia==0) return ~secret[3]; // otherwise squeeze will care about fills
|
||||
x = any_squeeze(incG(x));
|
||||
@ -34,6 +35,46 @@ NOINLINE u64 bqn_hashArr(B x, const u64 secret[4]) { // TODO manual separation o
|
||||
if (isTemp) TFREE(data);
|
||||
dec(x);
|
||||
return r;
|
||||
}
|
||||
|
||||
u64 hashbuf[3];
|
||||
switch(TY(x)) {
|
||||
case t_funBl: case t_md1Bl: case t_md2Bl:
|
||||
case t_funBI: case t_md1BI: case t_md2BI:
|
||||
case t_ns: case t_nfn:
|
||||
return wyhash64(secret[0], x.u);
|
||||
|
||||
case t_md1D: {
|
||||
Md1D* xv = c(Md1D,x);
|
||||
hashbuf[0] = 0;
|
||||
hashbuf[1] = bqn_hash(xv->f, secret);
|
||||
hashbuf[2] = bqn_hash(tag(xv->m1, MD1_TAG), secret);
|
||||
break;
|
||||
}
|
||||
case t_md2D: {
|
||||
Md2D* xv = c(Md2D,x);
|
||||
hashbuf[0] = bqn_hash(xv->g, secret);
|
||||
hashbuf[1] = bqn_hash(xv->f, secret);
|
||||
hashbuf[2] = bqn_hash(tag(xv->m2, MD1_TAG), secret);
|
||||
break;
|
||||
}
|
||||
case t_fork: {
|
||||
Fork* xv = c(Fork,x);
|
||||
hashbuf[0] = bqn_hash(xv->f, secret);
|
||||
hashbuf[1] = bqn_hash(xv->g, secret);
|
||||
hashbuf[2] = bqn_hash(xv->h, secret);
|
||||
break;
|
||||
}
|
||||
case t_atop: {
|
||||
Atop* xv = c(Atop,x);
|
||||
hashbuf[0] = 0;
|
||||
hashbuf[1] = bqn_hash(xv->g, secret);
|
||||
hashbuf[2] = bqn_hash(xv->h, secret);
|
||||
break;
|
||||
}
|
||||
default: thrM("Cannot hash this object");
|
||||
}
|
||||
return wyhash(hashbuf, sizeof(hashbuf), TY(x), secret);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -11,9 +11,9 @@ static void bcl(B x, usz ia) { // clean up bitarr tail bits to zero
|
||||
}
|
||||
}
|
||||
|
||||
u64 bqn_hashArr(B x, const u64 secret[4]);
|
||||
u64 bqn_hashObj(B x, const u64 secret[4]);
|
||||
static u64 bqn_hash(B x, const u64 secret[4]) { // doesn't consume
|
||||
if (isArr(x)) return bqn_hashArr(x, secret);
|
||||
if (isVal(x)) return bqn_hashObj(x, secret);
|
||||
return wyhash64(secret[0], x.u);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user