up

A priority search queue and LRU cache.
git clone git://git.jtobin.io/up.git
Log | Files | Refs

up_qat_raw.c (2429B)


      1 #include "all.h"
      2 
      3 u3_noun
      4 u3qdu_qat_raw(u3_noun a, u3_noun k, u3_noun p, u3_noun v)
      5 {
      6   if (u3_nul == a) {
      7     return u3nq(c3__tip, u3k(k), u3k(p), u3k(v));
      8   }
      9 
     10   u3_noun hoc = u3h(a);
     11 
     12   if (c3n == u3ud(hoc)) {
     13     return u3m_bail(c3__exit);
     14   }
     15   else switch ( hoc ) {
     16     default:
     17       return u3m_bail(c3__exit);
     18 
     19     case c3__tip: {
     20       u3_noun ka, pa, va;
     21       u3x_trel(u3t(a), &ka, &pa, &va);
     22 
     23       if (c3y == u3qdu_lex(p, k, pa, ka)) {
     24         return u3qdu_rule(k, p, v, a, u3_nul);
     25       }
     26       else
     27       {
     28         u3_noun rec = u3nq(c3__tip, u3k(k), u3k(p), u3k(v));
     29         u3_noun pro = u3qdu_rule(ka, pa, va, rec, u3_nul);
     30 
     31         u3z(rec);
     32 
     33         return pro;
     34       }
     35     }
     36 
     37     case c3__bin: {
     38       u3_noun ka, pa, va;
     39       u3_noun ta, ma, la, ra;
     40       u3x_qual(u3t(a), &ka, &pa, &va, &ta);
     41       u3x_trel(ta, &ma, &la, &ra);
     42 
     43       if (c3y == u3qdu_feud(ma, k, ka)) {
     44         if (c3y == u3qdu_lex(p, k, pa, ka)) {
     45           return u3qdu_rule(k, p, v, a, u3_nul);
     46         }
     47         else {
     48           u3_noun rec = u3nq(c3__tip, u3k(k), u3k(p), u3k(v));
     49           u3_noun rev = u3qdu_fuse(ma, la, ra);
     50           u3_noun pro = u3qdu_rule(ka, pa, va, rec, rev);
     51 
     52           u3z(rec);
     53           u3z(rev);
     54 
     55           return pro;
     56         }
     57       }
     58       else if (c3y == u3qdu_lex(p, k, pa, ka)) {
     59         if (c3y == u3qdu_zero(ma, ka)) {
     60           u3_noun rev = u3qdu_qat_raw(la, ka, pa, va);
     61           return u3nq(c3__bin, u3k(k), u3k(p),
     62                      u3nq(u3k(v), u3k(ma), rev, u3k(ra)));
     63         }
     64         else
     65         {
     66           u3_noun rev = u3qdu_qat_raw(ra, ka, pa, va);
     67           return u3nq(c3__bin, u3k(k), u3k(p),
     68                      u3nq(u3k(v), u3k(ma), u3k(la), rev));
     69         }
     70       }
     71       else if (c3y == u3qdu_zero(ma, k)) {
     72         u3_noun rev = u3qdu_qat_raw(la, k, p, v);
     73         return u3nq(c3__bin, u3k(ka), u3k(pa),
     74                   u3nq(u3k(va), u3k(ma), rev, u3k(ra)));
     75       }
     76       else
     77       {
     78         u3_noun rev = u3qdu_qat_raw(ra, k, p, v);
     79         return u3nq(c3__bin, u3k(ka), u3k(pa),
     80                   u3nq(u3k(va), u3k(ma), u3k(la), rev));
     81       }
     82     }
     83   }
     84 }
     85 
     86 u3_noun
     87 u3wdu_qat_raw(u3_noun cor)
     88 {
     89   u3_noun a, k, p, v;
     90 
     91   if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &k, u3x_sam_14, &p,
     92                         u3x_sam_15, &v, 0)) ||
     93        (c3n == u3ud(p)) )
     94   {
     95     return u3m_bail(c3__exit);
     96   } else {
     97     return u3qdu_qat_raw(a, k, p, v);
     98   }
     99 }
    100 
    101