Add MurmurHash3.

This commit is contained in:
C. Guy Yarvin 2014-08-26 12:11:59 -07:00
parent f23100ccc6
commit e75d2e70b2
6 changed files with 105 additions and 1 deletions

View File

@ -144,6 +144,7 @@ J164_3_OFILES=\
gen164/3/met.o \
gen164/3/mix.o \
gen164/3/mug.o \
gen164/3/mur.o \
gen164/3/peg.o \
gen164/3/po.o \
gen164/3/rap.o \
@ -314,7 +315,7 @@ vere: $(BIN)/vere
all: vere
$(LIBUV_MAKEFILE):
cd outside/libuv_0.11 ; sh autogen.sh ; ./configure
cd outside/libuv_0.11 ; sh autogen.sh ; ./configure --disable-dtrace
$(LIBUV): $(LIBUV_MAKEFILE)
$(MAKE) -C outside/libuv_0.11 all-am

View File

@ -1178,6 +1178,47 @@ u2_frag(u2_atom a,
}
}
/* Finalization mix for better avalanching.
*/
static c3_w
_mur_fmix(c3_w h_w)
{
h_w ^= h_w >> 16;
h_w *= 0x85ebca6b;
h_w ^= h_w >> 13;
h_w *= 0xc2b2ae35;
h_w ^= h_w >> 16;
return h_w;
}
/* u2_mur_words(): MurmurHash3 on raw words.
*/
c3_w
u2_mur_words(c3_w* key_w, c3_w len_w, c3_w syd_w)
{
c3_w goc_w = syd_w;
c3_w lig_w = 0xcc9e2d51;
c3_w duf_w = 0x1b873593;
c3_w i_w;
for ( i_w = 0; i_w < len_w; i_w++ ) {
c3_w kop_w = key_w[i_w];
kop_w *= lig_w;
kop_w = c3_rotw(15, kop_w);
kop_w *= duf_w;
goc_w ^= kop_w;
goc_w = c3_rotw(13, goc_w);
goc_w = (goc_w * 5) + 0xe6546b64;
}
goc_w ^= len_w;
goc_w = _mur_fmix(goc_w);
return goc_w;
}
/* u2_mug():
**
** Compute and/or recall the mug (31-bit FNV1a hash) of (a).

51
gen164/3/mur.c Normal file
View File

@ -0,0 +1,51 @@
/* j/3/mur.c
**
** This file is in the public domain.
*/
#include "all.h"
#include "../pit.h"
/* functions
*/
u2_weak // transfer
j2_mbc(Pt3, mur)(u2_wire wir_r,
u2_atom key, // retain
u2_atom syd) // retain
{
c3_w len_w = u2_cr_met(5, key);
c3_w syd_w = u2_cr_word(0, syd);
{
c3_w* key_w = alloca(4 * len_w);
c3_w goc_w;
u2_cr_words(0, len_w, key_w, key);
goc_w = u2_mur_words(key_w, len_w, syd_w);
fprintf(stderr, "goc_w %x\r\n", goc_w);
return u2_ci_words(1, &goc_w);
}
}
u2_weak // transfer
j2_mb(Pt3, mur)(u2_wire wir_r,
u2_noun cor) // retain
{
u2_noun a, b;
if ( (u2_no == u2_mean(cor, u2_cv_sam_2, &a, u2_cv_sam_3, &b, 0)) ||
(u2_no == u2_stud(a)) ||
(u2_no == u2_stud(b)) )
{
return u2_bl_bail(wir_r, c3__exit);
} else {
return j2_mbc(Pt3, mur)(wir_r, a, b);
}
}
/* structures
*/
u2_ho_jet
j2_mbj(Pt3, mur)[] = {
{ ".2", c3__lite, j2_mb(Pt3, mur),
u2_jet_test | u2_jet_live, u2_none, u2_none },
{ }
};

View File

@ -63,6 +63,7 @@
extern u2_ho_jet j2_mbj(Pt3, met)[];
extern u2_ho_jet j2_mbj(Pt3, mix)[];
extern u2_ho_jet j2_mbj(Pt3, mug)[];
extern u2_ho_jet j2_mbj(Pt3, mur)[];
extern u2_ho_jet j2_mbj(Pt3, peg)[];
extern u2_ho_jet j2_mbj(Pt3, rap)[];
extern u2_ho_jet j2_mbj(Pt3, rip)[];
@ -211,6 +212,7 @@
{ j2_sb(Pt3, met), j2_mbj(Pt3, met), 0, 0, u2_none },
{ j2_sb(Pt3, mix), j2_mbj(Pt3, mix), 0, 0, u2_none },
{ j2_sb(Pt3, mug), j2_mbj(Pt3, mug), 0, 0, u2_none },
{ j2_sb(Pt3, mur), j2_mbj(Pt3, mur), 0, 0, u2_none },
{ j2_sb(Pt3, peg), j2_mbj(Pt3, peg), 0, 0, u2_none },
{ j2_sb(Pt3, rap), j2_mbj(Pt3, rap), 0, 0, u2_none },
{ j2_sb(Pt3, rip), j2_mbj(Pt3, rip), 0, 0, u2_none },

View File

@ -60,6 +60,10 @@
# define c3_max(x, y) ( ((x) > (y)) ? (x) : (y) )
# define c3_min(x, y) ( ((x) < (y)) ? (x) : (y) )
/* Rotate.
*/
# define c3_rotw(r, x) ( ((x) << (r)) | ((x) >> (32 - (r))) )
/* Emergency stdio fix.
*/
int

View File

@ -555,6 +555,11 @@
c3_w
u2_mug(u2_noun a);
/* u2_mur_words(): MurmurHash3 on raw words.
*/
c3_w
u2_mur_words(c3_w* key_w, c3_w len_w, c3_w syd_w);
/* u2_mug_string():
**
** Compute the mug of `a`, LSB first.