up

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

lu_put.c (711B)


      1 #include "all.h"
      2 
      3 u3_noun
      4 u3qdl_put(u3_noun a, u3_noun k, u3_noun v)
      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 vue = u3qdu_vip(pri_a, k, tic_a, v);
     10 
     11   u3_noun pv, qv;
     12   u3x_cell(vue, &pv, &qv);
     13 
     14   u3_noun siz = (u3_nul == pv) ? u3qa_inc(siz_a) : u3k(siz_a);
     15 
     16   u3_noun pre = u3nq(u3k(cap_a), siz, u3qa_inc(tic_a), u3k(qv));
     17   u3_noun pro = u3kdl_ebb(pre);
     18 
     19   u3z(vue);
     20 
     21   return pro;
     22 }
     23 
     24 u3_noun
     25 u3wdl_put(u3_noun cor)
     26 {
     27   u3_noun a, k, v;
     28 
     29   if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6,
     30                         &k, u3x_sam_7, &v, 0)) ||
     31        (c3n == u3du(a)) )
     32   {
     33     return u3m_bail(c3__exit);
     34   } else {
     35     return u3qdl_put(a, k, v);
     36   }
     37 }
     38