uncomments/fixes/finishes u3r_mur* functions

This commit is contained in:
Joe Bryan 2018-12-31 16:26:53 -05:00
parent 86a38cbb92
commit f0fdfe118f
2 changed files with 158 additions and 45 deletions

View File

@ -431,3 +431,78 @@
*/
c3_y*
u3r_tape(u3_noun a);
// XX temporary
//
/* u3r_mur():
**
** Compute and/or recall the mug (31-bit hash) of (a).
*/
c3_w
u3r_mur(u3_noun a);
/* u3r_mur_string():
**
** Compute the mug of `a`, LSB first.
*/
c3_w
u3r_mur_string(const c3_c *a_c);
/* u3r_mur_words():
**
** Compute the mug of `buf`, `len`, LSW first.
*/
c3_w
u3r_mur_words(const c3_w *buf_w,
c3_w len_w);
/* u3r_mur_d():
**
** Compute the mug of `num`, LSW first.
*/
c3_w
u3r_mur_d(c3_d num_d);
/* u3r_mur_bytes():
**
** Compute the mug of `buf`, `len`, LSW first.
*/
c3_w
u3r_mur_bytes(const c3_y *buf_w,
c3_w len_w);
/* u3r_mur_cell():
**
** Compute the mug of `[a b]`.
*/
c3_w
u3r_mur_cell(u3_noun a,
u3_noun b);
/* u3r_mur_trel():
**
** Compute the mug of `[a b c]`.
*/
c3_w
u3r_mur_trel(u3_noun a,
u3_noun b,
u3_noun c);
/* u3r_mur_qual():
**
** Compute the mug of `[a b c d]`.
*/
c3_w
u3r_mur_qual(u3_noun a,
u3_noun b,
u3_noun c,
u3_noun d);
/* u3r_mur_both():
**
** Join two mugs.
*/
c3_w
u3r_mur_both(c3_w a_w,
c3_w b_w);

View File

