mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
add a function to return the first entry that is stored in a tree where
the key is an array of uint32_t (This used to be ctdb commit 99553397aade4f1c4d17ef14dad406934958c80a)
This commit is contained in:
parent
5a02262a06
commit
e0957ba4a4
@ -962,6 +962,43 @@ trbt_traversearray32(trbt_tree_t *tree, uint32_t keylen,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* this function will return the first node in a tree where
|
||||||
|
the key is an array of uint32_t
|
||||||
|
*/
|
||||||
|
void *
|
||||||
|
trbt_findfirstarray32(trbt_tree_t *tree, uint32_t keylen)
|
||||||
|
{
|
||||||
|
trbt_node_t *node;
|
||||||
|
|
||||||
|
if (keylen < 1) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tree == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
node=tree->root;
|
||||||
|
if (node == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (node->left) {
|
||||||
|
node = node->left;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* we found our node so return the data */
|
||||||
|
if (keylen == 1) {
|
||||||
|
return node->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* we are still traversing subtrees so find the first node in the
|
||||||
|
next level of trees
|
||||||
|
*/
|
||||||
|
return trbt_findfirstarray32(node->data, keylen-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
static void printtree(trbt_node_t *node, int levels)
|
static void printtree(trbt_node_t *node, int levels)
|
||||||
{
|
{
|
||||||
|
@ -76,3 +76,7 @@ void *trbt_lookuparray32(trbt_tree_t *tree, uint32_t keylen, uint32_t *key);
|
|||||||
|
|
||||||
/* Traverse a tree with a key based on an array of uint32 */
|
/* Traverse a tree with a key based on an array of uint32 */
|
||||||
void trbt_traversearray32(trbt_tree_t *tree, uint32_t keylen, void (*callback)(void *param, void *data), void *param);
|
void trbt_traversearray32(trbt_tree_t *tree, uint32_t keylen, void (*callback)(void *param, void *data), void *param);
|
||||||
|
|
||||||
|
/* Lookup the first node in the tree with a key based on an array of uint32
|
||||||
|
and return a pointer to data or NULL */
|
||||||
|
void *trbt_findfirstarray32(trbt_tree_t *tree, uint32_t keylen);
|
||||||
|
@ -301,6 +301,7 @@ int main(int argc, const char *argv[])
|
|||||||
printf("\niterations passed:%d\n", i);
|
printf("\niterations passed:%d\n", i);
|
||||||
trbt_traversearray32(tree, 3, random_traverse, NULL);
|
trbt_traversearray32(tree, 3, random_traverse, NULL);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
printf("first node: %s\n", (char *)trbt_findfirstarray32(tree, 3));
|
||||||
|
|
||||||
|
|
||||||
printf("\ndeleting all entries\n");
|
printf("\ndeleting all entries\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user