Esempio n. 1
0
void avl_check_balance(TREE *tree)
{
   if (tree->root) {
      assert( !IS_DEEPER(tree->root));
      if (IS_X(tree)) depth_x(tree->x_root, true);
      else            depth_l(tree->l_root, true);
   }
}
Esempio n. 2
0
int avl_depth(TREE *tree)
{
   if (tree->root) {
      if (IS_X(tree)) return depth_x(tree->x_root, false);
      else            return depth_l(tree->l_root, false);
   } else {
      return 0;
   }
}
Esempio n. 3
0
void avl_dump_w_ctx(TREE *tree, void (*callback)(void *data, int idx, int bal, void *context), void *context)
{
   if (tree->root) {
      int    max_depth = 0;
      int    idx, idx_top;
      void **data_v;
      int   *bal_v;

      if (IS_X(tree)) max_depth = depth_x(PTR_OF(tree->x_root), false);
      else            max_depth = depth_l(PTR_OF(tree->l_root), false);
      idx_top = 1 << max_depth;
      data_v = calloc(idx_top, sizeof(void*));
      bal_v  = calloc(idx_top, sizeof(int));
      if (IS_X(tree)) prepare_for_dump_x(PTR_OF(tree->x_root), 1, data_v, bal_v);
      else            prepare_for_dump_l(PTR_OF(tree->l_root), 1, data_v, bal_v);
      for (idx = 1; idx < idx_top; idx++) {
         (*callback)(data_v[idx], idx, bal_v[idx], context);
      }
      free(data_v);
      free(bal_v);
   } else {
      (*callback)(NULL, 1, 0, context);
   }
}
Esempio n. 4
0
/************************************************************************
 * GETNUM - Get a number from the input stream.
 *
 * ARGUMENTS
 *      radix - the radix of the number to be accumulated.  Can only be 8, 10,
 *                      or 16
 *      pval - a pointer to a VALUE union to be filled in with the value
 *
 * RETURNS - type of the token (L_CINTEGER or L_CFLOAT)
 *
 * SIDE EFFECTS -
 *      does push back on the input stream.
 *      writes into pval by reference
 *  uses buffer Reuse_W
 *
 * DESCRIPTION -
 *      Accumulate the number according to the rules for each radix.
 *      Set up the format string according to the radix (or distinguish
 *      integer from float if radix is 10) and convert to binary.
 *
 * AUTHOR - Ralph Ryan, Sept. 8, 1982
 *
 * MODIFICATIONS - none
 *
 ************************************************************************/
token_t getnum(REG      WCHAR           c)
{
    REG WCHAR   *p;
    WCHAR       *start;
    int         radix;
    token_t     tok;
    value_t     value;

    tok = L_CINTEGER;
    start = (Tiny_lexer_nesting ? Exp_ptr : Reuse_W);
    p = start;
    if( c == L'0' ) {
        c = get_non_eof();
        if( IS_X(c) ) {
            radix = 16;
            if( Prep ) {
                *p++ = L'0';
                *p++ = L'x';
            }
            for(c = get_non_eof(); LXC_IS_XDIGIT(c); c = get_non_eof()) {
                /* no check for overflow? */
                *p++ = c;
            }
            if((p == Reuse_W) && (Tiny_lexer_nesting == 0)) {
                strcpy (Msg_Text, GET_MSG (2153));
                error(2153);
            }
            goto check_suffix;
        }
        else {
            radix = 8;
            *p++ = L'0'; /* for preprocessing or 0.xxx case */
        }
    }
    else {
        radix = 10;
    }

    while( LXC_IS_DIGIT((WCHAR)c) ) {
        *p++ = c;
        c = get_non_eof();
    }

    if( IS_DOT(c) || IS_E(c) ) {
        UNGETCH();
        return(get_real(p));
    }

check_suffix:
    if( IS_EL(c) ) {
        if( Prep ) {
            *p++ = c;
        }
        c = get_non_eof();
        if( IS_U(c) ) {
            if(Prep) {
                *p++ = c;
            }
            tok = L_LONGUNSIGNED;
        }
        else {
            tok = L_LONGINT;
            UNGETCH();
        }
    }
    else if( IS_U(c) ) {
        if( Prep ) {
            *p++ = c;
        }
        c = get_non_eof();
        if( IS_EL(c) ) {
            if( Prep ) {
                *p++ = c;
            }
            tok = L_LONGUNSIGNED;
        }
        else {
            tok = L_CUNSIGNED;
            UNGETCH();
        }
    }
    else {
        UNGETCH();
    }
    *p = L'\0';
    if( start == Exp_ptr ) {
        Exp_ptr = p;
        return(L_NOTOKEN);
    }
    else if( Prep ) {
        myfwrite( Reuse_W, (size_t)(p - Reuse_W) * sizeof(WCHAR), 1, OUTPUTFILE);
        return(L_NOTOKEN);
    }
    value.v_long = matol(Reuse_W,radix);
    switch(tok) {
    case L_CINTEGER:
        tok = (radix == 10)
            ? c_size(value.v_long)
            : uc_size(value.v_long)
            ;
        break;
    case L_LONGINT:
        tok = l_size(value.v_long);
        break;
    case L_CUNSIGNED:
        tok = ul_size(value.v_long);
        break;
    }
    yylval.yy_tree = build_const(tok, &value);
    return(tok);
}