diff options
author | Oleksandr Byelkin <sanja@mariadb.com> | 2019-05-12 17:20:23 +0200 |
---|---|---|
committer | Oleksandr Byelkin <sanja@mariadb.com> | 2019-05-12 17:20:23 +0200 |
commit | c51f85f8823a845cd4a6aa1b2aa5af18484b2ab0 (patch) | |
tree | 65c45f6100c13dad90c33b86dc68be268139b0b8 /mysys | |
parent | a89f199c64a1d2339de7c167ce64ec148061a4d3 (diff) | |
parent | 8ce702aa90c174566f4ac950e85cc7570bf9b647 (diff) | |
download | mariadb-git-c51f85f8823a845cd4a6aa1b2aa5af18484b2ab0.tar.gz |
Merge branch '10.2' into 10.3
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/tree.c | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/mysys/tree.c b/mysys/tree.c index b07d56ec942..87297bb434e 100644 --- a/mysys/tree.c +++ b/mysys/tree.c @@ -77,6 +77,7 @@ static void rb_insert(TREE *tree,TREE_ELEMENT ***parent, TREE_ELEMENT *leaf); static void rb_delete_fixup(TREE *tree,TREE_ELEMENT ***parent); +static TREE_ELEMENT null_element= { NULL, NULL, 0, BLACK }; /* The actual code for handling binary trees */ @@ -95,8 +96,7 @@ void init_tree(TREE *tree, size_t default_alloc_size, size_t memory_limit, if (default_alloc_size < DEFAULT_ALLOC_SIZE) default_alloc_size= DEFAULT_ALLOC_SIZE; default_alloc_size= MY_ALIGN(default_alloc_size, DEFAULT_ALIGN_SIZE); - bzero((uchar*) &tree->null_element,sizeof(tree->null_element)); - tree->root= &tree->null_element; + tree->root= &null_element; tree->compare=compare; tree->size_of_element= size > 0 ? (uint) size : 0; tree->memory_limit=memory_limit; @@ -104,8 +104,6 @@ void init_tree(TREE *tree, size_t default_alloc_size, size_t memory_limit, tree->allocated=0; tree->elements_in_tree=0; tree->custom_arg = custom_arg; - tree->null_element.colour=BLACK; - tree->null_element.left=tree->null_element.right=0; tree->my_flags= my_flags; tree->flag= 0; if (!free_element && size >= 0 && @@ -167,7 +165,7 @@ static int free_tree(TREE *tree, my_bool abort, myf free_flags) free_root(&tree->mem_root, free_flags); } } - tree->root= &tree->null_element; + tree->root= &null_element; tree->elements_in_tree=0; tree->allocated=0; @@ -207,7 +205,7 @@ static int delete_tree_element(TREE *tree, TREE_ELEMENT *element, my_bool abort) { int error, first_error= 0; - if (element != &tree->null_element) + if (element != &null_element) { if ((first_error= delete_tree_element(tree, element->left, abort))) abort= 1; @@ -247,7 +245,7 @@ TREE_ELEMENT *tree_insert(TREE *tree, void *key, uint key_size, *parent = &tree->root; element= tree->root; for (;;) { - if (element == &tree->null_element || + if (element == &null_element || (cmp = (*tree->compare)(custom_arg, ELEMENT_KEY(tree,element), key)) == 0) break; @@ -260,11 +258,11 @@ TREE_ELEMENT *tree_insert(TREE *tree, void *key, uint key_size, *++parent = &element->left; element= element->left; } } - if (element == &tree->null_element) + if (element == &null_element) { uint alloc_size; if (tree->flag & TREE_ONLY_DUPS) - return((TREE_ELEMENT *) 1); + return TREE_ELEMENT_UNIQUE; alloc_size=sizeof(TREE_ELEMENT)+key_size+tree->size_of_element; tree->allocated+=alloc_size; @@ -284,7 +282,7 @@ TREE_ELEMENT *tree_insert(TREE *tree, void *key, uint key_size, if (!element) return(NULL); **parent=element; - element->left=element->right= &tree->null_element; + element->left=element->right= &null_element; if (!tree->offset_to_key) { if (key_size == sizeof(void*)) /* no length, save pointer */ @@ -326,7 +324,7 @@ int tree_delete(TREE *tree, void *key, uint key_size, void *custom_arg) *parent= &tree->root; element= tree->root; for (;;) { - if (element == &tree->null_element) + if (element == &null_element) return 1; /* Was not in tree */ if ((cmp = (*tree->compare)(custom_arg, ELEMENT_KEY(tree,element), key)) == 0) @@ -340,12 +338,12 @@ int tree_delete(TREE *tree, void *key, uint key_size, void *custom_arg) *++parent = &element->left; element= element->left; } } - if (element->left == &tree->null_element) + if (element->left == &null_element) { (**parent)=element->right; remove_colour= element->colour; } - else if (element->right == &tree->null_element) + else if (element->right == &null_element) { (**parent)=element->left; remove_colour= element->colour; @@ -354,7 +352,7 @@ int tree_delete(TREE *tree, void *key, uint key_size, void *custom_arg) { org_parent= parent; *++parent= &element->right; nod= element->right; - while (nod->left != &tree->null_element) + while (nod->left != &null_element) { *++parent= &nod->left; nod= nod->left; } @@ -384,7 +382,7 @@ void *tree_search(TREE *tree, void *key, void *custom_arg) for (;;) { - if (element == &tree->null_element) + if (element == &null_element) return (void*) 0; if ((cmp = (*tree->compare)(custom_arg, ELEMENT_KEY(tree,element), key)) == 0) @@ -409,8 +407,8 @@ void *tree_search_key(TREE *tree, const void *key, TODO: support for HA_READ_KEY_OR_PREV, HA_READ_PREFIX flags if needed. */ - *parents = &tree->null_element; - while (element != &tree->null_element) + *parents = &null_element; + while (element != &null_element) { *++parents= element; if ((cmp= (*tree->compare)(custom_arg, ELEMENT_KEY(tree, element), @@ -481,14 +479,14 @@ void *tree_search_edge(TREE *tree, TREE_ELEMENT **parents, { TREE_ELEMENT *element= tree->root; - *parents= &tree->null_element; - while (element != &tree->null_element) + *parents= &null_element; + while (element != &null_element) { *++parents= element; element= ELEMENT_CHILD(element, child_offs); } *last_pos= parents; - return **last_pos != &tree->null_element ? + return **last_pos != &null_element ? ELEMENT_KEY(tree, **last_pos) : NULL; } @@ -497,11 +495,11 @@ void *tree_search_next(TREE *tree, TREE_ELEMENT ***last_pos, int l_offs, { TREE_ELEMENT *x= **last_pos; - if (ELEMENT_CHILD(x, r_offs) != &tree->null_element) + if (ELEMENT_CHILD(x, r_offs) != &null_element) { x= ELEMENT_CHILD(x, r_offs); *++*last_pos= x; - while (ELEMENT_CHILD(x, l_offs) != &tree->null_element) + while (ELEMENT_CHILD(x, l_offs) != &null_element) { x= ELEMENT_CHILD(x, l_offs); *++*last_pos= x; @@ -511,12 +509,12 @@ void *tree_search_next(TREE *tree, TREE_ELEMENT ***last_pos, int l_offs, else { TREE_ELEMENT *y= *--*last_pos; - while (y != &tree->null_element && x == ELEMENT_CHILD(y, r_offs)) + while (y != &null_element && x == ELEMENT_CHILD(y, r_offs)) { x= y; y= *--*last_pos; } - return y == &tree->null_element ? NULL : ELEMENT_KEY(tree, y); + return y == &null_element ? NULL : ELEMENT_KEY(tree, y); } } @@ -532,7 +530,7 @@ ha_rows tree_record_pos(TREE *tree, const void *key, double left= 1; double right= tree->elements_in_tree; - while (element != &tree->null_element) + while (element != &null_element) { if ((cmp= (*tree->compare)(custom_arg, ELEMENT_KEY(tree, element), key)) == 0) |