summaryrefslogtreecommitdiffstats
path: root/source3/lib/adt_tree.c
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2002-07-19 18:49:44 +0000
committerGerald Carter <jerry@samba.org>2002-07-19 18:49:44 +0000
commit9fe3bd1259e7bda901f7a264bd7fc88c72d2112f (patch)
tree7099006b7ed3b3dbfabe514d84183cd4bda609ac /source3/lib/adt_tree.c
parent80c8fe63d2d2149ff9d2294da281d61a683e27ea (diff)
downloadsamba-9fe3bd1259e7bda901f7a264bd7fc88c72d2112f.tar.gz
samba-9fe3bd1259e7bda901f7a264bd7fc88c72d2112f.tar.xz
samba-9fe3bd1259e7bda901f7a264bd7fc88c72d2112f.zip
* refactored registry operations some. subkey lists and
registry values are now passed around in containers (REGSUBKEY_CTR & REGVAL_CTR) which each possess a TALLOC_CTX. * removed subkey_specific_fn() from REGISTRY_OPS. Is implemented in the form of a wrapper * temporarily broke the printing registry ops. * implemented inheritence for the data_p of nodes in a SORTED_TREE * All REGISTRY_KEY instances now store a valid REGISTRY_HOOK since the default REGOSTRY_OPS structure is stored in the root of the cache_tree. * Probably some other change I forgot.... T (This used to be commit e7b55e8f017e638342d9c8c1a9259000745a0298)
Diffstat (limited to 'source3/lib/adt_tree.c')
-rw-r--r--source3/lib/adt_tree.c47
1 files changed, 32 insertions, 15 deletions
diff --git a/source3/lib/adt_tree.c b/source3/lib/adt_tree.c
index e3519c6c41d..3a6e722c97d 100644
--- a/source3/lib/adt_tree.c
+++ b/source3/lib/adt_tree.c
@@ -26,7 +26,8 @@
for comparision of two children
*************************************************************************/
-SORTED_TREE* sorted_tree_init( int (cmp_fn)(void*, void*),
+SORTED_TREE* sorted_tree_init( void *data_p,
+ int (cmp_fn)(void*, void*),
void (free_fn)(void*) )
{
SORTED_TREE *tree = NULL;
@@ -45,6 +46,7 @@ SORTED_TREE* sorted_tree_init( int (cmp_fn)(void*, void*),
}
ZERO_STRUCTP( tree->root );
+ tree->root->data_p = data_p;
return tree;
}
@@ -94,7 +96,6 @@ void sorted_tree_destroy( SORTED_TREE *tree )
static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key )
{
TREE_NODE *infant = NULL;
- TREE_NODE *child, *crib;
TREE_NODE **siblings;
int i, result;
@@ -116,7 +117,7 @@ static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key )
/* first child */
if ( node->num_children == 1 ) {
- DEBUG(11,("sorted_tree_birth_child: First child of node [%s]! [%s]\n",
+ DEBUG(10,("sorted_tree_birth_child: First child of node [%s]! [%s]\n",
node->key ? node->key : "NULL", infant->key ));
node->children[0] = infant;
}
@@ -133,23 +134,28 @@ static TREE_NODE* sorted_tree_birth_child( TREE_NODE *node, char* key )
for ( i = node->num_children-1; i>=1; i-- )
{
- crib = node->children[i];
- child = node->children[i-1];
-
DEBUG(10,("sorted_tree_birth_child: Looking for crib; infant -> [%s], child -> [%s]\n",
- infant->key, child->key));
+ infant->key, node->children[i-1]->key));
/* the strings should never match assuming that we
have called sorted_tree_find_child() first */
- result = StrCaseCmp( infant->key, child->key );
+ result = StrCaseCmp( infant->key, node->children[i-1]->key );
if ( result > 0 ) {
- crib = infant;
+ node->children[i] = infant;
break;
}
-
- crib = child;
+
+ /* bump everything towards the end on slot */
+
+ node->children[i] = node->children[i-1];
}
+
+ /* if we haven't found the correct clot yet, the child
+ will be first in the list */
+
+ if ( i == 0 )
+ node->children[0] = infant;
}
return infant;
@@ -376,6 +382,9 @@ void* sorted_tree_find( SORTED_TREE *tree, char *key )
str = keystr;
current = tree->root;
+ if ( tree->root->data_p )
+ result = tree->root->data_p;
+
do
{
/* break off the remaining part of the path */
@@ -384,7 +393,7 @@ void* sorted_tree_find( SORTED_TREE *tree, char *key )
if ( str )
*str = '\0';
- DEBUG(10,("sorted_tree_find: [loop] key => [%s]\n", base));
+ DEBUG(11,("sorted_tree_find: [loop] key => [%s]\n", base));
/* iterate to the next child */
@@ -399,10 +408,18 @@ void* sorted_tree_find( SORTED_TREE *tree, char *key )
str = base;
}
+ /*
+ * the idea is that the data_p for a parent should
+ * be inherited by all children, but allow it to be
+ * overridden farther down
+ */
+
+ if ( current && current->data_p )
+ result = current->data_p;
+
} while ( base && current );
-
- if ( current )
- result = current->data_p;
+
+ /* result should be the data_p from the lowest match node in the tree */
SAFE_FREE( keystr );