diff --git a/Makefile b/Makefile index 6fe628fe4..b68bbed0d 100644 --- a/Makefile +++ b/Makefile @@ -213,6 +213,7 @@ J_C_OFILES=\ jets/c/met.o \ jets/c/mix.o \ jets/c/mug.o \ + jets/c/muk.o \ jets/c/peg.o \ jets/c/po.o \ jets/c/pow.o \ diff --git a/include/jets/q.h b/include/jets/q.h index 65c7d260f..58067710b 100644 --- a/include/jets/q.h +++ b/include/jets/q.h @@ -59,6 +59,7 @@ u3_noun u3qc_mas(u3_atom); u3_noun u3qc_met(u3_atom, u3_atom); u3_noun u3qc_mix(u3_atom, u3_atom); + u3_noun u3qc_muk(u3_atom, u3_atom, u3_atom); u3_noun u3qc_peg(u3_atom, u3_atom); u3_noun u3qc_pow(u3_atom, u3_atom); u3_noun u3qc_rap(u3_atom, u3_noun); diff --git a/include/jets/w.h b/include/jets/w.h index 7457ef84f..57a5af06a 100644 --- a/include/jets/w.h +++ b/include/jets/w.h @@ -59,6 +59,7 @@ u3_noun u3wc_met(u3_noun); u3_noun u3wc_mix(u3_noun); u3_noun u3wc_mug(u3_noun); + u3_noun u3wc_muk(u3_noun); u3_noun u3wc_peg(u3_noun); u3_noun u3wc_pow(u3_noun); u3_noun u3wc_rap(u3_noun); diff --git a/jets/c/muk.c b/jets/c/muk.c new file mode 100644 index 000000000..60e0a6b41 --- /dev/null +++ b/jets/c/muk.c @@ -0,0 +1,54 @@ +/* j/c/muk.c +** +*/ +#include "all.h" +#include + +/* functions +*/ + u3_noun + u3qc_muk(u3_atom seed, + u3_atom len, + u3_atom key) + { + c3_w seed_w; + c3_w len_w; + c3_y *key_y; + c3_w out_w; + + c3_assert(u3r_met(5, seed) <= 1); + c3_assert(u3r_met(0, len) <= 31); + c3_assert(u3r_met(3, key) <= len); + + seed_w = u3r_word(0, seed); + len_w = u3r_word(0, len); + if (len_w > 0) { /* can't u3a_calloc 0 bytes */ + key_y = u3a_calloc(sizeof(c3_y), len); + } else { + key_y = 0; + } + u3r_bytes(0, len, key_y, key); + + MurmurHash3_x86_32(key_y, len, seed_w, &out_w); + + u3a_free(key_y); + return u3i_words(1, &out_w); + } + + u3_noun + u3wc_muk(u3_noun cor) + { + u3_noun seed, len, key; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &seed, + u3x_sam_6, &len, + u3x_sam_7, &key, 0)) || + (c3n == u3ud(seed)) || + (c3n == u3ud(len)) || + (c3n == u3ud(key)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qc_muk(seed, len, key); + } + } diff --git a/jets/tree.c b/jets/tree.c index 2c23ccd8c..bffbf3883 100644 --- a/jets/tree.c +++ b/jets/tree.c @@ -54,6 +54,7 @@ static u3j_harm _mood__hoon_mas_a[] = {{".2", u3wc_mas, c3y}, {}}; static u3j_harm _mood__hoon_met_a[] = {{".2", u3wc_met, c3y}, {}}; static u3j_harm _mood__hoon_mix_a[] = {{".2", u3wc_mix, c3y}, {}}; static u3j_harm _mood__hoon_mug_a[] = {{".2", u3wc_mug, c3y}, {}}; +static u3j_harm _mood__hoon_muk_a[] = {{".2", u3wc_muk, c3y}, {}}; static u3j_harm _mood__hoon_peg_a[] = {{".2", u3wc_peg, c3y}, {}}; static u3j_harm _mood__hoon_pow_a[] = {{".2", u3wc_pow, c3y}, {}}; static u3j_harm _mood__hoon_rap_a[] = {{".2", u3wc_rap, c3y}, {}}; @@ -464,6 +465,7 @@ static u3j_core _mood__hoon_d[] = { "met", _mood__hoon_met_a }, { "mix", _mood__hoon_mix_a }, { "mug", _mood__hoon_mug_a }, + { "muk", _mood__hoon_muk_a }, { "peg", _mood__hoon_peg_a }, { "pow", _mood__hoon_pow_a }, { "rap", _mood__hoon_rap_a },