up

A priority search queue and LRU cache.
Log | Files | Refs

commit 88f1ff2248bfbfa62ab4585ba7ae0bf14ca5a009
Author: Jared Tobin <jared@jtobin.io>
Date:   Fri, 17 Mar 2023 20:46:15 +0400

Initial commit.

Diffstat:
Ajets/lu_del.c | 39+++++++++++++++++++++++++++++++++++++++
Ajets/lu_ebb.c | 43+++++++++++++++++++++++++++++++++++++++++++
Ajets/lu_get.c | 46++++++++++++++++++++++++++++++++++++++++++++++
Ajets/lu_put.c | 38++++++++++++++++++++++++++++++++++++++
Ajets/up_bot.c | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_cut.c | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_del.c | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_dew.c | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_feud.c | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_funk.c | 38++++++++++++++++++++++++++++++++++++++
Ajets/up_fuse.c | 150+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_get.c | 86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_lex.c | 24++++++++++++++++++++++++
Ajets/up_peak.c | 37+++++++++++++++++++++++++++++++++++++
Ajets/up_put.c | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_qat_del.c | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_qat_dew.c | 105+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_qat_pour.c | 41+++++++++++++++++++++++++++++++++++++++++
Ajets/up_qat_put.c | 29+++++++++++++++++++++++++++++
Ajets/up_qat_raw.c | 101+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_qor_bot.c | 34++++++++++++++++++++++++++++++++++
Ajets/up_qor_del.c | 117+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_qor_dew.c | 159+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_qor_get.c | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_qor_has.c | 32++++++++++++++++++++++++++++++++
Ajets/up_qor_lbal.c | 205+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_qor_llos.c | 41+++++++++++++++++++++++++++++++++++++++++
Ajets/up_qor_llsin.c | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_qor_lrsin.c | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_qor_put.c | 133+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_qor_rbal.c | 205+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_qor_rlos.c | 41+++++++++++++++++++++++++++++++++++++++++
Ajets/up_qor_rlsin.c | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_qor_rrsin.c | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_qor_sec.c | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_qor_see.c | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_qor_sink.c | 36++++++++++++++++++++++++++++++++++++
Ajets/up_qor_size.c | 33+++++++++++++++++++++++++++++++++
Ajets/up_qor_top.c | 26++++++++++++++++++++++++++
Ajets/up_qor_toy.c | 44++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_rule.c | 33+++++++++++++++++++++++++++++++++
Ajets/up_see.c | 157+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_vip.c | 160+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajets/up_wane.c | 39+++++++++++++++++++++++++++++++++++++++
Ajets/up_zero.c | 29+++++++++++++++++++++++++++++
Aup.hoon | 856+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
46 files changed, 4146 insertions(+), 0 deletions(-)

