pike.git / src / rbtree.c

version» Context lines:

pike.git/src/rbtree.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: rbtree.c,v 1.19 2002/12/07 23:16:46 grubba Exp $ + || $Id: rbtree.c,v 1.20 2002/12/08 16:45:33 mast Exp $   */      /* An implementation of a threaded red/black balanced binary tree.    *    * Created 2001-04-27 by Martin Stjernholm <mast@lysator.liu.se>    */      #include "global.h"    - RCSID("$Id: rbtree.c,v 1.19 2002/12/07 23:16:46 grubba Exp $"); + RCSID("$Id: rbtree.c,v 1.20 2002/12/08 16:45:33 mast Exp $");      #include "interpret.h"   #include "pike_error.h"   #include "rbtree_low.h"      #include <assert.h>   #include <stdlib.h>      #if defined (PIKE_DEBUG) || defined (TEST_MULTISET)   
pike.git/src/rbtree.c:1483:    else { /* Interior node. */    idx = top_idx[idx];    list->flags &= ~(RB_THREAD_PREV|RB_THREAD_NEXT);    prev_tgt = next_src->next = stack[idx] = list;    list->prev = stack[idx - 1];    if (idx == depth) {    assert (!root);    root = list;    }    } +  assert (idx <= depth);       if (count++ == deep_end) {    if (idx) { /* Interior node is "half a leaf". */    next_src = list;    list->flags |= RB_THREAD_NEXT;    }    start = 1;    }       if (idx & 1) list->flags &= ~RB_RED;
pike.git/src/rbtree.c:1505:    if (top_idx[idx] == top_idx[idx + 1])    top_idx[idx] = idx + 1;    else {    top_idx[idx] = top_idx[idx + 1];    stack[idx + 1]->next = list;    }       list = next;    }    -  /* FIXME: What if root is still NULL here? */ +  assert (deep_end == length - 1 && (length & 1) ? idx == 0 : idx == start); + #ifdef PIKE_DEBUG +  for (; idx <= depth; idx++) +  assert (top_idx[idx] == depth + 1); + #endif    assert(root);       next_src->next = NULL;    root->flags &= ~RB_RED;    if (stack_malloced) xfree (stack);    }    else if (length) {    root = list;   #ifdef PIKE_DEBUG    list = list->next;
pike.git/src/rbtree.c:1727: Inside #if defined (PIKE_DEBUG) || defined (TEST_MULTISET)
   fputc ('(', stderr);    }, { /* prev is leaf. */    p = rbstack;    n2 = node;    RBSTACK_UP (p, n);    while (n && (n->flags & RB_THREAD_NEXT || n->next != n2)) {    n2 = n;    RBSTACK_UP (p, n);    }    if (node->prev != n) -  fprintf (stderr, "[Thread ptr is %p, expected %p] ", node->prev, n); +  fprintf (stderr, "[Thread ptr is %p, expected %p]\n%*s", +  node->prev, n, depth, "");    }, { /* prev is subtree. */    if (!node->prev) {    fputs ("[Zero subtree]", stderr);    goto between_1;    }    }, { /* Between nodes. */    if (!(node->flags & RB_THREAD_PREV))    fprintf (stderr, "\n%*s", depth, "");    if (node == root) fputs ("root=", stderr);    fprintf (stderr, "%p/%c",
pike.git/src/rbtree.c:1752: Inside #if defined (PIKE_DEBUG) || defined (TEST_MULTISET)
   }    }, { /* next is leaf. */    p = rbstack;    n2 = node;    RBSTACK_UP (p, n);    while (n && (n->flags & RB_THREAD_PREV || n->prev != n2)) {    n2 = n;    RBSTACK_UP (p, n);    }    if (node->next != n) -  fprintf (stderr, " [Thread ptr is %p, expected %p]", node->next, n); +  fprintf (stderr, "\n%*s[Thread ptr is %p, expected %p]", +  depth, "", node->next, n);    }, { /* next is subtree. */ -  +  fprintf (stderr, "\n%*s", depth, "");    if (!node->next) { -  fputs (" [Zero subtree]", stderr); +  fputs ("[Zero subtree]", stderr);    goto leave_1;    } -  fprintf (stderr, "\n%*s", depth, ""); +     }, { /* Pop. */    fputc (')', stderr); -  depth--; +     skip_node: -  ; +  depth--;    });    fputc ('\n', stderr);    }    else    fprintf (stderr, "(empty tree)\n");   }      /* If pos isn't zero, it points to a pointer in the stack that will be    * marked in the output. */   void debug_dump_rbstack (struct rbstack_ptr rbstack, struct rbstack_ptr *pos)