Branch: Tag:

2002-12-08

2002-12-08 16:45:33 by Martin Stjernholm <mast@lysator.liu.se>

Added some more asserts in rb_make_tree to catch unbalanced trees.
Made the debug tree dump slightly easier to read.

Rev: src/rbtree.c:1.20

2:   || 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.
12:      #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"
1490:    root = list;    }    } +  assert (idx <= depth);       if (count++ == deep_end) {    if (idx) { /* Interior node is "half a leaf". */
1512:    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;
1734: Inside #if defined (PIKE_DEBUG) || defined (TEST_MULTISET)
   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);
1759: Inside #if defined (PIKE_DEBUG) || defined (TEST_MULTISET)
   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);    }