diff --git a/jets/lu_del.c b/jets/lu_del.c @@ -0,0 +1,39 @@ +#include "all.h" + +u3_noun +u3qdl_del(u3_noun a, u3_noun k) +{ + u3_noun cap_a, siz_a, tic_a, pri_a; + u3x_qual(a, &cap_a, &siz_a, &tic_a, &pri_a); + + u3_noun ded = u3qdu_dew(pri_a, k); + + if (u3_nul == ded) { + return u3k(a); + } + else { + u3_noun pd, qd, rd; + u3x_trel(u3t(ded), &pd, &qd, &rd); + + u3_noun pro = u3nq(u3k(cap_a), u3qa_dec(siz_a), u3k(tic_a), u3k(rd)); + + u3z(ded); + + return pro; + } +} + +u3_noun +u3wdl_del(u3_noun cor) +{ + u3_noun a, k; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &k, 0)) || + (c3n == u3du(a)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdl_del(a, k); + } +} + diff --git a/jets/lu_ebb.c b/jets/lu_ebb.c @@ -0,0 +1,43 @@ +#include "all.h" + +u3_noun +u3qdl_ebb(u3_noun a) +{ + u3_noun cap_a, siz_a, tic_a, pri_a; + u3x_qual(a, &cap_a, &siz_a, &tic_a, &pri_a); + + if (c3y == u3qa_gte(tic_a, 0x7fffffff)) { + return u3nq(u3k(cap_a), 0, 0, u3_nul); + } + else if (c3y == u3qa_gth(siz_a, cap_a)) { + return u3nq(u3k(cap_a), u3qa_dec(siz_a), u3k(tic_a), u3qdu_cut(pri_a)); + } + else { + return u3k(a); + } +} + +u3_noun +u3kdl_ebb(u3_noun a) +{ + u3_noun pro = u3qdl_ebb(a); + + u3z(a); + return pro; +} + +u3_noun +u3wdl_ebb(u3_noun cor) +{ + u3_noun a; + + if ( (c3n == u3r_mean(cor, u3x_sam, &a, 0)) || + (c3n == u3du(a)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdl_ebb(a); + } +} + + diff --git a/jets/lu_get.c b/jets/lu_get.c @@ -0,0 +1,46 @@ +#include "all.h" + +u3_noun +u3qdl_get(u3_noun a, u3_noun k) +{ + u3_noun cap_a, siz_a, tic_a, pri_a; + u3x_qual(a, &cap_a, &siz_a, &tic_a, &pri_a); + + u3_noun val = u3qdu_see(pri_a, k, tic_a); + + u3_noun pv, qv; + u3x_cell(val, &pv, &qv); + + if (u3_nul == pv) { + u3z(val); + + return u3_nul; + } + else { + u3_noun ppv, qpv; + u3x_cell(u3t(pv), &ppv, &qpv); + + u3_noun pru = u3nq(u3k(cap_a), u3k(siz_a), u3qa_inc(tic_a), u3k(qv)); + u3_noun pre = u3kdl_ebb(pru); + u3_noun pro = u3nt(u3_nul, u3k(qpv), pre); + + u3z(val); + + return pro; + } +} + +u3_noun +u3wdl_get(u3_noun cor) +{ + u3_noun a, k; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &k, 0)) || + (c3n == u3du(a)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdl_get(a, k); + } +} + diff --git a/jets/lu_put.c b/jets/lu_put.c @@ -0,0 +1,38 @@ +#include "all.h" + +u3_noun +u3qdl_put(u3_noun a, u3_noun k, u3_noun v) +{ + u3_noun cap_a, siz_a, tic_a, pri_a; + u3x_qual(a, &cap_a, &siz_a, &tic_a, &pri_a); + + u3_noun vue = u3qdu_vip(pri_a, k, tic_a, v); + + u3_noun pv, qv; + u3x_cell(vue, &pv, &qv); + + u3_noun siz = (u3_nul == pv) ? u3qa_inc(siz_a) : u3k(siz_a); + + u3_noun pre = u3nq(u3k(cap_a), siz, u3qa_inc(tic_a), u3k(qv)); + u3_noun pro = u3kdl_ebb(pre); + + u3z(vue); + + return pro; +} + +u3_noun +u3wdl_put(u3_noun cor) +{ + u3_noun a, k, v; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, + &k, u3x_sam_7, &v, 0)) || + (c3n == u3du(a)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdl_put(a, k, v); + } +} + diff --git a/jets/up_bot.c b/jets/up_bot.c @@ -0,0 +1,49 @@ +#include "all.h" + +u3_noun +u3qdu_bot(u3_noun a) +{ + if (u3_nul == a) { + return u3_nul; + } + + u3_atom hoc = u3h(a); + + if (c3n == u3ud(hoc)) { + return u3m_bail(c3__exit); + } + else switch ( hoc ) { + default: + return u3m_bail(c3__exit); + + case c3__tip: { + u3_noun ka, pa, va; + u3x_trel(u3t(a), &ka, &pa, &va); + + return u3nc(u3_nul, + u3nq(u3k(ka), u3k(pa), u3k(u3h(va)), u3qdu_cut(a))); + } + + case c3__bin: { + u3_noun ka, pa, ta; + u3x_trel(u3t(a), &ka, &pa, &ta); + + return u3nc(u3_nul, + u3nq(u3k(ka), u3k(pa), u3k(u3h(u3h(ta))), u3qdu_cut(a))); + } + } +} + +u3_noun +u3wdu_bot(u3_noun cor) +{ + u3_noun a; + + if (c3n == u3r_mean(cor, u3x_sam, &a, 0)) { + return u3m_bail(c3__exit); + } else { + return u3qdu_bot(a); + } +} + + diff --git a/jets/up_cut.c b/jets/up_cut.c @@ -0,0 +1,73 @@ +#include "all.h" + +u3_noun +u3qdu_cut(u3_noun a) +{ + if (u3_nul == a) { + return u3_nul; + } + + u3_noun lal = u3h(a); + + if (c3n == u3ud(lal)) { + return u3m_bail(c3__exit); + } + else switch ( lal ) { + default: + return u3m_bail(c3__exit); + + case c3__tip: { + u3_noun ka, pa, va, vva, tva; + u3x_trel(u3t(a), &ka, &pa, &va); + u3x_cell(va, &vva, &tva); + + u3_noun hol = u3qdu_qor_bot(tva); + u3_noun pro = (u3_nul == hol) ? u3_nul : u3nc(c3__tip, u3k(u3t(hol))); + + u3z(hol); + return pro; + } + + case c3__bin: { + u3_noun ka, pa, va, ta, vva, tva; + u3_noun ma, la, ra; + + u3x_qual(u3t(a), &ka, &pa, &va, &ta); + u3x_cell(va, &vva, &tva); + u3x_trel(ta, &ma, &la, &ra); + + u3_noun hol = u3qdu_qor_bot(tva); + + if (u3_nul == hol) { + return u3qdu_fuse(ma, la, ra); + } + else { + u3_noun kh, ph, vh; + u3x_trel(u3t(hol), &kh, &ph, &vh); + + u3_noun pre = u3qdu_fuse(ma, la, ra); + u3_noun pro = u3qdu_qat_raw(pre, kh, ph, vh); + + u3z(hol); + u3z(pre); + + return pro; + } + } + } +} + +u3_noun +u3wdu_cut(u3_noun cor) +{ + u3_noun a; + + if ( (c3n == u3r_mean(cor, u3x_sam, &a, 0)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_cut(a); + } +} + + diff --git a/jets/up_del.c b/jets/up_del.c @@ -0,0 +1,64 @@ +#include "all.h" + +u3_noun +u3qdu_del(u3_noun a, u3_noun k) +{ + u3_noun ded = u3qdu_qat_dew(a, k); + + if (u3_nul == ded) { + return u3k(a); + } + else { + u3_noun pv, qv, rv, sv; + u3_noun vrv, trv; + + u3x_qual(u3t(ded), &pv, &qv, &rv, &sv); + u3x_cell(rv, &vrv, &trv); + + if (c3y == u3r_sing(k, pv)) { + + u3_noun low = u3qdu_qor_bot(trv); + + if (u3_nul == low) { + u3_noun pro = u3k(sv); + + u3z(ded); + return pro; + } + else { + u3_noun kl, pl, vl; + u3x_trel(u3t(low), &kl, &pl, &vl); + + u3_noun pro = u3qdu_qat_raw(sv, kl, pl, vl); + + u3z(ded); + u3z(low); + + return pro; + } + } + else { + u3_noun buc = u3nc(u3k(vrv), u3qdu_qor_del(trv, k)); + u3_noun pro = u3qdu_qat_raw(sv, pv, qv, buc); + + u3z(ded); + u3z(buc); + + return pro; + } + } +} + +u3_noun +u3wdu_del(u3_noun cor) +{ + u3_noun a, k; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &k, 0)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_del(a, k); + } +} + diff --git a/jets/up_dew.c b/jets/up_dew.c @@ -0,0 +1,78 @@ +#include "all.h" + +u3_noun +u3qdu_dew(u3_noun a, u3_noun k) +{ + u3_noun ded = u3qdu_qat_dew(a, k); + + if (u3_nul == ded) { + return u3_nul; + } + else { + u3_noun pv, qv, rv, sv; + u3_noun vrv, trv; + + u3x_qual(u3t(ded), &pv, &qv, &rv, &sv); + u3x_cell(rv, &vrv, &trv); + + if (c3y == u3r_sing(k, pv)) { + u3_noun low = u3qdu_qor_bot(trv); + + if (u3_nul == low) { + u3_noun pro = u3nq(u3_nul, u3k(qv), u3k(vrv), u3k(sv)); + + u3z(ded); + + return pro; + } + else { + u3_noun kl, pl, vl; + u3x_trel(u3t(low), &kl, &pl, &vl); + + u3_noun pro = u3nq(u3_nul, u3k(qv), u3k(vrv), + u3qdu_qat_raw(sv, kl, pl, vl)); + + u3z(ded); + u3z(low); + + return pro; + } + } + else { + u3_noun low = u3qdu_qor_dew(trv, k); + + if (u3_nul == low) { + u3z(ded); + + return u3_nul; + } + else { + u3_noun pl, ql, rl; + u3x_trel(u3t(low), &pl, &ql, &rl); + + u3_noun buc = u3nc(u3k(vrv), u3k(rl)); + u3_noun pro = u3nq(u3_nul, u3k(pl), u3k(ql), + u3qdu_qat_raw(sv, pv, qv, buc)); + + u3z(ded); + u3z(low); + u3z(buc); + + return pro; + } + } + } +} + +u3_noun +u3wdu_dew(u3_noun cor) +{ + u3_noun a, k; + + if (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &k, 0)) { + return u3m_bail(c3__exit); + } else { + return u3qdu_dew(a, k); + } +} + diff --git a/jets/up_feud.c b/jets/up_feud.c @@ -0,0 +1,51 @@ +#include "all.h" + +u3_noun +_mask(u3_atom a) +{ + u3_atom x = u3qa_dec(a); + u3_atom y = u3qc_mix(x, 0x7fffffff); + + u3_atom pro = u3qc_mix(y, a); + + u3z(x); + u3z(y); + + return pro; +} + +c3_o +u3qdu_feud(u3_atom m, u3_atom k, u3_atom l) +{ + u3_atom n = _mask(m); + u3_atom h = u3r_mug(k); + u3_atom i = u3r_mug(l); + u3_atom a = u3qc_dis(h, n); + u3_atom b = u3qc_dis(i, n); + + u3_atom pro = ( a == b ) ? c3n : c3y; + + u3z(n); + u3z(h); + u3z(i); + u3z(a); + u3z(b); + + return pro; +} + +u3_noun +u3wdu_feud(u3_noun cor) +{ + u3_noun m, k, l; + + if ( + (c3n == u3r_mean(cor, u3x_sam_2, &m, u3x_sam_6, &k, u3x_sam_7, &l, 0 )) || + (c3n == u3ud(m)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_feud(m, k, l); + } +} + diff --git a/jets/up_funk.c b/jets/up_funk.c @@ -0,0 +1,38 @@ +#include "all.h" + +u3_noun +u3qdu_funk(u3_noun k, u3_atom p, u3_noun v, u3_atom m, u3_noun l, u3_noun r) +{ + if ( u3_nul == l ) { + if ( u3_nul == r ) { + return u3nq(c3__tip, u3k(k), u3k(p), u3k(v)); + } + else { + return u3nq(c3__bin, u3k(k), u3k(p), + u3nq(u3k(v), u3k(m), u3_nul, u3k(r))); + } + } + else { + return u3nq(c3__bin, u3k(k), u3k(p), + u3nq(u3k(v), u3k(m), u3k(l), u3k(r))); + } +} + +u3_noun +u3wdu_funk(u3_noun cor) +{ + u3_noun k, p, v, m, l, r; + + if ( + (c3n == u3r_mean(cor, u3x_sam_2, &k, u3x_sam_6, &p, u3x_sam_14, &v, + u3x_sam_30, &m, u3x_sam_62, &l, u3x_sam_63, &r, 0 )) || + (c3n == u3ud(m)) || + (c3n == u3du(v)) || + (c3n == u3ud(p)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_funk(k, p, v, m, l, r); + } +} + diff --git a/jets/up_fuse.c b/jets/up_fuse.c @@ -0,0 +1,150 @@ +#include "all.h" + +u3_noun +u3qdu_fuse(u3_atom m, u3_noun l, u3_noun r) +{ + if ( u3_nul == l ) { + return u3k(r); + } + else { + u3_noun hol = u3h(l); + + if ( c3n == u3ud(hol) ) { + return u3m_bail(c3__exit); + } + else switch ( hol ) { + default: + return u3m_bail(c3__exit); + + case c3__tip: { + if ( u3_nul == r ) { + return u3k(l); + } + else { + u3_noun hor = u3h(r); + + if ( c3n == u3ud(hor) ) { + return u3m_bail(c3__exit); + } + else switch ( hor ) { + default: + return u3m_bail(c3__exit); + + case c3__tip: { + u3_noun p_l, k_l, v_l; + u3_noun p_r, k_r, v_r; + + u3x_trel(u3t(l), &k_l, &p_l, &v_l); + u3x_trel(u3t(r), &k_r, &p_r, &v_r); + + if ( c3y == u3qdu_lex(p_l, k_l, p_r, k_r) ) { + return u3nq(c3__bin, u3k(k_l), u3k(p_l), + u3nq(u3k(v_l), u3k(m), u3_nul, u3k(r))); + } + else { + return u3nq(c3__bin, u3k(k_r), u3k(p_r), + u3nq(u3k(v_r), u3k(m), u3k(l), u3_nul)); + } + } + + case c3__bin: { + u3_noun p_l, k_l, v_l; + u3_noun p_r, k_r, v_r, m_r, l_r, r_r; + u3_noun q_r; + + u3x_trel(u3t(l), &k_l, &p_l, &v_l); + u3x_qual(u3t(r), &k_r, &p_r, &v_r, &q_r); + u3x_trel(q_r, &m_r, &l_r, &r_r); + + if ( c3y == u3qdu_lex(p_l, k_l, p_r, k_r) ) { + return u3nq(c3__bin, u3k(k_l), u3k(p_l), + u3nq(u3k(v_l), u3k(m), u3_nul, u3k(r))); + } + else { + return u3nq(c3__bin, u3k(k_r), u3k(p_r), + u3nq(u3k(v_r), u3k(m), u3k(l), + u3qdu_fuse(m_r, l_r, r_r))); + } + } + } + } + } + + case c3__bin: { + if ( u3_nul == r ) { + return u3k(l); + } + else { + u3_noun hor = u3h(r); + + if ( c3n == u3ud(hor) ) { + return u3m_bail(c3__exit); + } + else switch ( hor ) { + default: + return u3m_bail(c3__exit); + + case c3__tip: { + u3_noun p_l, k_l, v_l, m_l, l_l, r_l; + u3_noun p_r, k_r, v_r; + u3_noun q_l; + + u3x_trel(u3t(r), &k_r, &p_r, &v_r); + u3x_qual(u3t(l), &k_l, &p_l, &v_l, &q_l); + u3x_trel(q_l, &m_l, &l_l, &r_l); + + if ( c3y == u3qdu_lex(p_l, k_l, p_r, k_r) ) { + return u3nq(c3__bin, u3k(k_l), u3k(p_l), + u3nq(u3k(v_l), u3k(m), + u3qdu_fuse(m_l, l_l, r_l), u3k(r))); + } + else { + return u3nq(c3__bin, u3k(k_r), u3k(p_r), + u3nq(u3k(v_r), u3k(m), u3k(l), u3_nul)); + } + } + + case c3__bin: { + u3_noun p_l, k_l, v_l, m_l, l_l, r_l; + u3_noun p_r, k_r, v_r, m_r, l_r, r_r; + u3_noun q_l; + u3_noun q_r; + + u3x_qual(u3t(l), &k_l, &p_l, &v_l, &q_l); + u3x_qual(u3t(r), &k_r, &p_r, &v_r, &q_r); + u3x_trel(q_l, &m_l, &l_l, &r_l); + u3x_trel(q_r, &m_r, &l_r, &r_r); + + if ( c3y == u3qdu_lex(p_l, k_l, p_r, k_r) ) { + return u3nq(c3__bin, u3k(k_l), u3k(p_l), + u3nq(u3k(v_l), u3k(m), + u3qdu_fuse(m_l, l_l, r_l), u3k(r))); + } + else { + return u3nq(c3__bin, u3k(k_r), u3k(p_r), + u3nq(u3k(v_r), u3k(m), u3k(l), + u3qdu_fuse(m_r, l_r, r_r))); + } + } + } + } + } + } + } +} + +u3_noun +u3wdu_fuse(u3_noun cor) +{ + u3_noun m, l, r; + + if ( + (c3n == u3r_mean(cor, u3x_sam_2, &m, u3x_sam_6, &l, u3x_sam_7, &r, 0 )) || + (c3n == u3ud(m)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_fuse(m, l, r); + } +} + diff --git a/jets/up_get.c b/jets/up_get.c @@ -0,0 +1,86 @@ +#include "all.h" + +u3_noun +u3qdu_get(u3_noun a, u3_noun k) +{ + if (u3_nul == a) { + return u3_nul; + } + + u3_atom hoc = u3h(a); + + if (c3n == u3ud(hoc)) { + return u3m_bail(c3__exit); + } + else switch ( hoc) { + default: + return u3m_bail(c3__exit); + + case c3__tip: { + u3_noun ka, pa, va; + u3x_trel(u3t(a), &ka, &pa, &va); + + u3_noun vva, tva; + u3x_cell(va, &vva, &tva); + + u3_atom mk = u3r_mug(k); + u3_atom mka = u3r_mug(ka); + + if (c3n == u3r_sing(mk, mka)) { + return u3_nul; + } + else if (c3y == u3r_sing(k, ka)) { + return u3nt(u3_nul, u3k(pa), u3k(vva)); + } + else { + return u3qdu_qor_get(tva, k); + } + } + + case c3__bin: { + u3_noun ka, pa, va, ta; + u3_noun vva, tva; + u3_noun ma, la, ra; + + u3x_qual(u3t(a), &ka, &pa, &va, &ta); + u3x_cell(va, &vva, &tva); + u3x_trel(ta, &ma, &la, &ra); + + u3_noun mk = u3r_mug(k); + u3_noun mka = u3r_mug(ka); + + if (c3y == u3qdu_feud(ma, k, ka)) { + return u3_nul; + } + else if (c3y == u3r_sing(mk, mka)) { + if (c3y == u3r_sing(k, ka)) { + return u3nt(u3_nul, u3k(pa), u3k(vva)); + } + else { + return u3qdu_qor_get(tva, k); + } + } + else if (c3y == u3qdu_zero(ma, k)) { + return u3qdu_get(la, k); + } + else { + return u3qdu_get(ra, k); + } + } + } +} + +u3_noun +u3wdu_get(u3_noun cor) +{ + u3_noun a, k; + + if (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &k, 0)) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_get(a, k); + } +} + + diff --git a/jets/up_lex.c b/jets/up_lex.c @@ -0,0 +1,24 @@ +#include "all.h" + +c3_o +u3qdu_lex(u3_atom p, u3_noun k, u3_atom q, u3_noun l) +{ + return ( c3y == u3r_sing(p, q) ) ? u3qc_gor(k, l) : u3qa_lth(p, q); +} + +u3_noun +u3wdu_lex(u3_noun cor) +{ + u3_noun p, k, q, l; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &p, u3x_sam_6, &k, u3x_sam_14, &q, + u3x_sam_15, &l, 0)) || + (c3n == u3ud(p)) || + (c3n == u3ud(q)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_lex(p, k, q, l); + } +} + diff --git a/jets/up_peak.c b/jets/up_peak.c @@ -0,0 +1,37 @@ +#include "all.h" + +u3_noun +u3qdu_peak(u3_noun k, u3_noun l) +{ + u3_atom h = u3r_mug(k); + u3_atom i = u3r_mug(l); + + c3_w a = h ^ i; + + // see + // + // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 + + a |= a >> 1; + a |= a >> 2; + a |= a >> 4; + a |= a >> 8; + a |= a >> 16; + a ^= a >> 1; + + return a; +} + +u3_noun +u3wdu_peak(u3_noun cor) +{ + u3_noun a, b; + + if (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_peak(a, b); + } +} + diff --git a/jets/up_put.c b/jets/up_put.c @@ -0,0 +1,83 @@ +#include "all.h" + +u3_noun +u3qdu_put(u3_noun a, u3_noun k, u3_atom p, u3_noun v) +{ + u3_noun ded = u3qdu_qat_dew(a, k); + + if (u3_nul == ded) { + u3_noun buc = u3nc(u3k(v), u3_nul); + u3_noun pro = u3qdu_qat_raw(a, k, p, buc); + + u3z(buc); + return pro; + } + else { + u3_noun pv, qv, rv, sv; + u3_noun vrv, trv; + + u3x_qual(u3t(ded), &pv, &qv, &rv, &sv); + u3x_cell(rv, &vrv, &trv); + + if (c3y == u3r_sing(k, pv)) { + u3_noun sun = u3qdu_qor_sink(trv, k, p, v); + + u3_noun ps, qs, rs; + u3x_trel(sun, &ps, &qs, &rs); + + u3_noun pro = u3qdu_qat_raw(sv, ps, qs, rs); + + u3z(ded); + u3z(sun); + + return pro; + } + else if ( (c3y == u3qa_lth(qv, p)) || + ( (c3y == u3r_sing(p, qv)) && (c3y == u3qc_gor(pv, k)) ) ) { + + u3_noun buc = u3nc(u3k(vrv), u3qdu_qor_put(trv, k, p, v)); + u3_noun pro = u3qdu_qat_raw(sv, pv, qv, buc); + + u3z(ded); + u3z(buc); + + return pro; + } + else if (c3y == u3qdu_qor_has(trv, k)) { + u3_noun dud = u3qdu_qor_del(trv, k); + u3_noun buc = u3nc(u3k(v), u3qdu_qor_put(dud, pv, qv, vrv)); + u3_noun pro = u3qdu_qat_raw(sv, k, p, buc); + + u3z(ded); + u3z(dud); + u3z(buc); + + return pro; + } + else { + u3_noun buc = u3nc(u3k(v), u3qdu_qor_put(trv, pv, qv, vrv)); + u3_noun pro = u3qdu_qat_raw(sv, k, p, buc); + + u3z(ded); + u3z(buc); + + return pro; + } + } +} + +u3_noun +u3wdu_put(u3_noun cor) +{ + u3_noun a, k, p, v; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &k, u3x_sam_14, &p, + u3x_sam_15, &v, 0)) || + (c3n == u3ud(p)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_put(a, k, p, v); + } +} + diff --git a/jets/up_qat_del.c b/jets/up_qat_del.c @@ -0,0 +1,68 @@ +#include "all.h" + +u3_noun +u3qdu_qat_del(u3_noun a, u3_noun k) +{ + if (u3_nul == a) { + return u3_nul; + } + + u3_noun hoc = u3h(a); + + if (c3n == u3ud(hoc)) { + return u3m_bail(c3__exit); + } + else switch ( hoc ) { + default: + return u3m_bail(c3__exit); + + case c3__tip: { + return ( c3y == u3r_sing(k, u3h(u3t(a))) ) ? u3_nul : u3k(a); + } + + case c3__bin: { + u3_noun ka, pa, va, ma; + u3_noun ta, la, ra; + u3x_qual(u3t(a), &ka, &pa, &va, &ta); + u3x_trel(ta, &ma, &la, &ra); + + if (c3y == u3qdu_feud(ma, k, ka)) { + return u3k(a); + } + else if (c3y == u3r_sing(k, ka)) { + return u3qdu_fuse(ma, la, ra); + } + else if (c3y == u3qdu_zero(ma, k)) { + u3_noun ul = u3qdu_qat_del(la, k); + u3_noun pro = u3qdu_funk(ka, pa, va, ma, ul, ra); + + u3z(ul); + + return pro; + } + else { + u3_noun ur = u3qdu_qat_del(ra, k); + u3_noun pro = u3qdu_wane(ka, pa, va, ma, la, ur); + + u3z(ur); + + return pro; + } + } + } +} + +u3_noun +u3wdu_qat_del(u3_noun cor) +{ + u3_noun a, k; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &k, 0)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_qat_del(a, k); + } +} + + diff --git a/jets/up_qat_dew.c b/jets/up_qat_dew.c @@ -0,0 +1,105 @@ +#include "all.h" + +static u3_noun +_omit(u3_noun b, u3_noun k) +{ + if (u3_nul == b) { + return u3nc(u3_nul, u3_nul); + } + + u3_noun hob = u3h(b); + + if (c3n == u3ud(hob)) { + return u3m_bail(c3__exit); + } + else switch ( hob ) { + default: + return u3m_bail(c3__exit); + + case c3__tip: { + u3_noun kb, pb, vb; + u3x_trel(u3t(b), &kb, &pb, &vb); + + u3_noun mk = u3r_mug(k); + u3_noun mkb = u3r_mug(kb); + + return (c3n == u3r_sing(mk, mkb)) + ? u3nc(u3_nul, u3k(b)) + : u3nc(u3nq(u3_nul, u3k(kb), u3k(pb), u3k(vb)), u3_nul); + } + + case c3__bin: { + u3_noun kb, pb, vb; + u3_noun tb, mb, lb, rb; + u3x_qual(u3t(b), &kb, &pb, &vb, &tb); + u3x_trel(tb, &mb, &lb, &rb); + + if (c3y == u3qdu_feud(mb, k, kb)) { + return u3nc(u3_nul, u3k(b)); + } + + u3_atom mk = u3r_mug(k); + u3_atom mkb = u3r_mug(kb); + + if (c3y == u3r_sing(mk, mkb)) { + return u3nc(u3nq(u3_nul, u3k(kb), u3k(pb), u3k(vb)), + u3qdu_fuse(mb, lb, rb)); + } + else if (c3y == u3qdu_zero(mb, k)) { + u3_noun med = _omit(lb, k); + u3_noun pro = u3nc(u3k(u3h(med)), + u3qdu_funk(kb, pb, vb, mb, u3t(med), rb)); + + u3z(med); + return pro; + } + else { + u3_noun med = _omit(rb, k); + u3_noun pro = u3nc(u3k(u3h(med)), + u3qdu_wane(kb, pb, vb, mb, lb, u3t(med))); + + u3z(med); + return pro; + } + } + } +} + +u3_noun +u3qdu_qat_dew(u3_noun a, u3_noun k) +{ + u3_noun med = _omit(a, k); + + u3_noun pm, qm; + u3x_cell(med, &pm, &qm); + + if (u3_nul == pm) { + u3z(med); + return u3_nul; + } + else { + u3_noun vel = u3t(pm); + + u3_noun pv, qv, rv; + u3x_trel(vel, &pv, &qv, &rv); + + u3_noun pro = u3nc(u3_nul, u3nq(u3k(pv), u3k(qv), u3k(rv), u3k(qm))); + + u3z(med); + return pro; + } +} + +u3_noun +u3wdu_qat_dew(u3_noun cor) +{ + u3_noun a, k; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &k, 0)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_qat_dew(a, k); + } +} + diff --git a/jets/up_qat_pour.c b/jets/up_qat_pour.c @@ -0,0 +1,41 @@ +#include "all.h" + +u3_noun +u3qdu_qat_pour(u3_noun a) +{ + u3_noun bot = u3qdu_qor_bot(a); + + if (u3_nul == bot) { + return u3_nul; + } + else { + u3_noun u = u3t(bot); + + u3_noun pu, qu; + u3x_cell(u, &pu, &qu); + + u3_atom k_pu, p_pu, v_pu; + u3x_trel(pu, &k_pu, &p_pu, &v_pu); + + u3_noun pro = u3nc(u3_nul, u3nq(u3k(p_pu), u3k(k_pu), u3k(v_pu), u3k(qu))); + + u3z(bot); + + return pro; + } +} + +u3_noun +u3wdu_qat_pour(u3_noun cor) +{ + u3_noun a; + + if (c3n == u3r_mean(cor, u3x_sam, &a, 0)) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_qat_pour(a); + } +} + + diff --git a/jets/up_qat_put.c b/jets/up_qat_put.c @@ -0,0 +1,29 @@ +#include "all.h" + +u3_noun +u3qdu_qat_put(u3_noun a, u3_noun k, u3_noun p, u3_noun v) +{ + u3_noun pre = u3qdu_qat_del(a, k); + u3_noun pro = u3qdu_qat_raw(pre, k, p, v); + + u3z(pre); + + return pro; +} + +u3_noun +u3wdu_qat_put(u3_noun cor) +{ + u3_noun a, k, p, v; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &k, u3x_sam_14, &p, + u3x_sam_15, &v, 0)) || + (c3n == u3ud(p)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_qat_put(a, k, p, v); + } +} + + diff --git a/jets/up_qat_raw.c b/jets/up_qat_raw.c @@ -0,0 +1,101 @@ +#include "all.h" + +u3_noun +u3qdu_qat_raw(u3_noun a, u3_noun k, u3_noun p, u3_noun v) +{ + if (u3_nul == a) { + return u3nq(c3__tip, u3k(k), u3k(p), u3k(v)); + } + + u3_noun hoc = u3h(a); + + if (c3n == u3ud(hoc)) { + return u3m_bail(c3__exit); + } + else switch ( hoc ) { + default: + return u3m_bail(c3__exit); + + case c3__tip: { + u3_noun ka, pa, va; + u3x_trel(u3t(a), &ka, &pa, &va); + + if (c3y == u3qdu_lex(p, k, pa, ka)) { + return u3qdu_rule(k, p, v, a, u3_nul); + } + else + { + u3_noun rec = u3nq(c3__tip, u3k(k), u3k(p), u3k(v)); + u3_noun pro = u3qdu_rule(ka, pa, va, rec, u3_nul); + + u3z(rec); + + return pro; + } + } + + case c3__bin: { + u3_noun ka, pa, va; + u3_noun ta, ma, la, ra; + u3x_qual(u3t(a), &ka, &pa, &va, &ta); + u3x_trel(ta, &ma, &la, &ra); + + if (c3y == u3qdu_feud(ma, k, ka)) { + if (c3y == u3qdu_lex(p, k, pa, ka)) { + return u3qdu_rule(k, p, v, a, u3_nul); + } + else { + u3_noun rec = u3nq(c3__tip, u3k(k), u3k(p), u3k(v)); + u3_noun rev = u3qdu_fuse(ma, la, ra); + u3_noun pro = u3qdu_rule(ka, pa, va, rec, rev); + + u3z(rec); + u3z(rev); + + return pro; + } + } + else if (c3y == u3qdu_lex(p, k, pa, ka)) { + if (c3y == u3qdu_zero(ma, ka)) { + u3_noun rev = u3qdu_qat_raw(la, ka, pa, va); + return u3nq(c3__bin, u3k(k), u3k(p), + u3nq(u3k(v), u3k(ma), rev, u3k(ra))); + } + else + { + u3_noun rev = u3qdu_qat_raw(ra, ka, pa, va); + return u3nq(c3__bin, u3k(k), u3k(p), + u3nq(u3k(v), u3k(ma), u3k(la), rev)); + } + } + else if (c3y == u3qdu_zero(ma, k)) { + u3_noun rev = u3qdu_qat_raw(la, k, p, v); + return u3nq(c3__bin, u3k(ka), u3k(pa), + u3nq(u3k(va), u3k(ma), rev, u3k(ra))); + } + else + { + u3_noun rev = u3qdu_qat_raw(ra, k, p, v); + return u3nq(c3__bin, u3k(ka), u3k(pa), + u3nq(u3k(va), u3k(ma), u3k(la), rev)); + } + } + } +} + +u3_noun +u3wdu_qat_raw(u3_noun cor) +{ + u3_noun a, k, p, v; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &k, u3x_sam_14, &p, + u3x_sam_15, &v, 0)) || + (c3n == u3ud(p)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_qat_raw(a, k, p, v); + } +} + + diff --git a/jets/up_qor_bot.c b/jets/up_qor_bot.c @@ -0,0 +1,34 @@ +#include "all.h" + +u3_noun +u3qdu_qor_bot(u3_noun a) +{ + if (u3_nul == a) { + return u3_nul; + } + else + { + u3_noun na, ta, ma; + u3x_trel(a, &na, &ta, &ma); + + u3_noun kna, pna, vna; + u3x_trel(na, &kna, &pna, &vna); + + return u3nc(u3_nul, + u3nq(u3k(kna), u3k(pna), u3k(vna), u3qdu_qor_sec(ta, ma))); + } +} + +u3_noun +u3wdu_qor_bot(u3_noun cor) +{ + u3_noun a; + + if (c3n == u3r_mean(cor, u3x_sam, &a, 0)) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_qor_bot(a); + } +} + diff --git a/jets/up_qor_del.c b/jets/up_qor_del.c @@ -0,0 +1,117 @@ +#include "all.h" + +u3_noun +u3qdu_qor_del(u3_noun a, u3_noun k) +{ + if (u3_nul == a) { + return u3_nul; + } + + u3_noun n_a, t_a, m_a; + u3x_trel(a, &n_a, &t_a, &m_a); + + if (u3_nul == t_a) { + u3_noun kn_a = u3h(n_a); + + if (c3y == u3r_sing(k, kn_a)) { + return u3_nul; + } + else { + return u3nt(u3k(n_a), u3_nul, u3k(kn_a)); + } + } + + u3_noun hot = u3h(t_a); + + if (c3n == u3ud(hot)) { + return u3m_bail(c3__exit); + } + else switch ( hot ) { + default: + return u3m_bail(c3__exit); + + case c3__rlos: { + u3_noun b = u3t(u3t(t_a)); + + u3_noun n_b, l_b, m_b, r_b; + u3x_qual(b, &n_b, &l_b, &m_b, &r_b); + + if ( (c3y == u3r_sing(k, m_b)) || (c3y == u3qc_gor(k, m_b)) ) { + u3_noun lel = u3nt(u3k(n_a), u3k(l_b), u3k(m_b)); + u3_noun rel = u3nt(u3k(n_b), u3k(r_b), u3k(m_a)); + + u3_noun lod = u3qdu_qor_del(lel, k); + u3_noun pro = u3qdu_qor_toy(lod, rel); + + u3z(lod); + u3z(lel); + u3z(rel); + + return pro; + } + else { + u3_noun lel = u3nt(u3k(n_a), u3k(l_b), u3k(m_b)); + u3_noun rel = u3nt(u3k(n_b), u3k(r_b), u3k(m_a)); + + u3_noun rod = u3qdu_qor_del(rel, k); + u3_noun pro = u3qdu_qor_toy(lel, rod); + + u3z(rod); + u3z(lel); + u3z(rel); + + return pro; + } + } + + case c3__llos: { + u3_noun b = u3t(u3t(t_a)); + + u3_noun n_b, l_b, m_b, r_b; + u3x_qual(b, &n_b, &l_b, &m_b, &r_b); + + if ( (c3y == u3r_sing(k, m_b)) || (c3y == u3qc_gor(k, m_b)) ) { + u3_noun lel = u3nt(u3k(n_b), u3k(l_b), u3k(m_b)); + u3_noun rel = u3nt(u3k(n_a), u3k(r_b), u3k(m_a)); + + u3_noun lod = u3qdu_qor_del(lel, k); + u3_noun pro = u3qdu_qor_toy(lod, rel); + + u3z(lod); + u3z(lel); + u3z(rel); + + return pro; + } + else { + u3_noun lel = u3nt(u3k(n_b), u3k(l_b), u3k(m_b)); + u3_noun rel = u3nt(u3k(n_a), u3k(r_b), u3k(m_a)); + + u3_noun rod = u3qdu_qor_del(rel, k); + u3_noun pro = u3qdu_qor_toy(lel, rod); + + u3z(rod); + u3z(lel); + u3z(rel); + + return pro; + } + } + } +} + +u3_noun +u3wdu_qor_del(u3_noun cor) +{ + u3_noun a, k; + + if (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &k, 0)) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_qor_del(a, k); + } +} + + + diff --git a/jets/up_qor_dew.c b/jets/up_qor_dew.c @@ -0,0 +1,159 @@ +#include "all.h" + +u3_noun +u3qdu_qor_dew(u3_noun a, u3_noun k) +{ + if (u3_nul == a) { + return u3_nul; + } + + u3_noun n_a, t_a, m_a; + u3x_trel(a, &n_a, &t_a, &m_a); + + if (u3_nul == t_a) { + u3_noun kn_a, pn_a, vn_a; + u3x_trel(n_a, &kn_a, &pn_a, &vn_a); + + if (c3n == u3r_sing(k, kn_a)) { + return u3_nul; + } + else { + return u3nq(u3_nul, u3k(pn_a), u3k(vn_a), u3_nul); + } + } + + u3_noun hot = u3h(t_a); + + if (c3n == u3ud(hot)) { + return u3m_bail(c3__exit); + } + else switch ( hot ) { + default: + return u3m_bail(c3__exit); + + case c3__llos: { + u3_noun b = u3t(u3t(t_a)); + + u3_noun n_b, l_b, m_b, r_b; + u3x_qual(b, &n_b, &l_b, &m_b, &r_b); + + u3_noun lel = u3nt(u3k(n_b), u3k(l_b), u3k(m_b)); + u3_noun rel = u3nt(u3k(n_a), u3k(r_b), u3k(m_a)); + + if ( (c3y == u3r_sing(k, m_b)) || (c3y == u3qc_gor(k, m_b)) ) { + u3_noun pat = u3qdu_qor_dew(lel, k); + + if (u3_nul == pat) { + u3z(lel); + u3z(rel); + + return u3_nul; + } + else { + u3_noun pp, qp, rp; + u3x_trel(u3t(pat), &pp, &qp, &rp); + + u3_noun pro = u3nq(u3_nul, u3k(pp), u3k(qp), u3qdu_qor_toy(rp, rel)); + + u3z(lel); + u3z(rel); + u3z(pat); + + return pro; + } + } + else { + u3_noun pat = u3qdu_qor_dew(rel, k); + + if (u3_nul == pat) { + u3z(lel); + u3z(rel); + + return u3_nul; + } + else { + u3_noun pp, qp, rp; + u3x_trel(u3t(pat), &pp, &qp, &rp); + + u3_noun pro = u3nq(u3_nul, u3k(pp), u3k(qp), u3qdu_qor_toy(lel, rp)); + + u3z(lel); + u3z(rel); + u3z(pat); + + return pro; + } + } + } + + case c3__rlos: { + u3_noun b = u3t(u3t(t_a)); + + u3_noun n_b, l_b, m_b, r_b; + u3x_qual(b, &n_b, &l_b, &m_b, &r_b); + + u3_noun lel = u3nt(u3k(n_a), u3k(l_b), u3k(m_b)); + u3_noun rel = u3nt(u3k(n_b), u3k(r_b), u3k(m_a)); + + if ( (c3y == u3r_sing(k, m_b)) || (c3y == u3qc_gor(k, m_b)) ) { + u3_noun pat = u3qdu_qor_dew(lel, k); + + if (u3_nul == pat) { + u3z(lel); + u3z(rel); + + return u3_nul; + } + else { + u3_noun pp, qp, rp; + u3x_trel(u3t(pat), &pp, &qp, &rp); + + u3_noun pro = u3nq(u3_nul, u3k(pp), u3k(qp), u3qdu_qor_toy(rp, rel)); + + u3z(lel); + u3z(rel); + u3z(pat); + + return pro; + } + } + else { + u3_noun pat = u3qdu_qor_dew(rel, k); + + if (u3_nul == pat) { + u3z(lel); + u3z(rel); + + return u3_nul; + } + else { + u3_noun pp, qp, rp; + u3x_trel(u3t(pat), &pp, &qp, &rp); + + u3_noun pro = u3nq(u3_nul, u3k(pp), u3k(qp), u3qdu_qor_toy(lel, rp)); + + u3z(lel); + u3z(rel); + u3z(pat); + + return pro; + } + } + } + + } +} + +u3_noun +u3wdu_qor_dew(u3_noun cor) +{ + u3_noun a, k; + + if (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &k, 0)) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_qor_dew(a, k); + } +} + diff --git a/jets/up_qor_get.c b/jets/up_qor_get.c @@ -0,0 +1,87 @@ +#include "all.h" + +u3_noun +u3qdu_qor_get(u3_noun a, u3_noun k) +{ + if (u3_nul == a) { + return u3_nul; + } + + u3_noun tor = u3qdu_qor_see(a); + + if (u3_nul == tor) { + return u3_nul; + } + + u3_noun hot = u3h(tor); + + if (c3n == u3ud(hot)) { + return u3m_bail(c3__exit); + } + else switch ( hot ) { + default: + return u3m_bail(c3__exit); + + case c3__sing: { + u3_noun n_tor = u3t(tor); + + u3_noun kn_tor, pn_tor, vn_tor; + u3x_trel(n_tor, &kn_tor, &pn_tor, &vn_tor); + + if (c3n == u3r_sing(k, kn_tor)) { + u3z(tor); + return u3_nul; + } + else { + u3_noun pro = u3nt(u3_nul, u3k(pn_tor), u3k(vn_tor)); + + u3z(tor); + + return pro; + } + } + + case c3__play: { + u3_noun l_tor, r_tor; + u3x_cell(u3t(tor), &l_tor, &r_tor); + + if (u3_nul == l_tor) { + return u3m_bail(c3__exit); + } + + u3_noun lop = u3t(u3t(l_tor)); + + if ( (c3y == u3r_sing(k, lop)) || (c3y == u3qc_gor(k, lop)) ) { + u3_noun pro = u3qdu_qor_get(l_tor, k); + + u3z(tor); + + return pro; + } + else { + u3_noun pro = u3qdu_qor_get(r_tor, k); + + u3z(tor); + + return pro; + } + + } + } +} + +u3_noun +u3wdu_qor_get(u3_noun cor) +{ + u3_noun a, k; + + if (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &k, 0)) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_qor_get(a, k); + } +} + + + diff --git a/jets/up_qor_has.c b/jets/up_qor_has.c @@ -0,0 +1,32 @@ +#include "all.h" + +c3_o +u3qdu_qor_has(u3_noun a, u3_noun k) +{ + u3_noun pre = u3qdu_qor_get(a, k); + + if (u3_nul == pre) { + return c3n; + } + else { + u3z(pre); + + return c3y; + } +} + +u3_noun +u3wdu_qor_has(u3_noun cor) +{ + u3_noun a, k; + + if (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &k, 0)) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_qor_has(a, k); + } +} + + + diff --git a/jets/up_qor_lbal.c b/jets/up_qor_lbal.c @@ -0,0 +1,205 @@ +#include "all.h" + +u3_noun +_lrdub(u3_noun n_a, u3_noun l_a, u3_noun m_a, u3_noun r_a) +{ + if ( c3n == u3du(l_a) ) { + return u3m_bail(c3__exit); + } + + u3_noun p_l_a = u3t(u3t(l_a)); + u3_noun hol = u3h(l_a); + + if ( c3n == u3ud(hol) ) { + return u3m_bail(c3__exit); + } + else switch ( hol ) { + default: + return u3m_bail(c3__exit); + + case c3__llos: { + u3_noun n_p_l_a, l_p_l_a, m_p_l_a, r_p_l_a; + u3x_qual(p_l_a, &n_p_l_a, &l_p_l_a, &m_p_l_a, &r_p_l_a); + + u3_noun pre = u3qdu_qor_llsin(n_p_l_a, l_p_l_a, m_p_l_a, r_p_l_a); + u3_noun pro = u3qdu_qor_lrsin(n_a, pre, m_a, r_a); + + u3z(pre); + + return pro; + } + + case c3__rlos: { + u3_noun n_p_l_a, l_p_l_a, m_p_l_a, r_p_l_a; + u3x_qual(p_l_a, &n_p_l_a, &l_p_l_a, &m_p_l_a, &r_p_l_a); + + u3_noun pre = u3qdu_qor_rlsin(n_p_l_a, l_p_l_a, m_p_l_a, r_p_l_a); + u3_noun pro = u3qdu_qor_lrsin(n_a, pre, m_a, r_a); + + u3z(pre); + + return pro; + } + } +} + +u3_noun +_lldub(u3_noun n_a, u3_noun l_a, u3_noun m_a, u3_noun r_a) +{ + if ( c3n == u3du(r_a) ) { + return u3m_bail(c3__exit); + } + + u3_noun p_r_a = u3t(u3t(r_a)); + u3_noun hor = u3h(r_a); + + if ( c3n == u3ud(hor) ) { + return u3m_bail(c3__exit); + } + else switch ( hor ) { + default: + return u3m_bail(c3__exit); + + case c3__llos: { + u3_noun n_p_r_a, l_p_r_a, m_p_r_a, r_p_r_a; + u3x_qual(p_r_a, &n_p_r_a, &l_p_r_a, &m_p_r_a, &r_p_r_a); + + u3_noun pre = u3qdu_qor_lrsin(n_p_r_a, l_p_r_a, m_p_r_a, r_p_r_a); + u3_noun pro = u3qdu_qor_llsin(n_a, l_a, m_a, pre); + + u3z(pre); + + return pro; + } + + case c3__rlos: { + u3_noun n_p_r_a, l_p_r_a, m_p_r_a, r_p_r_a; + u3x_qual(p_r_a, &n_p_r_a, &l_p_r_a, &m_p_r_a, &r_p_r_a); + + u3_noun pre = u3qdu_qor_rrsin(n_p_r_a, l_p_r_a, m_p_r_a, r_p_r_a); + u3_noun pro = u3qdu_qor_llsin(n_a, l_a, m_a, pre); + + u3z(pre); + + return pro; + } + } +} + +u3_noun +_lrbal(u3_noun n, u3_noun l, u3_noun m, u3_noun r) +{ + if ( c3n == u3du(l) ) { + return u3m_bail(c3__exit); + } + + u3_noun p_l = u3t(u3t(l)); + + u3_noun n_p_l, l_p_l, m_p_l, r_p_l; + u3x_qual(p_l, &n_p_l, &l_p_l, &m_p_l, &r_p_l); + + u3_atom sl = u3qdu_qor_size(l_p_l); + u3_atom sr = u3qdu_qor_size(r_p_l); + + c3_o comp = u3qa_gth(sl, sr); + + u3z(sl); + u3z(sr); + + return ( c3y == comp ) ? u3qdu_qor_lrsin(n, l, m, r) : _lrdub(n, l, m, r); +} + +u3_noun +_llbal(u3_noun n, u3_noun l, u3_noun m, u3_noun r) +{ + if ( c3n == u3du(r) ) { + return u3m_bail(c3__exit); + } + + u3_noun p_r = u3t(u3t(r)); + + u3_noun n_p_r, l_p_r, m_p_r, r_p_r; + u3x_qual(p_r, &n_p_r, &l_p_r, &m_p_r, &r_p_r); + + u3_atom sl = u3qdu_qor_size(l_p_r); + u3_atom sr = u3qdu_qor_size(r_p_r); + + c3_o comp = u3qa_lth(sl, sr); + + u3z(sl); + u3z(sr); + + return ( c3y == comp ) ? u3qdu_qor_llsin(n, l, m, r) : _lldub(n, l, m, r); +} + +u3_noun +u3qdu_qor_lbal(u3_noun n_a, u3_noun l_a, u3_noun m_a, u3_noun r_a) +{ + u3_atom sl = u3qdu_qor_size(l_a); + u3_atom sr = u3qdu_qor_size(r_a); + u3_atom s = u3qa_add(sl, sr); + + if ( c3y == u3qa_lth(s, 2) ) { + + u3z(sl); + u3z(sr); + u3z(s); + + return u3qdu_qor_llos(n_a, l_a, m_a, r_a); + } + else { + u3z(s); + + u3_atom sm_l = u3qa_mul(4, sl); + + if ( c3y == u3qa_gth(sr, sm_l) ) { + u3z(sl); + u3z(sr); + u3z(sm_l); + + return _llbal(n_a, l_a, m_a, r_a); + } + else { + u3z(sr); + u3z(sm_l); + + u3_atom sm_r = u3qa_mul(4, sr); + + if ( c3y == u3qa_gth(sl, sm_r) ) { + u3z(sl); + u3z(sm_r); + + return _lrbal(n_a, l_a, m_a, r_a); + } + else { + u3z(sl); + u3z(sm_r); + + return u3qdu_qor_llos(n_a, l_a, m_a, r_a); + } + } + } +} + +u3_noun +u3wdu_qor_lbal(u3_noun cor) +{ + u3_noun a; + + if ( (c3n == u3r_mean(cor, u3x_sam, &a, 0 )) || + (c3n == u3du(a)) ) + { + return u3m_bail(c3__exit); + } else { + u3_noun n, l, m, r; + u3x_qual(a, &n, &l, &m, &r); + + if ( (c3n == u3du(n)) || (c3n == u3ud(m)) ) { + return u3m_bail(c3__exit); + } + else { + return u3qdu_qor_lbal(n, l, m, r); + } + } +} + diff --git a/jets/up_qor_llos.c b/jets/up_qor_llos.c @@ -0,0 +1,41 @@ +#include "all.h" + +u3_noun +u3qdu_qor_llos(u3_noun n, u3_noun l, u3_atom m, u3_noun r) +{ + u3_atom sl = u3qdu_qor_size(l); + u3_atom sr = u3qdu_qor_size(r); + u3_atom s = u3qa_add(sl, sr); + + u3_noun pro = u3qa_inc(s); + + u3z(sl); + u3z(sr); + u3z(s); + + return u3nt(c3__llos, pro, u3nq(u3k(n), u3k(l), u3k(m), u3k(r))); +} + +u3_noun +u3wdu_qor_llos(u3_noun cor) +{ + u3_noun a; + + if ( (c3n == u3r_mean(cor, u3x_sam, &a, 0)) || + (c3n == u3du(a)) ) + { + return u3m_bail(c3__exit); + } else { + u3_noun n, l, m, r; + + u3x_qual(a, &n, &l, &m, &r); + + if ( (c3n == u3du(n)) || (c3n == u3ud(m)) ) { + return u3m_bail(c3__exit); + } + else { + return u3qdu_qor_llos(n, l, m, r); + } + } +} + diff --git a/jets/up_qor_llsin.c b/jets/up_qor_llsin.c @@ -0,0 +1,87 @@ +#include "all.h" + +u3_noun +u3qdu_qor_llsin(u3_noun n_a, u3_noun l_a, u3_noun m_a, u3_noun r_a) +{ + if ( c3n == u3du(r_a) ) { + return u3m_bail(c3__exit); + } + + u3_noun b = u3t(u3t(r_a)); + + u3_noun n_b, l_b, m_b, r_b; + u3_noun k_n_b, t_b; + u3x_qual(b, &n_b, &l_b, &m_b, &r_b); + u3x_cell(n_b, &k_n_b, &t_b); + + u3_noun p_n_b = u3h(t_b); + u3_noun hor = u3h(r_a); + + if ( c3n == u3ud(hor) ) { + return u3m_bail(c3__exit); + } + else switch ( hor ) { + default: + return u3m_bail(c3__exit); + + case c3__llos: { + u3_noun k_n_a, t_a; + u3x_cell(n_a, &k_n_a, &t_a); + + u3_noun p_n_a = u3h(t_a); + + if ( (c3n == u3ud(p_n_a)) || (c3n == u3ud(p_n_b)) ) { + return u3m_bail(c3__exit); + } + + if ( c3y == u3qdu_lex(p_n_a, k_n_a, p_n_b, k_n_b) ) { + u3_noun pre = u3qdu_qor_rlos(n_b, l_a, m_a, l_b); + u3_noun pro = u3qdu_qor_llos(n_a, pre, m_b, r_b); + + u3z(pre); + + return pro; + } + else { + u3_noun pre = u3qdu_qor_llos(n_a, l_a, m_a, l_b); + u3_noun pro = u3qdu_qor_llos(n_b, pre, m_b, r_b); + + u3z(pre); + + return pro; + } + } + + case c3__rlos: { + u3_noun pre = u3qdu_qor_llos(n_a, l_a, m_a, l_b); + u3_noun pro = u3qdu_qor_rlos(n_b, pre, m_b, r_b); + + u3z(pre); + + return pro; + } + } +} + +u3_noun +u3wdu_qor_llsin(u3_noun cor) +{ + u3_noun a; + + if ( (c3n == u3r_mean(cor, u3x_sam, &a, 0 )) || + (c3n == u3du(a)) ) + { + return u3m_bail(c3__exit); + } else { + u3_noun n, l, m, r; + u3x_qual(a, &n, &l, &m, &r); + + if ( (c3n == u3du(n)) || (c3n == u3ud(m)) ) { + return u3m_bail(c3__exit); + } + else { + return u3qdu_qor_llsin(n, l, m, r); + } + } +} + diff --git a/jets/up_qor_lrsin.c b/jets/up_qor_lrsin.c @@ -0,0 +1,65 @@ +#include "all.h" + +u3_noun +u3qdu_qor_lrsin(u3_noun n_a, u3_noun l_a, u3_noun m_a, u3_noun r_a) +{ + if ( c3n == u3du(l_a) ) { + return u3m_bail(c3__exit); + } + + u3_noun b = u3t(u3t(l_a)); + + u3_noun n_b, l_b, m_b, r_b; + u3x_qual(b, &n_b, &l_b, &m_b, &r_b); + + u3_noun hol = u3h(l_a); + + if ( c3n == u3ud(hol) ) { + return u3m_bail(c3__exit); + } + else switch ( hol ) { + default: + return u3m_bail(c3__exit); + + case c3__llos: { + u3_noun pre = u3qdu_qor_llos(n_a, r_b, m_a, r_a); + u3_noun pro = u3qdu_qor_llos(n_b, l_b, m_b, pre); + + u3z(pre); + + return pro; + } + + case c3__rlos: { + u3_noun pre = u3qdu_qor_llos(n_b, r_b, m_a, r_a); + u3_noun pro = u3qdu_qor_llos(n_a, l_b, m_b, pre); + + u3z(pre); + + return pro; + } + } +} + +u3_noun +u3wdu_qor_lrsin(u3_noun cor) +{ + u3_noun a; + + if ( (c3n == u3r_mean(cor, u3x_sam, &a, 0 )) || + (c3n == u3du(a)) ) + { + return u3m_bail(c3__exit); + } else { + u3_noun n, l, m, r; + u3x_qual(a, &n, &l, &m, &r); + + if ( (c3n == u3du(n)) || (c3n == u3ud(m)) ) { + return u3m_bail(c3__exit); + } + else { + return u3qdu_qor_lrsin(n, l, m, r); + } + } +} + diff --git a/jets/up_qor_put.c b/jets/up_qor_put.c @@ -0,0 +1,133 @@ +#include "all.h" + +u3_noun +u3qdu_qor_put(u3_noun a, u3_noun k, u3_noun p, u3_noun v) +{ + if (u3_nul == a) { + return u3nt(u3nt(u3k(k), u3k(p), u3k(v)), u3_nul, u3k(k)); + } + + u3_noun n_a, t_a, m_a; + u3_noun k_n_a, p_n_a, v_n_a; + u3x_trel(a, &n_a, &t_a, &m_a); + u3x_trel(n_a, &k_n_a, &p_n_a, &v_n_a); + + if (u3_nul == t_a) { + if (c3y == u3r_sing(k, m_a)) { + return u3nt(u3nt(u3k(k), u3k(p), u3k(v)), u3_nul, u3k(k)); + } + else if (c3y == u3qc_gor(k, m_a)) { + u3_noun fel = u3nt(u3nt(u3k(k), u3k(p), u3k(v)), u3_nul, u3k(k)); + u3_noun fer = u3nt(u3k(n_a), u3_nul, u3k(k_n_a)); + + u3_noun pro = u3qdu_qor_toy(fel, fer); + + u3z(fel); + u3z(fer); + + return pro; + } + else { + u3_noun fel = u3nt(u3nt(u3k(k_n_a), u3k(p_n_a), u3k(v_n_a)), + u3_nul, + u3k(k_n_a)); + u3_noun fer = u3nt(u3nt(u3k(k), u3k(p), u3k(v)), u3_nul, u3k(k)); + u3_noun pro = u3qdu_qor_toy(fel, fer); + + u3z(fel); + u3z(fer); + + return pro; + } + } + + u3_noun hot = u3h(t_a); + + if (c3n == u3ud(hot)) { + return u3m_bail(c3__exit); + } + else switch ( hot ) { + default: + return u3m_bail(c3__exit); + + case c3__rlos: { + u3_noun b = u3t(u3t(t_a)); + + u3_noun n_b, l_b, m_b, r_b; + u3x_qual(b, &n_b, &l_b, &m_b, &r_b); + + if ( (c3y == u3r_sing(k, m_b)) || (c3y == u3qc_gor(k, m_b)) ) { + u3_noun fel = u3nt(u3k(n_a), u3k(l_b), u3k(m_b)); + u3_noun fer = u3nt(u3k(n_b), u3k(r_b), u3k(m_a)); + u3_noun pre = u3qdu_qor_put(fel, k, p, v); + u3_noun pro = u3qdu_qor_toy(pre, fer); + + u3z(pre); + u3z(fel); + u3z(fer); + + return pro; + } else { + u3_noun fel = u3nt(u3k(n_b), u3k(r_b), u3k(m_a)); + u3_noun fer = u3nt(u3k(n_a), u3k(l_b), u3k(m_b)); + u3_noun pre = u3qdu_qor_put(fel, k, p, v); + u3_noun pro = u3qdu_qor_toy(fer, pre); + + u3z(pre); + u3z(fel); + u3z(fer); + + return pro; + } + } + + case c3__llos: { + u3_noun b = u3t(u3t(t_a)); + + u3_noun n_b, l_b, m_b, r_b; + u3x_qual(b, &n_b, &l_b, &m_b, &r_b); + + if ( (c3y == u3r_sing(k, m_b)) || (c3y == u3qc_gor(k, m_b)) ) { + u3_noun fel = u3nt(u3k(n_b), u3k(l_b), u3k(m_b)); + u3_noun fer = u3nt(u3k(n_a), u3k(r_b), u3k(m_a)); + u3_noun pre = u3qdu_qor_put(fel, k, p, v); + + u3_noun pro = u3qdu_qor_toy(pre, fer); + + u3z(pre); + u3z(fel); + u3z(fer); + + return pro; + } else { + u3_noun fel = u3nt(u3k(n_a), u3k(r_b), u3k(m_a)); + u3_noun fer = u3nt(u3k(n_b), u3k(l_b), u3k(m_b)); + u3_noun pre = u3qdu_qor_put(fel, k, p, v); + u3_noun pro = u3qdu_qor_toy(fer, pre); + + u3z(pre); + u3z(fel); + u3z(fer); + + return pro; + } + } + } +} + +u3_noun +u3wdu_qor_put(u3_noun cor) +{ + u3_noun a, k, p, v; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &k, + u3x_sam_14, &p, u3x_sam_15, &v, 0)) || + (c3n == u3ud(p)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_qor_put(a, k, p, v); + } +} + + diff --git a/jets/up_qor_rbal.c b/jets/up_qor_rbal.c @@ -0,0 +1,205 @@ +#include "all.h" + +u3_noun +_rrdub(u3_noun n_a, u3_noun l_a, u3_noun m_a, u3_noun r_a) +{ + if ( c3n == u3du(l_a) ) { + return u3m_bail(c3__exit); + } + + u3_noun p_l_a = u3t(u3t(l_a)); + u3_noun hol = u3h(l_a); + + if ( c3n == u3ud(hol) ) { + return u3m_bail(c3__exit); + } + else switch ( hol ) { + default: + return u3m_bail(c3__exit); + + case c3__llos: { + u3_noun n_p_l_a, l_p_l_a, m_p_l_a, r_p_l_a; + u3x_qual(p_l_a, &n_p_l_a, &l_p_l_a, &m_p_l_a, &r_p_l_a); + + u3_noun pre = u3qdu_qor_llsin(n_p_l_a, l_p_l_a, m_p_l_a, r_p_l_a); + u3_noun pro = u3qdu_qor_rrsin(n_a, pre, m_a, r_a); + + u3z(pre); + + return pro; + } + + case c3__rlos: { + u3_noun n_p_l_a, l_p_l_a, m_p_l_a, r_p_l_a; + u3x_qual(p_l_a, &n_p_l_a, &l_p_l_a, &m_p_l_a, &r_p_l_a); + + u3_noun pre = u3qdu_qor_rlsin(n_p_l_a, l_p_l_a, m_p_l_a, r_p_l_a); + u3_noun pro = u3qdu_qor_rrsin(n_a, pre, m_a, r_a); + + u3z(pre); + + return pro; + } + } +} + +u3_noun +_rldub(u3_noun n_a, u3_noun l_a, u3_noun m_a, u3_noun r_a) +{ + if ( c3n == u3du(r_a) ) { + return u3m_bail(c3__exit); + } + + u3_noun p_r_a = u3t(u3t(r_a)); + u3_noun hor = u3h(r_a); + + if ( c3n == u3ud(hor) ) { + return u3m_bail(c3__exit); + } + else switch ( hor ) { + default: + return u3m_bail(c3__exit); + + case c3__llos: { + u3_noun n_p_r_a, l_p_r_a, m_p_r_a, r_p_r_a; + u3x_qual(p_r_a, &n_p_r_a, &l_p_r_a, &m_p_r_a, &r_p_r_a); + + u3_noun pre = u3qdu_qor_lrsin(n_p_r_a, l_p_r_a, m_p_r_a, r_p_r_a); + u3_noun pro = u3qdu_qor_rlsin(n_a, l_a, m_a, pre); + + u3z(pre); + + return pro; + } + + case c3__rlos: { + u3_noun n_p_r_a, l_p_r_a, m_p_r_a, r_p_r_a; + u3x_qual(p_r_a, &n_p_r_a, &l_p_r_a, &m_p_r_a, &r_p_r_a); + + u3_noun pre = u3qdu_qor_rrsin(n_p_r_a, l_p_r_a, m_p_r_a, r_p_r_a); + u3_noun pro = u3qdu_qor_rlsin(n_a, l_a, m_a, pre); + + u3z(pre); + + return pro; + } + } +} + +u3_noun +_rrbal(u3_noun n, u3_noun l, u3_noun m, u3_noun r) +{ + if ( c3n == u3du(l) ) { + return u3m_bail(c3__exit); + } + + u3_noun p_l = u3t(u3t(l)); + + u3_noun n_p_l, l_p_l, m_p_l, r_p_l; + u3x_qual(p_l, &n_p_l, &l_p_l, &m_p_l, &r_p_l); + + u3_atom sl = u3qdu_qor_size(l_p_l); + u3_atom sr = u3qdu_qor_size(r_p_l); + + c3_o comp = u3qa_gth(sl, sr); + + u3z(sl); + u3z(sr); + + return ( c3y == comp ) ? u3qdu_qor_rrsin(n, l, m, r) : _rrdub(n, l, m, r); +} + +u3_noun +_rlbal(u3_noun n, u3_noun l, u3_noun m, u3_noun r) +{ + if ( c3n == u3du(r) ) { + return u3m_bail(c3__exit); + } + + u3_noun p_r = u3t(u3t(r)); + + u3_noun n_p_r, l_p_r, m_p_r, r_p_r; + u3x_qual(p_r, &n_p_r, &l_p_r, &m_p_r, &r_p_r); + + u3_atom sl = u3qdu_qor_size(l_p_r); + u3_atom sr = u3qdu_qor_size(r_p_r); + + c3_o comp = u3qa_lth(sl, sr); + + u3z(sl); + u3z(sr); + + return ( c3y == comp ) ? u3qdu_qor_rlsin(n, l, m, r) : _rldub(n, l, m, r); +} + +u3_noun +u3qdu_qor_rbal(u3_noun n_a, u3_noun l_a, u3_noun m_a, u3_noun r_a) +{ + u3_atom sl = u3qdu_qor_size(l_a); + u3_atom sr = u3qdu_qor_size(r_a); + u3_atom s = u3qa_add(sl, sr); + + if ( c3y == u3qa_lth(s, 2) ) { + u3z(sl); + u3z(sr); + u3z(s); + + return u3qdu_qor_rlos(n_a, l_a, m_a, r_a); + } + else { + u3z(s); + + u3_atom sm_l = u3qa_mul(4, sl); + + if ( c3y == u3qa_gth(sr, sm_l) ) { + u3z(sl); + u3z(sr); + u3z(sm_l); + + return _rlbal(n_a, l_a, m_a, r_a); + } + else { + u3z(sr); + u3z(sm_l); + + u3_atom sm_r = u3qa_mul(4, sr); + + if ( c3y == u3qa_gth(sl, sm_r) ) { + u3z(sl); + u3z(sm_r); + + return _rrbal(n_a, l_a, m_a, r_a); + } + else { + u3z(sl); + u3z(sm_r); + + return u3qdu_qor_rlos(n_a, l_a, m_a, r_a); + } + } + } +} + +u3_noun +u3wdu_qor_rbal(u3_noun cor) +{ + u3_noun a; + + if ( (c3n == u3r_mean(cor, u3x_sam, &a, 0 )) || + (c3n == u3du(a)) ) + { + return u3m_bail(c3__exit); + } else { + u3_noun n, l, m, r; + u3x_qual(a, &n, &l, &m, &r); + + if ( (c3n == u3du(n)) || (c3n == u3ud(m)) ) { + return u3m_bail(c3__exit); + } + else { + return u3qdu_qor_rbal(n, l, m, r); + } + } +} + + diff --git a/jets/up_qor_rlos.c b/jets/up_qor_rlos.c @@ -0,0 +1,41 @@ +#include "all.h" + +u3_noun +u3qdu_qor_rlos(u3_noun n, u3_noun l, u3_atom m, u3_noun r) +{ + u3_atom sl = u3qdu_qor_size(l); + u3_atom sr = u3qdu_qor_size(r); + u3_atom s = u3qa_add(sl, sr); + + u3_noun pro = u3qa_inc(s); + + u3z(sl); + u3z(sr); + u3z(s); + + return u3nt(c3__rlos, pro, u3nq(u3k(n), u3k(l), u3k(m), u3k(r))); +} + +u3_noun +u3wdu_qor_rlos(u3_noun cor) +{ + u3_noun a; + + if ( (c3n == u3r_mean(cor, u3x_sam, &a, 0)) || + (c3n == u3du(a)) ) + { + return u3m_bail(c3__exit); + } else { + u3_noun n, l, m, r; + + u3x_qual(a, &n, &l, &m, &r); + + if ( (c3n == u3du(n)) || (c3n == u3ud(m)) ) { + return u3m_bail(c3__exit); + } + else { + return u3qdu_qor_rlos(n, l, m, r); + } + } +} + diff --git a/jets/up_qor_rlsin.c b/jets/up_qor_rlsin.c @@ -0,0 +1,65 @@ +#include "all.h" + +u3_noun +u3qdu_qor_rlsin(u3_noun n_a, u3_noun l_a, u3_noun m_a, u3_noun r_a) +{ + if ( c3n == u3du(r_a) ) { + return u3m_bail(c3__exit); + } + + u3_noun b = u3t(u3t(r_a)); + + u3_noun n_b, l_b, m_b, r_b; + u3x_qual(b, &n_b, &l_b, &m_b, &r_b); + + u3_noun hor = u3h(r_a); + + if ( c3n == u3ud(hor) ) { + return u3m_bail(c3__exit); + } + else switch ( hor ) { + default: + return u3m_bail(c3__exit); + + case c3__llos: { + u3_noun pre = u3qdu_qor_rlos(n_b, l_a, m_a, l_b); + u3_noun pro = u3qdu_qor_rlos(n_a, pre, m_b, r_b); + + u3z(pre); + + return pro; + } + + case c3__rlos: { + u3_noun pre = u3qdu_qor_rlos(n_a, l_a, m_a, l_b); + u3_noun pro = u3qdu_qor_rlos(n_b, pre, m_b, r_b); + + u3z(pre); + + return pro; + } + } +} + +u3_noun +u3wdu_qor_rlsin(u3_noun cor) +{ + u3_noun a; + + if ( (c3n == u3r_mean(cor, u3x_sam, &a, 0 )) || + (c3n == u3du(a)) ) + { + return u3m_bail(c3__exit); + } else { + u3_noun n, l, m, r; + u3x_qual(a, &n, &l, &m, &r); + + if ( (c3n == u3du(n)) || (c3n == u3ud(m)) ) { + return u3m_bail(c3__exit); + } + else { + return u3qdu_qor_rlsin(n, l, m, r); + } + } +} + diff --git a/jets/up_qor_rrsin.c b/jets/up_qor_rrsin.c @@ -0,0 +1,89 @@ +#include "all.h" + +u3_noun +u3qdu_qor_rrsin(u3_noun n_a, u3_noun l_a, u3_noun m_a, u3_noun r_a) +{ + if ( c3n == u3du(l_a) ) { + return u3m_bail(c3__exit); + } + + u3_noun b = u3t(u3t(l_a)); + + u3_noun n_b, l_b, m_b, r_b, t_b; + u3_noun k_n_b; + u3x_qual(b, &n_b, &l_b, &m_b, &r_b); + u3x_cell(n_b, &k_n_b, &t_b); + + u3_noun p_n_b = u3h(t_b); + u3_noun hol = u3h(l_a); + + if ( c3n == u3ud(hol) ) { + return u3m_bail(c3__exit); + } + else switch ( hol ) { + default: + return u3m_bail(c3__exit); + + case c3__llos: { + u3_noun pre = u3qdu_qor_rlos(n_a, r_b, m_a, r_a); + u3_noun pro = u3qdu_qor_llos(n_b, l_b, m_b, pre); + + u3z(pre); + + return pro; + } + + case c3__rlos: { + u3_noun k_n_a; + u3_noun t_a; + + u3x_cell(n_a, &k_n_a, &t_a); + + u3_noun p_n_a = u3h(t_a); + + if ( (c3n == u3ud(p_n_a)) || (c3n == u3ud(p_n_b)) ) { + return u3m_bail(c3__exit); + } + + if ( c3y == u3qdu_lex(p_n_a, k_n_a, p_n_b, k_n_b) ) { + u3_noun pre = u3qdu_qor_llos(n_b, r_b, m_a, r_a); + u3_noun pro = u3qdu_qor_rlos(n_a, l_b, m_b, pre); + + u3z(pre); + + return pro; + } + else { + u3_noun pre = u3qdu_qor_rlos(n_a, r_b, m_a, r_a); + u3_noun pro = u3qdu_qor_rlos(n_b, l_b, m_b, pre); + + u3z(pre); + + return pro; + } + } + } +} + +u3_noun +u3wdu_qor_rrsin(u3_noun cor) +{ + u3_noun a; + + if ( (c3n == u3r_mean(cor, u3x_sam, &a, 0 )) || + (c3n == u3du(a)) ) + { + return u3m_bail(c3__exit); + } else { + u3_noun n, l, m, r; + u3x_qual(a, &n, &l, &m, &r); + + if ( (c3n == u3du(n)) || (c3n == u3ud(m)) ) { + return u3m_bail(c3__exit); + } + else { + return u3qdu_qor_rrsin(n, l, m, r); + } + } +} + diff --git a/jets/up_qor_sec.c b/jets/up_qor_sec.c @@ -0,0 +1,66 @@ +#include "all.h" + +u3_noun +u3qdu_qor_sec(u3_noun t, u3_atom m) +{ + if ( u3_nul == t ) { + return u3_nul; + } + else { + u3_noun hol = u3h(t); + + if ( c3n == u3ud(hol) ) { + return u3m_bail(c3__exit); + } + else switch ( hol ) { + default: + return u3m_bail(c3__exit); + + case c3__llos: { + u3_noun n_p_t, l_p_t, m_p_t, r_p_t; + u3x_qual(u3t(u3t(t)), &n_p_t, &l_p_t, &m_p_t, &r_p_t); + + u3_noun fel = u3nt(u3k(n_p_t), u3k(l_p_t), u3k(m_p_t)); + + u3_noun pre = u3qdu_qor_sec(r_p_t, m); + u3_noun pro = u3qdu_qor_toy(fel, pre); + + u3z(fel); + u3z(pre); + + return pro; + } + + case c3__rlos: { + u3_noun n_p_t, l_p_t, m_p_t, r_p_t; + u3x_qual(u3t(u3t(t)), &n_p_t, &l_p_t, &m_p_t, &r_p_t); + + u3_noun fer = u3nt(u3k(n_p_t), u3k(r_p_t), u3k(m)); + + u3_noun pre = u3qdu_qor_sec(l_p_t, m_p_t); + u3_noun pro = u3qdu_qor_toy(pre, fer); + + u3z(fer); + u3z(pre); + + return pro; + } + } + } +} + +u3_noun +u3wdu_qor_sec(u3_noun cor) +{ + u3_noun t, m; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &t, u3x_sam_3, &m, 0 )) || + (c3n == u3ud(m)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_qor_sec(t, m); + } +} + + diff --git a/jets/up_qor_see.c b/jets/up_qor_see.c @@ -0,0 +1,64 @@ +#include "all.h" + +u3_noun +u3qdu_qor_see(u3_noun a) +{ + if (u3_nul == a) { + return u3_nul; + } + + u3_noun n_a, t_a, m_a; + u3x_trel(a, &n_a, &t_a, &m_a); + + if (u3_nul == t_a) { + return u3nc(c3__sing, u3k(n_a)); + } + + u3_atom hot = u3h(t_a); + + if ( c3n == u3ud(hot) ) { + return u3m_bail(c3__exit); + } + else switch ( hot ) { + default: + return u3m_bail(c3__exit); + + case c3__llos: { + u3_noun p_t_a = u3t(u3t(t_a)); + + u3_noun n_p_t_a, l_p_t_a, m_p_t_a, r_p_t_a; + u3x_qual(p_t_a, &n_p_t_a, &l_p_t_a, &m_p_t_a, &r_p_t_a); + + return u3nt( + c3__play, + u3nt(u3k(n_p_t_a), u3k(l_p_t_a), u3k(m_p_t_a)), + u3nt(u3k(n_a), u3k(r_p_t_a), u3k(m_a))); + } + + case c3__rlos: { + u3_noun p_t_a = u3t(u3t(t_a)); + + u3_noun n_p_t_a, l_p_t_a, m_p_t_a, r_p_t_a; + u3x_qual(p_t_a, &n_p_t_a, &l_p_t_a, &m_p_t_a, &r_p_t_a); + + return u3nt( + c3__play, + u3nt(u3k(n_a), u3k(l_p_t_a), u3k(m_p_t_a)), + u3nt(u3k(n_p_t_a), u3k(r_p_t_a), u3k(m_a))); + } + } +} + +u3_noun +u3wdu_qor_see(u3_noun cor) +{ + u3_noun a; + + if (c3n == u3r_mean(cor, u3x_sam, &a, 0)) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_qor_see(a); + } +} + diff --git a/jets/up_qor_sink.c b/jets/up_qor_sink.c @@ -0,0 +1,36 @@ +#include "all.h" + +u3_noun +u3qdu_qor_sink(u3_noun a, u3_noun k, u3_atom p, u3_noun v) +{ + u3_noun b = u3qdu_qor_put(a, k, p, v); + u3_noun pre = u3qdu_qor_bot(b); + + u3z(b); + + if (u3_nul == pre) { + return u3m_bail(c3__exit); + } else + { + u3_noun pro = u3k(u3t(pre)); + u3z(pre); + + return pro; + } +} + +u3_noun +u3wdu_qor_sink(u3_noun cor) +{ + u3_noun a, k, p, v; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &k, u3x_sam_14, &p, + u3x_sam_15, &v, 0)) || + (c3n == u3ud(p)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_qor_sink(a, k, p, v); + } +} + diff --git a/jets/up_qor_size.c b/jets/up_qor_size.c @@ -0,0 +1,33 @@ +#include "all.h" + +u3_atom +u3qdu_qor_size(u3_noun t) +{ + if ( u3_nul == t ) { + return 0; + } + else { + u3_atom pro = u3k(u3h(u3t(t))); + + if ( c3n == u3ud(pro) ) { + return u3m_bail(c3__exit); + } + else { + return pro; + } + } +} + +u3_noun +u3wdu_qor_size(u3_noun cor) +{ + u3_noun t; + + if ( (c3n == u3r_mean(cor, u3x_sam, &t, 0)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_qor_size(t); + } +} + diff --git a/jets/up_qor_top.c b/jets/up_qor_top.c @@ -0,0 +1,26 @@ +#include "all.h" + +u3_noun +u3qdu_qor_top(u3_noun a) +{ + if (u3_nul == a) { + return u3m_bail(c3__exit); + } + else { + return u3k(u3t(u3t(a))); + } +} + +u3_noun +u3wdu_qor_top(u3_noun cor) +{ + u3_noun a; + + if (c3n == u3r_mean(cor, u3x_sam, &a, 0)) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_qor_top(a); + } +} + diff --git a/jets/up_qor_toy.c b/jets/up_qor_toy.c @@ -0,0 +1,44 @@ +#include "all.h" + +u3_noun +u3qdu_qor_toy(u3_noun a, u3_noun b) +{ + if ( u3_nul == a ) { + return u3k(b); + } + else if ( u3_nul == b ) { + return u3k(a); + } + else { + u3_noun n_a, t_a, m_a; + u3_noun n_b, t_b, m_b; + u3x_trel(a, &n_a, &t_a, &m_a); + u3x_trel(b, &n_b, &t_b, &m_b); + + u3_noun k_n_a, p_n_a, v_n_a; + u3_noun k_n_b, p_n_b, v_n_b; + u3x_trel(n_a, &k_n_a, &p_n_a, &v_n_a); + u3x_trel(n_b, &k_n_b, &p_n_b, &v_n_b); + + if ( c3y == u3qdu_lex(p_n_a, k_n_a, p_n_b, k_n_b) ) { + return u3nt(u3k(n_a), u3qdu_qor_rbal(n_b, t_a, m_a, t_b), u3k(m_b)); + } + else { + return u3nt(u3k(n_b), u3qdu_qor_lbal(n_a, t_a, m_a, t_b), u3k(m_b)); + } + } +} + +u3_noun +u3wdu_qor_toy(u3_noun cor) +{ + u3_noun a, b; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0 )) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_qor_toy(a, b); + } +} + diff --git a/jets/up_rule.c b/jets/up_rule.c @@ -0,0 +1,33 @@ +#include "all.h" + +u3_noun +u3qdu_rule(u3_atom k, u3_atom p, u3_noun v, u3_noun a, u3_noun b) +{ + u3_atom l = u3h(u3t(a)); + u3_atom m = u3qdu_peak(k, l); + + return (c3y == u3qdu_zero(m, l)) + ? u3nq(c3__bin, u3k(k), u3k(p), u3nq(u3k(v), m, u3k(a), u3k(b))) + : u3nq(c3__bin, u3k(k), u3k(p), u3nq(u3k(v), m, u3k(b), u3k(a))); +} + +u3_noun +u3wdu_rule(u3_noun cor) +{ + u3_atom k, p; + u3_noun v, a, b; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &k, u3x_sam_6, &p, u3x_sam_14, &v, + u3x_sam_30, &a, u3x_sam_31, &b, 0)) || + (c3n == u3ud(p)) || + (c3n == u3du(v)) || + (c3n == u3du(a)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_rule(k, p, v, a, b); + } +} + + + diff --git a/jets/up_see.c b/jets/up_see.c @@ -0,0 +1,157 @@ +#include "all.h" + +static u3_noun +_stir(u3_noun k, u3_atom p, u3_noun l, u3_atom q, u3_noun buc) +{ + u3_noun vb, tb; + u3x_cell(buc, &vb, &tb); + + if (c3y == u3r_sing(k, l)) { + if (u3_nul == tb) { + return u3nc(u3nt(u3_nul, u3k(q), u3k(vb)), + u3qdu_qor_sink(tb, l, p, vb)); + } + else { + return u3nc(u3nt(u3_nul, u3k(q), u3k(vb)), + u3qdu_qor_sink(tb, k, p, vb)); + } + } + else { + u3_noun val = u3qdu_qor_get(tb, k); + + if (u3_nul == val) { + return u3nq(u3_nul, u3k(l), u3k(q), u3k(buc)); + } + else { + u3_noun pro = u3nq(u3k(val), u3k(l), u3k(q), + u3nc(u3k(vb), + u3qdu_qor_put(tb, k, p, u3t(u3t(val))))); + + u3z(val); + return pro; + } + } +} + +u3_noun +u3qdu_see(u3_noun a, u3_noun k, u3_noun p) +{ + if (u3_nul == a) { + return u3nc(u3_nul, u3_nul); + } + + u3_atom hoc = u3h(a); + + if (c3n == u3ud(hoc)) { + return u3m_bail(c3__exit); + } + else switch ( hoc ) { + default: + return u3m_bail(c3__exit); + + case c3__tip: { + u3_noun ka, pa, va; + u3x_trel(u3t(a), &ka, &pa, &va); + + u3_atom mk = u3r_mug(k); + u3_atom mka = u3r_mug(ka); + + if (mk != mka) { + return u3nc(u3_nul, u3k(a)); + } + else { + u3_noun mud = _stir(k, p, ka, pa, va); + + u3_noun pm, qm, rm, sm; + u3x_qual(mud, &pm, &qm, &rm, &sm); + + u3_noun pro = u3nc(u3k(pm), u3nq(c3__tip, u3k(qm), u3k(rm), u3k(sm))); + + u3z(mud); + + return pro; + } + } + + case c3__bin: { + u3_noun ka, pa, va, ta, ma, la, ra; + u3x_qual(u3t(a), &ka, &pa, &va, &ta); + u3x_trel(ta, &ma, &la, &ra); + + if (c3y == u3qdu_feud(ma, k, ka)) { + return u3nc(u3_nul, u3k(a)); + } + + u3_atom mk = u3r_mug(k); + u3_atom mka = u3r_mug(ka); + + if (mk == mka) { + u3_noun mud = _stir(k, p, ka, pa, va); + u3_noun pm, qm, rm, sm; + u3x_qual(mud, &pm, &qm, &rm, &sm); + + if (c3y == u3qdu_zero(ma, k)) { + u3_noun lef = u3qdu_qat_raw(la, qm, rm, sm); + u3_noun pro = u3nc(u3k(pm), u3qdu_fuse(ma, lef, ra)); + + u3z(mud); + u3z(lef); + + return pro; + } + else { + u3_noun rye = u3qdu_qat_raw(ra, qm, rm, sm); + u3_noun pro = u3nc(u3k(pm), u3qdu_fuse(ma, la, rye)); + + u3z(mud); + u3z(rye); + + return pro; + } + } + else if (c3y == u3qdu_zero(ma, k)) { + u3_noun val = u3qdu_see(la, k, p); + + u3_noun pv, qv; + u3x_cell(val, &pv, &qv); + + u3_noun pro = u3nc(u3k(pv), + u3nq(c3__bin, u3k(ka), u3k(pa), + u3nq(u3k(va), u3k(ma), u3k(qv), u3k(ra)))); + + u3z(val); + return pro; + } + else { + u3_noun val = u3qdu_see(ra, k, p); + + u3_noun pv, qv; + u3x_cell(val, &pv, &qv); + + u3_noun pro = u3nc(u3k(pv), + u3nq(c3__bin, u3k(ka), u3k(pa), + u3nq(u3k(va), u3k(ma), u3k(la), u3k(qv)))); + + u3z(val); + return pro; + } + } + } +} + +u3_noun +u3wdu_see(u3_noun cor) +{ + u3_noun a, k, p; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &k, + u3x_sam_7, &p, 0)) || + (c3n == u3ud(p)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_see(a, k, p); + } +} + + diff --git a/jets/up_vip.c b/jets/up_vip.c @@ -0,0 +1,160 @@ +#include "all.h" + +u3_noun +u3qdu_vip(u3_noun a, u3_noun k, u3_atom p, u3_noun v) +{ + if (u3_nul == a) { + return u3nc(u3_nul, + u3nq(c3__tip, u3k(k), u3k(p), u3nc(u3k(v), u3_nul))); + } + + u3_atom hoc = u3h(a); + + if (c3n == u3ud(hoc)) { + return u3m_bail(c3__exit); + } + else switch ( hoc) { + default: + return u3m_bail(c3__exit); + + case c3__tip: { + u3_noun ka, pa, va; + u3x_trel(u3t(a), &ka, &pa, &va); + + u3_noun vva, tva; + u3x_cell(va, &vva, &tva); + + u3_atom mk = u3r_mug(k); + u3_atom mka = u3r_mug(ka); + + if (c3y == u3r_sing(mk, mka)) { + if (c3y == u3r_sing(k, ka)) { + return u3nc(u3nt(u3_nul, u3k(pa), u3k(vva)), + u3nc(c3__tip, u3qdu_qor_sink(tva, k, p, v))); + } + else { + u3_noun got = u3qdu_qor_get(tva, k); + u3_noun buc = u3nc(u3k(vva), u3qdu_qor_put(tva, k, p, v)); + u3_noun pro = u3nc(u3k(got), + u3nq(c3__tip, u3k(ka), u3k(pa), u3k(buc))); + + u3z(got); + u3z(buc); + return pro; + } + } + else { + u3_noun lef = u3nq(c3__tip, u3k(k), u3k(p), u3nc(u3k(v), u3_nul)); + u3_noun pro = u3nc(u3_nul, u3qdu_rule(ka, pa, va, lef, u3_nul)); + + u3z(lef); + return pro; + } + } + + case c3__bin: { + u3_noun ka, pa, va, ta, ma, la, ra; + u3x_qual(u3t(a), &ka, &pa, &va, &ta); + u3x_trel(ta, &ma, &la, &ra); + + if (c3y == u3qdu_feud(ma, k, ka)) { + u3_noun lef = u3nq(c3__tip, u3k(k), u3k(p), u3nc(u3k(v), u3_nul)); + u3_noun rye = u3qdu_fuse(ma, la, ra); + + u3_noun pro = u3nc(u3_nul, u3qdu_rule(ka, pa, va, lef, rye)); + + u3z(lef); + u3z(rye); + + return pro; + } + + u3_noun mk = u3r_mug(k); + u3_noun mka = u3r_mug(ka); + + if (c3y == u3r_sing(mk, mka)) { + + u3_noun vva, tva; + u3x_cell(va, &vva, &tva); + + if (c3y == u3r_sing(k, ka)) { + u3_noun val = u3qdu_qor_sink(tva, k, p, v); + + u3_noun pv, qv, rv; + u3x_trel(val, &pv, &qv, &rv); + + if (c3y == u3qdu_zero(ma, pv)) { + u3_noun lef = u3qdu_qat_raw(la, pv, qv, rv); + u3_noun pro = u3nc(u3nt(u3_nul, u3k(pa), u3k(vva)), + u3qdu_fuse(ma, lef, ra)); + + u3z(val); + u3z(lef); + + return pro; + } + else { + u3_noun rye = u3qdu_qat_raw(ra, pv, qv, rv); + u3_noun pro = u3nc(u3nt(u3_nul, u3k(pa), u3k(vva)), + u3qdu_fuse(ma, la, rye)); + + u3z(val); + u3z(rye); + + return pro; + } + } + else { + u3_noun got = u3qdu_qor_get(tva, k); + u3_noun buc = u3nc(u3k(vva), u3qdu_qor_put(tva, k, p, v)); + u3_noun pro = u3nc(u3k(got), + u3nq(c3__bin, u3k(ka), u3k(pa), + u3nq(u3k(buc), u3k(ma), u3k(la), u3k(ra)))); + + u3z(got); + u3z(buc); + + return pro; + } + + } + else if (c3y == u3qdu_zero(ma, k)) { + u3_noun val = u3qdu_vip(la, k, p, v); + u3_noun pro = u3nc(u3k(u3h(val)), + u3nq(c3__bin, u3k(ka), u3k(pa), + u3nq(u3k(va), u3k(ma), u3k(u3t(val)), u3k(ra)))); + + u3z(val); + + return pro; + } + else { + u3_noun val = u3qdu_vip(ra, k, p, v); + u3_noun pro = u3nc(u3k(u3h(val)), + u3nq(c3__bin, u3k(ka), u3k(pa), + u3nq(u3k(va), u3k(ma), u3k(la), u3k(u3t(val))))); + + u3z(val); + + return pro; + } + } + } +} + +u3_noun +u3wdu_vip(u3_noun cor) +{ + u3_noun a, k, p, v; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &k, u3x_sam_14, &p, + u3x_sam_15, &v, 0)) || + (c3n == u3ud(p)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_vip(a, k, p, v); + } +} + + diff --git a/jets/up_wane.c b/jets/up_wane.c @@ -0,0 +1,39 @@ +#include "all.h" + +u3_noun +u3qdu_wane(u3_noun k, u3_atom p, u3_noun v, u3_atom m, u3_noun l, u3_noun r) +{ + if ( u3_nul == r ) { + if ( u3_nul == l) { + return u3nq(c3__tip, u3k(k), u3k(p), u3k(v)); + } + else { + return u3nq(c3__bin, u3k(k), u3k(p), + u3nq(u3k(v), u3k(m), u3k(l), u3_nul)); + } + } + else { + return u3nq(c3__bin, u3k(k), u3k(p), + u3nq(u3k(v), u3k(m), u3k(l), u3k(r))); + } +} + +u3_noun +u3wdu_wane(u3_noun cor) +{ + u3_noun k, p, v, m, l, r; + + if ( + (c3n == u3r_mean(cor, u3x_sam_2, &k, u3x_sam_6, &p, u3x_sam_14, &v, + u3x_sam_30, &m, u3x_sam_62, &l, u3x_sam_63, &r, 0 )) || + (c3n == u3ud(m)) || + (c3n == u3ud(p)) || + (c3n == u3du(v)) + ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_wane(k, p, v, m, l, r); + } +} + diff --git a/jets/up_zero.c b/jets/up_zero.c @@ -0,0 +1,29 @@ +#include "all.h" + +c3_o +u3qdu_zero(u3_atom m, u3_noun k) +{ + u3_atom h = u3r_mug(k); + u3_atom d = u3qc_dis(m, h); + u3_atom pro = ( d == 0 ) ? c3y : c3n; + + u3z(h); + u3z(d); + + return pro; +} + +u3_noun +u3wdu_zero(u3_noun cor) +{ + u3_noun m, k; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &m, u3x_sam_3, &k, 0)) || + (c3n == u3ud(m)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qdu_zero(m, k); + } +} + diff --git a/up.hoon b/up.hoon @@ -0,0 +1,856 @@ +:- %say +|= [* ~ ~] +:- %noun +:: priority search queue and LRU cache engines +:: +|% +++ up + ~/ %up + |* [k=mold v=mold] + :: molds and mold builders + :: + ~% %core + ~ + |% + +$ pri :: psq + $@ ~ + $% [%bin =k p=@ v=buc m=@ l=pri r=pri] + [%tip =k p=@ v=buc] + == + :: + +$ buc [=v t=pro] :: collision handling + :: + +$ pro $@(~ [n=elem t=ltree m=k]) :: internal psq + :: + +$ elem [=k p=@ =v] :: key, pri, value + :: + +$ ltree :: loser tree + $@ ~ + $% [%llos s=@ p=lnode] + [%rlos s=@ p=lnode] + == + :: + +$ lnode [n=elem l=ltree m=k r=ltree] :: loser tree node + :: + +$ torn :: tournament view + $@ ~ + $% [%sing n=elem] + [%play l=pro r=pro] + == + :: utilities + :: + ++ lex :: muggish lex order + ~/ %lex + |= [p=@ k=k q=@ l=k] + ^- ? + ?: =(p q) + (gor k l) + (lth p q) + :: radix tree utilities + :: + ++ zero :: mask keeps none + ~/ %zero + |= [m=@ k=k] + ^- ? + =(0 (dis (mug k) m)) + :: + ++ peak :: max unlike bit + ~/ %peak + |= [k=k l=k] + ^- @ + (rsh 0 (bex (xeb (mix (mug k) (mug l))))) + :: + ++ feud :: high bits differ + ~/ %feud + |= [m=@ k=k l=k] + ^- ? + =/ n (mix (mix (dec m) 0x7fff.ffff) m) :: 31-bit high mask + !=((dis (mug k) n) (dis (mug l) n)) + :: + ++ rule :: decide branch + ~/ %rule :: + |= [k=k p=@ v=buc a=pri b=pri] :: a must be nonempty + ^- pri + =/ l +<.a + =/ m (peak k l) + ?: (zero m l) + [%bin k p v m a b] + [%bin k p v m b a] + :: + ++ fuse :: disjoint tree merge + ~/ %fuse + |= [m=@ l=pri r=pri] + ^- pri + ?~ l r + ?- -.l + %tip + ?~ r l + :- %bin + ?- -.r + %tip + ?: (lex p.l k.l p.r k.r) + [k.l p.l v.l m ~ r] + [k.r p.r v.r m l ~] + :: + %bin + ?: (lex p.l k.l p.r k.r) + [k.l p.l v.l m ~ r] + [k.r p.r v.r m l $(m m.r, l l.r, r r.r)] + == + :: + %bin + ?~ r l + :- %bin + ?- -.r + %tip + ?: (lex p.l k.l p.r k.r) + [k.l p.l v.l m $(m m.l, l l.l, r r.l) r] + [k.r p.r v.r m l ~] + :: + %bin + ?: (lex p.l k.l p.r k.r) + [k.l p.l v.l m $(m m.l, l l.l, r r.l) r] + [k.r p.r v.r m l $(m m.r, l l.r, r r.r)] + == + == + :: + ++ funk :: shrink node (left) + ~/ %funk + |= [k=k p=@ v=buc m=@ l=pri r=pri] + ^- pri + ?~ l + ?~ r + [%tip k p v] + [%bin k p v m ~ r] + [%bin k p v m l r] + :: + ++ wane :: shrink node (right) + ~/ %wane + |= [k=k p=@ v=buc m=@ l=pri r=pri] + ^- pri + ?~ r + ?~ l + [%tip k p v] + [%bin k p v m l ~] + [%bin k p v m l r] + :: collision resolution + :: + ++ qor + ~% %qor ..qor ~ + |% + :: loser tree internals + :: + ++ wyt :: queue size + ~/ %wyt + |= =pro + ^- @ + ?~ pro 0 + +((size t.pro)) + :: + ++ size :: loser tree size + ~/ %size + |= t=ltree + ^- @ + ?~(t 0 s.t) + :: + ++ llos :: left loser node + ~/ %llos + |= a=lnode + ^- ltree + [%llos +((add (size l.a) (size r.a))) a] + :: + ++ rlos :: right loser node + ~/ %rlos + |= a=lnode + ^- ltree + [%rlos +((add (size l.a) (size r.a))) a] + :: + ++ lbal :: left-balance + ~/ %lbal + |= a=lnode + ^- ltree + =/ sl (size l.a) + =/ sr (size r.a) + ?: (lth (add sl sr) 2) + (llos a) + ?: (gth sr (mul 4 sl)) + ?> ?=(^ r.a) + ?: (lth (size l.p.r.a) (size r.p.r.a)) + (llsin a) + ?- -.r.a + %llos (llsin n.a l.a m.a (lrsin p.r.a)) + %rlos (llsin n.a l.a m.a (rrsin p.r.a)) + == + ?: (gth sl (mul 4 sr)) + ?> ?=(^ l.a) + ?: (gth (size l.p.l.a) (size r.p.l.a)) + (lrsin a) + ?- -.l.a + %llos (lrsin n.a (llsin p.l.a) m.a r.a) + %rlos (lrsin n.a (rlsin p.l.a) m.a r.a) + == + (llos a) + :: + ++ rbal :: right-balance + ~/ %rbal + |= a=lnode + ^- ltree + =/ sl (size l.a) + =/ sr (size r.a) + ?: (lth (add sl sr) 2) + (rlos a) + ?: (gth sr (mul 4 sl)) + ?> ?=(^ r.a) + ?: (lth (size l.p.r.a) (size r.p.r.a)) + (rlsin a) + ?- -.r.a + %llos (rlsin n.a l.a m.a (lrsin p.r.a)) + %rlos (rlsin n.a l.a m.a (rrsin p.r.a)) + == + ?: (gth sl (mul 4 sr)) + ?> ?=(^ l.a) + ?: (gth (size l.p.l.a) (size r.p.l.a)) + (rrsin a) + ?- -.l.a + %llos (rrsin n.a (llsin p.l.a) m.a r.a) + %rlos (rrsin n.a (rlsin p.l.a) m.a r.a) + == + (rlos a) + :: + ++ llsin :: left single-left + ~/ %llsin + |= a=lnode + ^- ltree + ?> ?=(^ r.a) + =/ b p.r.a + ?- -.r.a + %llos + ?: (lex p.n.a k.n.a p.n.b k.n.b) + (llos n.a (rlos n.b l.a m.a l.b) m.b r.b) + (llos n.b (llos n.a l.a m.a l.b) m.b r.b) + %rlos + (rlos n.b (llos n.a l.a m.a l.b) m.b r.b) + == + :: + ++ rlsin :: right single-right + ~/ %rlsin + |= a=lnode + ^- ltree + ?> ?=(^ r.a) + =/ b p.r.a + ?- -.r.a + %llos (rlos n.a (rlos n.b l.a m.a l.b) m.b r.b) + %rlos (rlos n.b (rlos n.a l.a m.a l.b) m.b r.b) + == + :: + ++ lrsin + ~/ %lrsin + |= a=lnode + ^- ltree + ?> ?=(^ l.a) + =/ b p.l.a + ?- -.l.a + %llos (llos n.b l.b m.b (llos n.a r.b m.a r.a)) + %rlos (llos n.a l.b m.b (llos n.b r.b m.a r.a)) + == + :: + ++ rrsin + ~/ %rrsin + |= a=lnode + ^- ltree + ?> ?=(^ l.a) + =/ b p.l.a + ?- -.l.a + %llos + (llos n.b l.b m.b (rlos n.a r.b m.a r.a)) + %rlos + ?: (lex p.n.a k.n.a p.n.b k.n.b) + (rlos n.a l.b m.b (llos n.b r.b m.a r.a)) + (rlos n.b l.b m.b (rlos n.a r.b m.a r.a)) + == + :: + ++ toy :: play + ~/ %toy + |= [a=pro b=pro] + ^- pro + ?~ a b + ?~ b a + ?: (lex p.n.a k.n.a p.n.b k.n.b) + [n.a (rbal n.b t.a m.a t.b) m.b] + [n.b (lbal n.a t.a m.a t.b) m.b] + :: + ++ sec :: second best + ~/ %sec + |= [t=ltree m=k] + |- ^- pro + ?~ t ~ + ?- -.t + %llos (toy [n.p.t l.p.t m.p.t] $(t r.p.t)) + %rlos (toy $(t l.p.t, m m.p.t) [n.p.t r.p.t m]) + == + :: + ++ sink :: make bucket + ~/ %sink + |= [a=pro =k p=@ =v] + ^- (trel _k @ buc) + =. a (put a k p v) + =/ val (bot a) + ?>(?=(^ val) u.val) + :: + ++ see :: tournament view + ~/ %see + |= a=pro + ^- torn + ?~ a ~ + ?~ t.a + [%sing n.a] + ?- -.t.a + %llos [%play [n.p.t.a l.p.t.a m.p.t.a] [n.a r.p.t.a m.a]] + %rlos [%play [n.a l.p.t.a m.p.t.a] [n.p.t.a r.p.t.a m.a]] + == + :: + ++ tap :: convert to list + ~/ %tap + |= a=pro + =| b=(list elem) + |- ^+ b + =/ tor (see a) + ?~ tor b + ?- -.tor + %sing [n.tor b] + %play (weld $(a l.tor) $(a r.tor)) + == + :: + ++ put :: add [key pri val] + ~/ %put + |= [a=pro =k p=@ =v] + |- ^- pro + ?~ a + [[k p v] ~ k] + ?: ?=(~ t.a) + ?: =(k m.a) + [[k p v] ~ k] + ?: (gor k m.a) + (toy [[k p v] ~ k] [n.a ~ k.n.a]) + (toy [n.a ~ k.n.a] [[k p v] ~ k]) + ?- -.t.a + %rlos + =/ b=lnode p.t.a + ?: |(=(k m.b) (gor k m.b)) + (toy $(a [n.a l.b m.b]) [n.b r.b m.a]) + (toy [n.a l.b m.b] $(a [n.b r.b m.a])) + :: + %llos + =/ b=lnode p.t.a + ?: |(=(k m.b) (gor k m.b)) + (toy $(a [n.b l.b m.b]) [n.a r.b m.a]) + (toy [n.b l.b m.b] $(a [n.a r.b m.a])) + == + :: + ++ has :: contains + ~/ %has + |= [a=pro =k] + !=(~ (get a k)) + :: + ++ get :: lookup + ~/ %get + |= [a=pro =k] + |- ^- (unit (pair @ v)) + ?~ a ~ + =/ tor=torn (see a) + ?~ tor ~ + ?- -.tor + %sing + ?. =(k k.n.tor) ~ + `[p.n.tor v.n.tor] + :: + %play + ?> ?=(^ l.tor) + ?: |(=(k m.l.tor) (gor k m.l.tor)) + $(a l.tor) + $(a r.tor) + == + :: + ++ del :: delete at key k + ~/ %del + |= [a=pro =k] + |- ^- pro + ?~ a ~ + ?: ?=(~ t.a) + ?: =(k k.n.a) ~ + [n.a ~ k.n.a] + ?- -.t.a + %rlos + =/ b=lnode p.t.a + ?: |(=(k m.b) (gor k m.b)) + (toy $(a [n.a l.b m.b]) [n.b r.b m.a]) + (toy [n.a l.b m.b] $(a [n.b r.b m.a])) + :: + %llos + =/ b=lnode p.t.a + ?: |(=(k m.b) (gor k m.b)) + (toy $(a [n.b l.b m.b]) [n.a r.b m.a]) + (toy [n.b l.b m.b] $(a [n.a r.b m.a])) + == + :: + ++ dew :: delete view + ~/ %dew + |= [a=pro =k] + |- ^- (unit (trel @ v pro)) + ?~ a ~ + ?~ t.a + ?. =(k k.n.a) ~ + `[p.n.a v.n.a ~] + ?- -.t.a + %llos + =/ b=lnode p.t.a + ?: |(=(k m.b) (gor k m.b)) + =/ pat $(a [n.b l.b m.b]) + ?~ pat ~ + %- some + :+ p.u.pat q.u.pat + (toy r.u.pat [n.a r.b m.a]) + =/ pat $(a [n.a r.b m.a]) + ?~ pat ~ + %- some + :+ p.u.pat q.u.pat + (toy [n.b l.b m.b] r.u.pat) + :: + %rlos + =/ b=lnode p.t.a + ?: |(=(k m.b) (gor k m.b)) + =/ pat $(a [n.a l.b m.b]) + ?~ pat ~ + %- some + :+ p.u.pat q.u.pat + (toy r.u.pat [n.b r.b m.a]) + =/ pat $(a [n.b r.b m.a]) + ?~ pat ~ + %- some + :+ p.u.pat q.u.pat + (toy [n.a l.b m.b] r.u.pat) + == + :: + ++ bot :: lowest-pro view + ~/ %bot + |= a=pro + ^- (unit (trel k @ buc)) + ?~ a ~ + `[k.n.a p.n.a v.n.a (sec t.a m.a)] + -- + :: radix tree logic + :: + ++ qat + ~% %qat ..qat ~ + |% + :: + ++ del :: delete at key k + ~/ %del + |= [a=pri k=k] + |- ^- pri + ?~ a ~ + ?- -.a + %tip + ?: =(k k.a) ~ + a + :: + %bin + ?: (feud m.a k k.a) + a + ?: =((mug k) (mug k.a)) + (fuse m.a l.a r.a) + ?: (zero m.a k) + (funk k.a p.a v.a m.a $(a l.a) r.a) + (wane k.a p.a v.a m.a l.a $(a r.a)) + == + :: + ++ dew :: delete view + ~/ %dew + |= [a=pri =k] + ^- (unit (qual _k @ buc pri)) + =- ?~ p.- ~ + `[p.u.p.- q.u.p.- r.u.p.- q.-] + |- ^- (pair (unit (trel _k @ buc)) pri) + ?~ a [~ ~] + ?- -.a + %tip + ?. =((mug k) (mug k.a)) + [~ a] + [`[k.a p.a v.a] ~] + :: + %bin + ?: (feud m.a k k.a) + [~ a] + ?: =((mug k) (mug k.a)) + :- `[k.a p.a v.a] + (fuse m.a l.a r.a) + ?: (zero m.a k) + =/ mud $(a l.a) + :- p.mud + (funk k.a p.a v.a m.a q.mud r.a) + =/ mud $(a r.a) + :- p.mud + (wane k.a p.a v.a m.a l.a q.mud) + == + :: + ++ raw :: raw insert + ~/ %raw :: + |= [a=pri k=k p=@ v=buc] :: k must not exist in + ^- pri :: queue + ?~ a [%tip k p v] + ?- -.a + %tip + ?: (lex p k p.a k.a) + (rule k p v a ~) + (rule k.a p.a v.a [%tip k p v] ~) + :: + %bin + ?: (feud m.a k k.a) + ?: (lex p k p.a k.a) + (rule k p v a ~) + (rule k.a p.a v.a [%tip k p v] (fuse m.a l.a r.a)) + :- %bin + ?: (lex p k p.a k.a) + ?: (zero m.a k.a) + [k p v m.a $(a l.a, k k.a, p p.a, v v.a) r.a] + [k p v m.a l.a $(a r.a, k k.a, p p.a, v v.a)] + ?: (zero m.a k) + [k.a p.a v.a m.a $(a l.a) r.a] + [k.a p.a v.a m.a l.a $(a r.a)] + == + :: + ++ put :: insert + ~/ %put + |= [a=pri k=k p=@ v=buc] + ^- pri + (raw (del a k) k p v) + :: + ++ gas :: concatenate + ~/ %gas + |= [a=pri b=(list (trel k @ buc))] + |- ^- pri + ?~ b a + $(b t.b, a (put a p.i.b q.i.b r.i.b)) + -- + :: pri logic + :: + ++ wyt :: queue size + |= a=pri + ^- @ + %+ rep a + |=([[k @ buc] @] +((add +<+ (wyt:qor t.+<->+)))) + :: + ++ get :: lookup + ~/ %get + |= [a=pri =k] + |- ^- (unit (pair @ v)) + ?~ a ~ + ?- -.a + %tip + ?. =((mug k) (mug k.a)) ~ + ?: =(k k.a) + `[p.a v.v.a] + (get:qor t.v.a k) + :: + %bin + ?: (feud m.a k k.a) ~ + ?: =((mug k) (mug k.a)) + ?: =(k k.a) + `[p.a v.v.a] + (get:qor t.v.a k) + ?: (zero m.a k) + $(a l.a) + $(a r.a) + == + :: + ++ has :: contains + |= [a=pri =k] + ^- ? + !=(~ (get a k)) + :: + ++ put :: insert + ~/ %put + |= [a=pri =k p=@ =v] + ^- pri + ?~ ded=(dew:qat a k) + (raw:qat a k p v ~) + =/ val u.ded + =. a s.val + %+ raw:qat a + ?: =(k p.val) + (sink:qor t.r.val k p v) + ?: |((lth q.val p) &(=(p q.val) (gor p.val k))) + [p.val q.val v.r.val (put:qor t.r.val k p v)] + :^ k p v + ?: (has:qor t.r.val k) + (put:qor (del:qor t.r.val k) p.val q.val v.r.val) + (put:qor t.r.val p.val q.val v.r.val) + :: + ++ del :: remove + ~/ %del + |= [a=pri =k] + ^- pri + ?~ ded=(dew:qat a k) a + =/ val u.ded + =. a s.val + ?: =(k p.val) + ?~ low=(bot:qor t.r.val) a + (raw:qat a u.low) + (raw:qat a p.val q.val v.r.val (del:qor t.r.val k)) + :: + ++ dew :: delete view + ~/ %dew + |= [a=pri =k] + ^- (unit (trel @ v pri)) + ?~ ded=(dew:qat a k) ~ + =/ val u.ded + =. a s.val + ?: =(k p.val) + %- some + :+ q.val v.r.val + ?~ low=(bot:qor t.r.val) a + (raw:qat a u.low) + ?~ low=(dew:qor t.r.val k) ~ + %- some + :+ p.u.low q.u.low + (raw:qat a p.val q.val v.r.val r.u.low) + :: + ++ gas :: concatenate + |= [a=pri b=(list (trel k @ v))] + |- ^- pri + ?~ b a + $(b t.b, a (put a p.i.b q.i.b r.i.b)) + :: + ++ bot :: min-priority view + ~/ %bot + |= a=pri + ^- (unit (qual k @ v pri)) + ?~ a ~ + %- some + ?- -.a + %tip [k.a p.a v.v.a (cut a)] + %bin [k.a p.a v.v.a (cut a)] + == + :: + ++ sam :: equality + |= [a=pri b=pri] + ^- ? + =/ loa (bot a) + =/ lob (bot b) + ?| &(=(~ loa) =(~ lob)) + !&(=(~ loa) !=(~ lob)) + !&(!=(~ loa) =(~ lob)) + ?> &(?=(^ loa) ?=(^ lob)) + ?& =(p.u.loa p.u.lob) + =(q.u.loa q.u.lob) + =(r.u.loa r.u.lob) + $(a s.u.loa, b s.u.lob) + == + == + :: + ++ key :: list of keys + |= a=pri + ^- (list k) + %+ turn `(list (trel k @ v))`(tap a) + |=([k @ v] +<-) + :: + ++ tap :: convert to list + |= a=pri + =| acc=(list (trel k @ buc)) + =/ lis + |- ^+ acc + ?~ a acc + ?- -.a + %tip [[k.a p.a v.a] acc] + %bin [[k.a p.a v.a] $(acc $(a r.a), a l.a)] + == + =| acc=(list (trel k @ v)) + |- ^+ acc + ?~ lis acc + =/ hed i.lis + =/ res (tap:qor t.r.hed) + =. acc (weld res acc) + $(lis t.lis, acc [[p.hed q.hed v.r.hed] acc]) + :: + ++ rep :: fold + |* [a=pri f=_=>(buc |=([[* @ buc] *] +<+))] + |- + ?~ a +<+.f + ?- -.a + %tip (f [k.a p.a v.a] +<+.f) + %bin $(a r.a, +<+.f $(a l.a, +<+.f (f [k.a p.a v.a] +<+.f))) + == + :: + ++ cut :: delete min-pri + ~/ %cut + |= a=pri + ^- pri + ?~ a ~ + ?- -.a + %tip + ?~ hol=(bot:qor t.v.a) ~ + [%tip u.hol] + :: + %bin + ?~ hol=(bot:qor t.v.a) (fuse m.a l.a r.a) + (raw:qat (fuse m.a l.a r.a) u.hol) + == + :: + ++ vip :: very important put + ~/ %vip :: + |= [a=pri k=k p=@ =v] :: p must be higher + ^- (pair (unit (pair @ _v)) pri) :: than resident max + ?~ a + [~ [%tip k p v ~]] + ?- -.a + %tip + ?: =((mug k) (mug k.a)) + ?: =(k k.a) + :- `[p.a v.v.a] + [%tip (sink:qor t.v.a k p v)] + :- (get:qor t.v.a k) + [%tip k.a p.a v.v.a (put:qor t.v.a k p v)] + [~ (rule k.a p.a v.a [%tip k p v ~] ~)] + :: + %bin + ?: (feud m.a k k.a) + [~ (rule k.a p.a v.a [%tip k p v ~] (fuse m.a l.a r.a))] + ?: =((mug k) (mug k.a)) + ?: =(k k.a) + :- `[p.a v.v.a] + =/ val (sink:qor t.v.a k p v) + ?: (zero m.a p.val) + (fuse m.a (raw:qat l.a val) r.a) + (fuse m.a l.a (raw:qat r.a val)) + :- (get:qor t.v.a k) + [%bin k.a p.a [v.v.a (put:qor t.v.a k p v)] m.a l.a r.a] + ?: (zero m.a k) + =/ val $(a l.a) + :- p.val + [%bin k.a p.a v.a m.a q.val r.a] + =/ val $(a r.a) + :- p.val + [%bin k.a p.a v.a m.a l.a q.val] + == + :: + ++ see :: get with pri bump + ~/ %see :: + |= [a=pri =k p=@] :: p must be higher + |^ ^- (pair (unit (pair @ v)) pri) :: than resident max + ?~ a [~ ~] + ?- -.a + %tip + ?. =((mug k) (mug k.a)) + [~ a] + =/ mud (stir k.a p.a v.a) + :- p.mud + [%tip q.mud r.mud s.mud] + :: + %bin + ?: (feud m.a k k.a) + [~ a] + ?: =((mug k) (mug k.a)) + =/ mud (stir k.a p.a v.a) + :- p.mud + ?: (zero m.a k) + (fuse m.a (raw:qat l.a q.mud r.mud s.mud) r.a) + (fuse m.a l.a (raw:qat r.a q.mud r.mud s.mud)) + ?: (zero m.a k) + =/ val $(a l.a) + :- p.val + [%bin k.a p.a v.a m.a q.val r.a] + =/ val $(a r.a) + :- p.val + [%bin k.a p.a v.a m.a l.a q.val] + == + :: + ++ stir + |= [l=_k q=@ =buc] + ^- (qual (unit (pair @ v)) _k @ _buc) + ?: =(k l) + :- `[q v.buc] + (sink:qor t.buc l p v.buc) + ?~ val=(get:qor t.buc k) [~ l q buc] + :^ val l q + [v.buc (put:qor t.buc k p q.u.val)] + -- + -- +:: +++ lu :: lru cache engine + ~/ %lu + |* [k=mold v=mold] + :: + ~% %core + ~ + |% + :: + +$ pes [cap=_`@`10.000 siz=@ tic=@ pri=pri:psq] :: lru cache + :: + ++ psq (up k v) + :: + ++ new :: new cache + ~/ %new + |= cap=@ + ^- pes + [cap 0 0 ~] + :: + ++ ebb :: trim cache + ~/ %ebb + |= a=pes + ?: (gte tic.a 0x7fff.ffff) + (new cap.a) + ?: (gth siz.a cap.a) + a(siz (dec siz.a), pri (cut:psq pri.a)) + a + :: + ++ put :: insert + ~/ %put + |= [a=pes =k =v] + ^- pes + =/ vue (vip:psq pri.a k tic.a v) + %- ebb + %_ a + siz ?~(p.vue +(siz.a) siz.a) + tic +(tic.a) + pri q.vue + == + :: + ++ get :: lookup w/pri bump + ~/ %get + |= [a=pes =k] + ^- (unit (pair v pes)) + =/ val (see:psq pri.a k tic.a) + ?~ p.val ~ + %- some + :- q.u.p.val + %- ebb + %_ a + tic +(tic.a) + pri q.val + == + :: + ++ del :: remove + ~/ %del + |= [a=pes =k] + ^- pes + ?~ ded=(dew:psq pri.a k) a + %_ a + siz (dec siz.a) + pri r.u.ded + == + :: + ++ gas :: concatenate + |= [a=pes b=(list (pair k v))] + ^- pes + ?~ b a + $(b t.b, a (put a p.i.b q.i.b)) + :: + ++ tap :: to list + |= a=pes + ^- (list (trel k @ v)) + (tap:psq pri.a) + :: + ++ key :: list of keys + |= a=pes + ^- (list k) + (key:psq pri.a) + -- +--