@ -2,6 +2,7 @@
**
*/
#include "all.h"
#include <murmur3.h>
/* _frag_word(): fast fragment/branch prediction for top word.
*/
@ -1710,9 +1711,6 @@ u3r_tape(u3_noun a)
return a_y;
}
#if 0
/* Finalization mix for better avalanching.
*/
static c3_w
@ -1754,10 +1752,10 @@ _mur_words(c3_w syd_w, const c3_w* key_w, c3_w len_w)
return goc_w;
}
/* u3_mur_words(): 31-bit nonzero MurmurHash3 on raw words.
/* u3r_mur_words(): 31-bit nonzero MurmurHash3 on raw words.
*/
c3_w
u3_mur_words(const c3_w* key_w, c3_w len_w)
u3r_mur_words(const c3_w* key_w, c3_w len_w)
{
c3_w syd_w = 0xcafebabe;
@ -1770,57 +1768,99 @@ u3_mur_words(const c3_w* key_w, c3_w len_w)
}
}
/* u3_mur_both():
/* u3r_mur_bytes():
**
** Compute the mug of `buf`, `len`, LSW first.
** XX temporary, reconcile with u3r_mur_words
*/
c3_w
u3r_mur_bytes(const c3_y *buf_y,
c3_w len_w)
{
c3_w syd_w = 0xcafebabe;
while ( 1 ) {
c3_w haz_w, ham_w;
MurmurHash3_x86_32(buf_y, len_w, syd_w, &haz_w);
ham_w = (haz_w >> 31) ^ (haz_w & 0x7fffffff);
if ( 0 != ham_w ) return ham_w;
else syd_w++;
}
}
/* u3r_mur_d():
**
** Compute the mug of `num`, LSW first.
*/
c3_w
u3r_mur_d(c3_d num_d)
{
c3_w buf_w[2];
buf_w[0] = (c3_w)(num_d & 0xffffffffULL);
buf_w[1] = (c3_w)(num_d >> 32ULL);
return u3r_mur_words(buf_w, 2);
}
/* u3r_mur_both():
**
** Join two murs.
*/
c3_w
u3_mur_both(c3_w lef_w, c3_w rit_w)
u3r_mur_both(c3_w lef_w, c3_w rit_w)
{
c3_w ham_w = lef_w ^ (0x7fffffff ^ rit_w);
return u3_mur_words(&ham_w, (0 == ham_w) ? 0 : 1);
return u3r_mur_words(&ham_w, (0 == ham_w) ? 0 : 1);
}
/* u3_mur(): MurmurHash3 on a noun.
/* u3r_mur(): MurmurHash3 on a noun.
*/
c3_w
u3_mur(u3_noun veb)
u3r_mur(u3_noun veb)
{
if ( u3_fly_is_cat(veb) ) {
return u3_mur_words(&veb, (0 == veb) ? 0 : 1);
c3_assert(u3_none != veb);
if ( _(u3a_is_cat(veb)) ) {
return u3r_mur_words(&veb, (0 == veb) ? 0 : 1);
}
else {
c3_w mur_w;
if ( (mur_w=*u3_at_dog_mur(veb)) ) {
return mur_w;
}
// u3a_noun* veb_u = u3a_to_ptr(veb);
if ( u3dog_is_pom(veb) ) {
mur_w = u3_mur_both(u3_mur(u3h(veb)), u3_mur(u3t(veb)));
// if ( veb_u->mug_w ) {
// return veb_u->mug_w;
// }
if ( _(u3a_is_cell(veb)) ) {
mur_w = u3r_mur_both(u3r_mur(u3h(veb)), u3r_mur(u3t(veb)));
}
else {
c3_w len_w = u3_met(5, veb);
c3_w len_w = u3r_met(5, veb);
c3_w* buf_w = malloc(4 * len_w);
u3_words(0, len_w, buf_w, veb);
mur_w = u3_mur_words(buf_w, len_w);
u3r_words(0, len_w, buf_w, veb);
mur_w = u3r_mur_words(buf_w, len_w);
free(buf_w);
}
*u3_at_dog_mur(veb) = mur_w;
// veb_u->mug_w = mur_w;
return mur_w;
}
}
/* u3_mur_string():
/* u3r_mur_string():
**
** Compute the mur of `a`, LSB first.
*/
c3_w
u3_mur_string(const c3_c *a_c)
u3r_mur_string(const c3_c *a_c)
{
c3_w len_w = strlen(a_c);
c3_w wor_w = ((len_w + 3) >> 2);
@ -1835,48 +1875,46 @@ u3_mur_string(const c3_c *a_c)
buf_w[inx_w] |= (a_c[i_w] << (8 * byt_w));
}
return u3_mur_words(buf_w, wor_w);
return u3r_mur_words(buf_w, wor_w);
}
/* u3_mur_cell():
/* u3r_mur_cell():
**
** Compute the mur of the cell `[hed tel]`.
*/
c3_w
u3_mur_cell(u3_noun hed,
u3_noun tel)
u3r_mur_cell(u3_noun hed,
u3_noun tel)
{
c3_w lus_w = u3_mur(hed);
c3_w biq_w = u3_mur(tel);
c3_w lus_w = u3r_mur(hed);
c3_w biq_w = u3r_mur(tel);
return u3_mur_both(lus_w, biq_w);
return u3r_mur_both(lus_w, biq_w);
}
/* u3_mur_trel():
/* u3r_mur_trel():
**
** Compute the mur of `[a b c]`.
*/
c3_w
u3_mur_trel(u3_noun a,
u3_noun b,
u3_noun c)
u3r_mur_trel(u3_noun a,
u3_noun b,
u3_noun c)
{
return u3_mur_both(u3_mur(a), u3_mur_both(u3_mur(b), u3_mur(c)));
return u3r_mur_both(u3r_mur(a), u3r_mur_both(u3r_mur(b), u3r_mur(c)));
}
/* u3_mur_qual():
/* u3r_mur_qual():
**
** Compute the mur of `[a b c d]`.
*/
c3_w
u3_mur_qual(u3_noun a,
u3_noun b,
u3_noun c,
u3_noun d)
u3r_mur_qual(u3_noun a,
u3_noun b,
u3_noun c,
u3_noun d)
{
return u3_mur_both(u3_mur(a),
u3_mur_both(u3_mur(b),
u3_mur_both(u3_mur(c), u3_mur(d))));
return u3r_mur_both(u3r_mur(a),
u3r_mur_both(u3r_mur(b),
u3r_mur_both(u3r_mur(c), u3r_mur(d))));
}
#endif