diff --git a/pkg/arvo/sys/hoon.hoon b/pkg/arvo/sys/hoon.hoon index b259b1ed0..b3a390d2a 100644 --- a/pkg/arvo/sys/hoon.hoon +++ b/pkg/arvo/sys/hoon.hoon @@ -1603,6 +1603,7 @@ d(l a(r l.d)) :: ++ rep :: reduce to product + ~/ %rep |* b/_=>(~ |=({* *} +<+)) |- ?~ a +<+.b @@ -1692,12 +1693,16 @@ a(n n.a(q (b p.n.a q.n.a)), l $(a l.a), r $(a r.a)) :: ++ wyt :: depth of map - |- ^- @ + =< $ + ~% %wyt + ~ + |. ^- @ ?~(a 0 +((add $(a l.a) $(a r.a)))) :: ++ key :: set of keys + =< $ + ~/ %key =+ b=`(set _?>(?=(^ a) p.n.a))`~ - |- ^+ b + |. ^+ b ?~ a b $(a r.a, b $(a l.a, b (~(put in b) p.n.a))) :: diff --git a/pkg/urbit/include/jets/w.h b/pkg/urbit/include/jets/w.h index c63026a19..5b202c8fd 100644 --- a/pkg/urbit/include/jets/w.h +++ b/pkg/urbit/include/jets/w.h @@ -86,10 +86,12 @@ u3_noun u3wdb_has(u3_noun); u3_noun u3wdb_int(u3_noun); u3_noun u3wdb_jab(u3_noun); + u3_noun u3wdb_key(u3_noun); u3_noun u3wdb_put(u3_noun); # define u3wdb_tap u3wdi_tap u3_noun u3wdb_uni(u3_noun); u3_noun u3wdb_run(u3_noun); +# define u3wdb_wyt u3wdi_wyt u3_noun u3wdi_bif(u3_noun); u3_noun u3wdi_del(u3_noun); diff --git a/pkg/urbit/jets/d/by_key.c b/pkg/urbit/jets/d/by_key.c new file mode 100644 index 000000000..62a8d510d --- /dev/null +++ b/pkg/urbit/jets/d/by_key.c @@ -0,0 +1,35 @@ +/* j/4/by_run.c +** +*/ +#include "all.h" + +/* internal functions + */ +static u3_noun +_by_key(u3_noun a, u3_noun set) +{ + if (u3_nul == a) { + return u3k(set); + } else { + u3_noun n_a, l_a, r_a; + u3_noun p_n_a, q_n_a; + u3x_trel(a, &n_a, &l_a, &r_a); + u3x_cell(n_a, &p_n_a, &q_n_a); + + u3_noun with_set = u3qdi_put(set, p_n_a); + u3_noun left_set = _by_key(l_a, with_set); + u3z(with_set); + u3_noun right_set = _by_key(r_a, left_set); + u3z(left_set); + + return right_set; + } +} + +u3_noun +u3wdb_key(u3_noun cor) +{ + u3_noun a; + u3x_mean(cor, u3x_con_sam, &a, 0); + return _by_key(a, 0); +} diff --git a/pkg/urbit/jets/tree.c b/pkg/urbit/jets/tree.c index 283fae819..4150cc1c2 100644 --- a/pkg/urbit/jets/tree.c +++ b/pkg/urbit/jets/tree.c @@ -1636,7 +1636,9 @@ static c3_c* _141_two__in_ha[] = { 0 }; - static u3j_harm _141_two__by_run_a[] = {{".2", u3wdb_run, c3y}, {}}; + static u3j_harm _141_two__by_key_a[] = {{".2", u3wdb_key}, {}}; + static u3j_harm _141_two__by_run_a[] = {{".2", u3wdb_run}, {}}; + static u3j_harm _141_two__by_wyt_a[] = {{".2", u3wdb_wyt}, {}}; static u3j_harm _141_two__by_tap_a[] = {{".2", u3wdb_tap, c3y}, {}}; static c3_c* _141_two__by_tap_ha[] = { @@ -1657,9 +1659,11 @@ static u3j_core _141_two__by_d[] = { "has", 7, _141_two__by_has_a, 0, _141_two__by_has_ha }, // { "int", 7, _141_two__by_int_a, 0, _141_two__by_int_ha }, { "jab", 7, _141_two__by_jab_a, 0, _141_two__by_jab_ha }, + { "key", 7, _141_two__by_key_a }, { "put", 7, _141_two__by_put_a, 0, _141_two__by_put_ha }, { "run", 7, _141_two__by_run_a }, { "tap", 7, _141_two__by_tap_a, 0, _141_two__by_tap_ha }, + { "wyt", 3, _141_two__by_wyt_a }, // { "uni", 7, _141_two__by_uni_a, 0, _141_two__by_uni_ha }, {} };