up

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

lu_get.c (781B)


      1 #include "all.h"
      2 
      3 u3_noun
      4 u3qdl_get(u3_noun a, u3_noun k)
      5 {
      6   u3_noun cap_a, siz_a, tic_a, pri_a;
      7   u3x_qual(a, &cap_a, &siz_a, &tic_a, &pri_a);
      8 
      9   u3_noun val = u3qdu_see(pri_a, k, tic_a);
     10 
     11   u3_noun pv, qv;
     12   u3x_cell(val, &pv, &qv);
     13 
     14   if (u3_nul == pv) {
     15     u3z(val);
     16 
     17     return u3_nul;
     18   }
     19   else {
     20     u3_noun ppv, qpv;
     21     u3x_cell(u3t(pv), &ppv, &qpv);
     22 
     23     u3_noun pru = u3nq(u3k(cap_a), u3k(siz_a), u3qa_inc(tic_a), u3k(qv));
     24     u3_noun pre = u3kdl_ebb(pru);
     25     u3_noun pro = u3nt(u3_nul, u3k(qpv), pre);
     26 
     27     u3z(val);
     28 
     29     return pro;
     30   }
     31 }
     32 
     33 u3_noun
     34 u3wdl_get(u3_noun cor)
     35 {
     36   u3_noun a, k;
     37 
     38   if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &k, 0)) ||
     39        (c3n == u3du(a)) )
     40   {
     41     return u3m_bail(c3__exit);
     42   } else {
     43     return u3qdl_get(a, k);
     44   }
     45 }
     46