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