MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / init_tree

Function init_tree

mysys/tree.c:86–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84#endif
85
86void init_tree(TREE *tree, ulong default_alloc_size, ulong memory_limit,
87 int size, qsort_cmp2 compare, my_bool with_delete,
88 tree_element_free free_element, const void *custom_arg)
89{
90 DBUG_ENTER("init_tree");
91 DBUG_PRINT("enter",("tree: 0x%lx size: %d", (long) tree, size));
92
93 if (default_alloc_size < DEFAULT_ALLOC_SIZE)
94 default_alloc_size= DEFAULT_ALLOC_SIZE;
95 default_alloc_size= MY_ALIGN(default_alloc_size, DEFAULT_ALIGN_SIZE);
96 memset(&tree->null_element, 0, sizeof(tree->null_element));
97 tree->root= &tree->null_element;
98 tree->compare=compare;
99 tree->size_of_element=size > 0 ? (uint) size : 0;
100 tree->memory_limit=memory_limit;
101 tree->free=free_element;
102 tree->allocated=0;
103 tree->elements_in_tree=0;
104 tree->custom_arg = custom_arg;
105 tree->null_element.colour=BLACK;
106 tree->null_element.left=tree->null_element.right=0;
107 tree->flag= 0;
108 if (!free_element && size >= 0 &&
109 ((uint) size <= sizeof(void*) || ((uint) size & (sizeof(void*)-1))))
110 {
111 /*
112 We know that the data doesn't have to be aligned (like if the key
113 contains a double), so we can store the data combined with the
114 TREE_ELEMENT.
115 */
116 tree->offset_to_key=sizeof(TREE_ELEMENT); /* Put key after element */
117 /* Fix allocation size so that we don't lose any memory */
118 default_alloc_size/=(sizeof(TREE_ELEMENT)+size);
119 if (!default_alloc_size)
120 default_alloc_size=1;
121 default_alloc_size*=(sizeof(TREE_ELEMENT)+size);
122 }
123 else
124 {
125 tree->offset_to_key=0; /* use key through pointer */
126 tree->size_of_element+=sizeof(void*);
127 }
128 if (!(tree->with_delete=with_delete))
129 {
130 init_alloc_root(&tree->mem_root, (uint) default_alloc_size, 0);
131 tree->mem_root.min_malloc=(sizeof(TREE_ELEMENT)+tree->size_of_element);
132 }
133 DBUG_VOID_RETURN;
134}
135
136static void free_tree(TREE *tree, myf free_flags)
137{

Callers 5

field_strMethod · 0.85
field_decimalMethod · 0.85
field_realMethod · 0.85
field_longlongMethod · 0.85
field_ulonglongMethod · 0.85

Calls 1

init_alloc_rootFunction · 0.85

Tested by

no test coverage detected