more work on pdf_add_tree_element().

Fri, 07 Mar 2003 11:28:45 +0000

author
eric
date
Fri, 07 Mar 2003 11:28:45 +0000
changeset 83
bbc7dd27aa5b
parent 82
abb03c7f4aab
child 84
a54eb7b9fc15

more work on pdf_add_tree_element().

pdf_name_tree.c file | annotate | diff | revisions
     1.1 diff -r abb03c7f4aab -r bbc7dd27aa5b pdf_name_tree.c
     1.2 --- a/pdf_name_tree.c	Fri Mar 07 11:02:31 2003 +0000
     1.3 +++ b/pdf_name_tree.c	Fri Mar 07 11:28:45 2003 +0000
     1.4 @@ -4,7 +4,7 @@
     1.5   *      will be compressed using ITU-T T.6 (G4) fax encoding.
     1.6   *
     1.7   * PDF routines
     1.8 - * $Id: pdf_name_tree.c,v 1.1 2003/03/07 02:16:08 eric Exp $
     1.9 + * $Id: pdf_name_tree.c,v 1.2 2003/03/07 03:28:45 eric Exp $
    1.10   * Copyright 2003 Eric Smith <eric@brouhaha.com>
    1.11   *
    1.12   * This program is free software; you can redistribute it and/or modify
    1.13 @@ -120,9 +120,17 @@
    1.14  				  struct pdf_obj *val)
    1.15  {
    1.16    struct pdf_name_tree_node *node;
    1.17 +  int i;
    1.18  
    1.19    /* find node which should contain element */
    1.20    node = tree->root;
    1.21 +  while (! node->leaf)
    1.22 +    {
    1.23 +      for (i = 0; i < (node->count - 1); i++)
    1.24 +	if (pdf_compare_obj (key, node->kids [i + 1]->min_key) < 0)
    1.25 +	  break;
    1.26 +      node = node->kids [i];
    1.27 +    }
    1.28  
    1.29    /* if node is full, split, recursing to root if necessary */
    1.30    if (node->count == MAX_NAME_TREE_NODE_ENTRIES)
    1.31 @@ -131,6 +139,29 @@
    1.32        pdf_add_tree_element (tree, key, val);
    1.33        return;
    1.34      }
    1.35 +
    1.36 +  /* $$$ figure out in which slot to insert it */
    1.37 +
    1.38 +  /* update limits, recursing upwards if necessary */
    1.39 +  if (i == 0)
    1.40 +    {
    1.41 +      node->min_key = key;
    1.42 +      while (node->parent && (node->parent->kids [0] == node))
    1.43 +	{
    1.44 +	  node = node->parent;
    1.45 +	  node->min_key = key;
    1.46 +	}
    1.47 +    }
    1.48 +  else if (i == (node->count - 1))
    1.49 +    {
    1.50 +      node->max_key = key;
    1.51 +      while (node->parent && (node->parent->kids [node->parent->count - 1] == node))
    1.52 +	{
    1.53 +	  node = node->parent;
    1.54 +	  node->max_key = key;
    1.55 +	}
    1.56 +    }
    1.57 +    
    1.58  }
    1.59  
    1.60