up

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

up_qor_rlsin.c (1167B)


      1 #include "all.h"
      2 
      3 u3_noun
      4 u3qdu_qor_rlsin(u3_noun n_a, u3_noun l_a, u3_noun m_a, u3_noun r_a)
      5 {
      6   if ( c3n == u3du(r_a) ) {
      7     return u3m_bail(c3__exit);
      8   }
      9 
     10   u3_noun b = u3t(u3t(r_a));
     11 
     12   u3_noun n_b, l_b, m_b, r_b;
     13   u3x_qual(b, &n_b, &l_b, &m_b, &r_b);
     14 
     15   u3_noun hor = u3h(r_a);
     16 
     17   if ( c3n == u3ud(hor) ) {
     18     return u3m_bail(c3__exit);
     19   }
     20   else switch ( hor ) {
     21     default:
     22       return u3m_bail(c3__exit);
     23 
     24     case c3__llos: {
     25       u3_noun pre = u3qdu_qor_rlos(n_b, l_a, m_a, l_b);
     26       u3_noun pro = u3qdu_qor_rlos(n_a, pre, m_b, r_b);
     27 
     28       u3z(pre);
     29 
     30       return pro;
     31     }
     32 
     33     case c3__rlos: {
     34       u3_noun pre = u3qdu_qor_rlos(n_a, l_a, m_a, l_b);
     35       u3_noun pro = u3qdu_qor_rlos(n_b, pre, m_b, r_b);
     36 
     37       u3z(pre);
     38 
     39       return pro;
     40     }
     41   }
     42 }
     43 
     44 u3_noun
     45 u3wdu_qor_rlsin(u3_noun cor)
     46 {
     47   u3_noun a;
     48 
     49   if ( (c3n == u3r_mean(cor, u3x_sam, &a, 0 )) ||
     50        (c3n == u3du(a)) )
     51   {
     52     return u3m_bail(c3__exit);
     53   } else {
     54     u3_noun n, l, m, r;
     55     u3x_qual(a, &n, &l, &m, &r);
     56 
     57     if ( (c3n == u3du(n)) || (c3n == u3ud(m)) ) {
     58       return u3m_bail(c3__exit);
     59     }
     60     else {
     61       return u3qdu_qor_rlsin(n, l, m, r);
     62     }
     63   }
     64 }
     65