pike.git / src / rbtree.c

version» Context lines:

pike.git/src/rbtree.c:1:   /* An implementation of a threaded red/black balanced binary tree.    *    * Created 2001-04-27 by Martin Stjernholm    * -  * $Id: rbtree.c,v 1.3 2001/05/01 07:52:19 mast Exp $ +  * $Id: rbtree.c,v 1.4 2001/05/01 21:37:56 grubba Exp $    */      #include "global.h"   #include "constants.h"   #include "builtin_functions.h"   #include "interpret.h"   #include "mapping.h"   #include "pike_error.h"   #include "svalue.h"   #include "rbtree.h"
pike.git/src/rbtree.c:34:    __FILE__, __LINE__), debug_rb_indval_fatal)      #endif      #define HDR(node) ((struct rb_node_hdr *) (node))      /* The default compare function for ind and indval. */   PMOD_EXPORT int rb_ind_default_cmp (struct svalue *key, union rb_node *node)   {    struct svalue tmp; -  return set_svalue_cmpfun (key, &use_rb_node_ind (&(node->i), tmp)); +  use_rb_node_ind (&(node->i), tmp); +  return set_svalue_cmpfun (key, &tmp);   }      struct svalue_cmp_data   {    struct svalue *key, *cmp_less;   };      static int svalue_cmp_eq (struct svalue_cmp_data *data, union rb_node *node)   {    int cmp_res;    struct svalue tmp;    push_svalue (data->key); -  push_svalue (&use_rb_node_ind (&(node->i), tmp)); +  use_rb_node_ind (&(node->i), tmp); +  push_svalue (&tmp);    apply_svalue (data->cmp_less, 2);    if (IS_ZERO (sp - 1))    cmp_res = !is_eq (data->key, &tmp);    else    cmp_res = -1;    pop_stack();    return cmp_res;   }      /* Considers equal as greater. */   static int svalue_cmp_ge (struct svalue_cmp_data *data, union rb_node *node)   {    int cmp_res;    struct svalue tmp;    push_svalue (data->key); -  push_svalue (&use_rb_node_ind (&(node->i), tmp)); +  use_rb_node_ind (&(node->i), tmp); +  push_svalue (&tmp);    apply_svalue (data->cmp_less, 2);    cmp_res = IS_ZERO (sp - 1) ? 1 : -1;    pop_stack();    return cmp_res;   }      /* Considers equal as less. */   static int svalue_cmp_le (struct svalue_cmp_data *data, union rb_node *node)   {    int cmp_res;    struct svalue tmp; -  push_svalue (&use_rb_node_ind (&(node->i), tmp)); +  use_rb_node_ind (&(node->i), tmp); +  push_svalue (&tmp);    push_svalue (data->key);    apply_svalue (data->cmp_less, 2);    cmp_res = IS_ZERO (sp - 1) ? -1 : 1;    pop_stack();    return cmp_res;   }      /* Functions for handling nodes with index only. */      BLOCK_ALLOC (rb_node_ind, 1024)
pike.git/src/rbtree.c:118:    node = alloc_rb_node_ind();    assign_svalue_no_free (&node->ind, ind);    DO_IF_DEBUG (node->ind.type |= RB_FLAG_MARKER);    }, { /* Replace. */    node = 0;    });    }       else {    LOW_RB_INSERT ((struct rb_node_hdr **) tree, HDR (node), { /* Compare. */ -  cmp_res = set_svalue_cmpfun (ind, &use_rb_node_ind (node, tmp)); +  use_rb_node_ind (node, tmp); +  cmp_res = set_svalue_cmpfun (ind, &tmp);    }, { /* Insert. */    node = alloc_rb_node_ind();    assign_svalue_no_free (&node->ind, ind);    DO_IF_DEBUG (node->ind.type |= RB_FLAG_MARKER);    }, { /* Replace. */    node = 0;    });    }       return node;
pike.git/src/rbtree.c:174:    HDR (old) = low_rb_delete ((struct rb_node_hdr **) tree,    (low_rb_cmp_fn *) svalue_cmp_eq, &data,    (low_rb_move_data_fn *) move_ind_data);    }    else    HDR (old) = low_rb_delete ((struct rb_node_hdr **) tree,    (low_rb_cmp_fn *) rb_ind_default_cmp, ind,    (low_rb_move_data_fn *) move_ind_data);    if (old) {    struct svalue tmp; -  free_svalue (&use_rb_node_ind (old, tmp)); +  use_rb_node_ind (old, tmp); +  free_svalue (&tmp);    really_free_rb_node_ind (old);    return 1;    }    return 0;   }      static struct rb_node_ind *copy_ind_node (struct rb_node_ind *node)   {    struct rb_node_ind *new = alloc_rb_node_ind();    struct svalue tmp; -  assign_svalue_no_free (&new->ind, &use_rb_node_ind (node, tmp)); +  use_rb_node_ind (node, tmp); +  assign_svalue_no_free (&new->ind, &tmp);    DO_IF_DEBUG (new->ind.type |= RB_FLAG_MARKER);    return new;   }      PMOD_EXPORT struct rb_node_ind *rb_ind_copy (struct rb_node_ind *tree)   {    return (struct rb_node_ind *)    low_rb_copy (HDR (tree), (low_rb_copy_fn *) copy_ind_node);   }   
pike.git/src/rbtree.c:245:    assign_svalue_no_free (&node->ind, ind);    assign_svalue_no_free (&node->val, val);    DO_IF_DEBUG (node->ind.type |= RB_FLAG_MARKER);    }, { /* Replace. */    node = 0;    });    }       else {    LOW_RB_INSERT ((struct rb_node_hdr **) tree, HDR (node), { /* Compare. */ -  cmp_res = set_svalue_cmpfun (ind, &use_rb_node_ind (node, tmp)); +  use_rb_node_ind (node, tmp); +  cmp_res = set_svalue_cmpfun (ind, &tmp);    }, { /* Insert. */    node = alloc_rb_node_indval();    assign_svalue_no_free (&node->ind, ind);    assign_svalue_no_free (&node->val, val);    DO_IF_DEBUG (node->ind.type |= RB_FLAG_MARKER);    }, { /* Replace. */    node = 0;    });    }   
pike.git/src/rbtree.c:319:    if (IS_ZERO (sp - 1)) \    cmp = !is_eq (a, b); \    else \    cmp = -1; \    pop_stack(); \    } \    else cmp = set_svalue_cmpfun (a, b); \    } while (0)       if (node) { -  DO_CMP (ind, &use_rb_node_ind (node, tmp), cmp1); +  use_rb_node_ind (node, tmp); +  DO_CMP (ind, &tmp, cmp1);    tmpnode = rb_indval_next (node); -  if (tmpnode) DO_CMP (ind, &use_rb_node_ind (tmpnode, tmp), cmp2); +  if (tmpnode) { +  use_rb_node_ind (tmpnode, tmp); +  DO_CMP (ind, &tmp, cmp2); +  }    else cmp2 = -1;    if (cmp1 < 0 || cmp2 > 0)    fatal ("Adding at this position would break the order.\n");    }    else { -  DO_CMP (ind, &use_rb_node_ind (rb_indval_first (*tree), tmp), cmp1); +  use_rb_node_ind (rb_indval_first (*tree), tmp); +  DO_CMP (ind, &tmp, cmp1);    if (cmp1 > 0) fatal ("Adding at beginning would break the order.\n");    }   #undef DO_CMP    }   #endif       if (cmp_less) {    struct svalue_cmp_data data;    data.cmp_less = cmp_less;    data.key = ind;
pike.git/src/rbtree.c:368:    HDR (old) = low_rb_delete ((struct rb_node_hdr **) tree,    (low_rb_cmp_fn *) svalue_cmp_eq, &data,    (low_rb_move_data_fn *) move_indval_data);    }    else    HDR (old) = low_rb_delete ((struct rb_node_hdr **) tree,    (low_rb_cmp_fn *) rb_ind_default_cmp, ind,    (low_rb_move_data_fn *) move_indval_data);    if (old) {    struct svalue tmp; -  free_svalue (&use_rb_node_ind (old, tmp)); +  use_rb_node_ind (old, tmp); +  free_svalue (&tmp);    free_svalue (&old->val);    really_free_rb_node_indval (old);    return 1;    }    return 0;   }      /* Returns the pointer to the node that actually was freed. */   PMOD_EXPORT struct rb_node_indval *rb_indval_delete_node (struct rb_node_indval **tree,    struct rb_node_indval *node,
pike.git/src/rbtree.c:398:    HDR (old) = low_rb_delete_node ((struct rb_node_hdr **) tree,    (low_rb_cmp_fn *) svalue_cmp_eq, &data,    (low_rb_move_data_fn *) move_ind_data,    HDR (node));    }    else    HDR (old) = low_rb_delete_node ((struct rb_node_hdr **) tree,    (low_rb_cmp_fn *) rb_ind_default_cmp, &tmp,    (low_rb_move_data_fn *) move_ind_data,    HDR (node)); -  free_svalue (&use_rb_node_ind (old, tmp)); +  use_rb_node_ind (old, tmp); +  free_svalue (&tmp);    free_svalue (&old->val);    really_free_rb_node_indval (old);    return old;   }      static struct rb_node_indval *copy_indval_node (struct rb_node_indval *node)   {    struct rb_node_indval *new = alloc_rb_node_indval();    struct svalue tmp; -  assign_svalue_no_free (&new->ind, &use_rb_node_ind (node, tmp)); +  use_rb_node_ind (node, tmp); +  assign_svalue_no_free (&new->ind, &tmp);    assign_svalue_no_free (&new->val, &node->val);    DO_IF_DEBUG (new->ind.type |= RB_FLAG_MARKER);    return new;   }      PMOD_EXPORT struct rb_node_indval *rb_indval_copy (struct rb_node_indval *tree)   {    return (struct rb_node_indval *)    low_rb_copy (HDR (tree), (low_rb_copy_fn *) copy_indval_node);   }
pike.git/src/rbtree.c:1395:   {    free_all_rb_node_ind_blocks();    free_all_rb_node_indval_blocks();   }      #if defined (PIKE_DEBUG) || defined (TEST_RBTREE)      static void debug_dump_ind_data (struct rb_node_ind *node)   {    struct svalue tmp; -  print_svalue (stderr, &use_rb_node_ind (node, tmp)); +  use_rb_node_ind (node, tmp); +  print_svalue (stderr, &tmp);    fputc (' ', stderr);   }      static void debug_dump_indval_data (struct rb_node_indval *node)   {    struct svalue tmp; -  print_svalue (stderr, &use_rb_node_ind (node, tmp)); +  use_rb_node_ind (node, tmp); +  print_svalue (stderr, &tmp);    fputs (": ", stderr);    print_svalue (stderr, &node->val);    fputc (' ', stderr);   }      static void debug_dump_rb_tree (struct rb_node_hdr *tree, dump_data_fn *dump_data)   {    if (tree) {    struct rb_node_hdr *n;    struct rbstack_ptr p;