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

Function remove

extra/yassl/taocrypt/test/memory.cpp:167–189  ·  view source on GitHub ↗

iterative remove

Source from the content-addressed store, hash-verified

165
166// iterative remove
167void remove(void* ptr)
168{
169 alloc_node* del = Root;
170 alloc_node* prev = 0;
171 alloc_node* replace = 0;
172
173 if ( lookup(del, ptr, prev) == false)
174 assert(0); // oops, not there
175
176 if (del->left_ && del->right_) // two children
177 replace = predecessorSwap(del);
178 else if (!del->left_ && !del->right_) // no children
179 replace = 0;
180 else // one child
181 replace = (del->left_) ? del->left_ : del->right_;
182
183 if (del == Root)
184 Root = replace;
185 else if (prev->left_ == del)
186 prev->left_ = replace;
187 else
188 prev->right_ = replace;
189}
190
191
192typedef void (*fp)(alloc_node*, void*);

Callers 4

pop_frontMethod · 0.85
removeMethod · 0.85
operator deleteFunction · 0.85
mainFunction · 0.85

Calls 2

lookupFunction · 0.85
predecessorSwapFunction · 0.85

Tested by

no test coverage detected