up

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

up_qor_rlos.c (709B)


      1 #include "all.h"
      2 
      3 u3_noun
      4 u3qdu_qor_rlos(u3_noun n, u3_noun l, u3_atom m, u3_noun r)
      5 {
      6   u3_atom sl = u3qdu_qor_size(l);
      7   u3_atom sr = u3qdu_qor_size(r);
      8   u3_atom s  = u3qa_add(sl, sr);
      9 
     10   u3_noun pro = u3qa_inc(s);
     11 
     12   u3z(sl);
     13   u3z(sr);
     14   u3z(s);
     15 
     16   return u3nt(c3__rlos, pro, u3nq(u3k(n), u3k(l), u3k(m), u3k(r)));
     17 }
     18 
     19 u3_noun
     20 u3wdu_qor_rlos(u3_noun cor)
     21 {
     22   u3_noun a;
     23 
     24   if ( (c3n == u3r_mean(cor, u3x_sam, &a, 0)) ||
     25        (c3n == u3du(a)) )
     26   {
     27     return u3m_bail(c3__exit);
     28   } else {
     29     u3_noun n, l, m, r;
     30 
     31     u3x_qual(a, &n, &l, &m, &r);
     32 
     33     if ( (c3n == u3du(n)) || (c3n == u3ud(m)) ) {
     34       return u3m_bail(c3__exit);
     35     }
     36     else {
     37       return u3qdu_qor_rlos(n, l, m, r);
     38     }
     39   }
     40 }
     41