up

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

up_qor_get.c (1404B)


      1 #include "all.h"
      2 
      3 u3_noun
      4 u3qdu_qor_get(u3_noun a, u3_noun k)
      5 {
      6   if (u3_nul == a) {
      7     return u3_nul;
      8   }
      9 
     10   u3_noun tor = u3qdu_qor_see(a);
     11 
     12   if (u3_nul == tor) {
     13     return u3_nul;
     14   }
     15 
     16   u3_noun hot = u3h(tor);
     17 
     18   if (c3n == u3ud(hot)) {
     19     return u3m_bail(c3__exit);
     20   }
     21   else switch ( hot ) {
     22     default:
     23       return u3m_bail(c3__exit);
     24 
     25     case c3__sing: {
     26       u3_noun n_tor = u3t(tor);
     27 
     28       u3_noun kn_tor, pn_tor, vn_tor;
     29       u3x_trel(n_tor, &kn_tor, &pn_tor, &vn_tor);
     30 
     31       if (c3n == u3r_sing(k, kn_tor)) {
     32         u3z(tor);
     33         return u3_nul;
     34       }
     35       else {
     36         u3_noun pro = u3nt(u3_nul, u3k(pn_tor), u3k(vn_tor));
     37 
     38         u3z(tor);
     39 
     40         return pro;
     41       }
     42     }
     43 
     44     case c3__play: {
     45       u3_noun l_tor, r_tor;
     46       u3x_cell(u3t(tor), &l_tor, &r_tor);
     47 
     48       if (u3_nul == l_tor) {
     49         return u3m_bail(c3__exit);
     50       }
     51 
     52       u3_noun lop = u3t(u3t(l_tor));
     53 
     54       if ( (c3y == u3r_sing(k, lop)) || (c3y == u3qc_gor(k, lop)) ) {
     55         u3_noun pro = u3qdu_qor_get(l_tor, k);
     56 
     57         u3z(tor);
     58 
     59         return pro;
     60       }
     61       else {
     62         u3_noun pro = u3qdu_qor_get(r_tor, k);
     63 
     64         u3z(tor);
     65 
     66         return pro;
     67       }
     68 
     69     }
     70   }
     71 }
     72 
     73 u3_noun
     74 u3wdu_qor_get(u3_noun cor)
     75 {
     76   u3_noun a, k;
     77 
     78   if (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &k, 0))
     79   {
     80     return u3m_bail(c3__exit);
     81   } else {
     82     return u3qdu_qor_get(a, k);
     83   }
     84 }
     85 
     86 
     87