31 element->
ptr = element +
sizeof(
struct element);
39 element->
right = NULL;
50 struct element * fitting = NULL;
52 while (NULL != tree) {
53 if (tree->
size == size) {
58 if (size > tree->
size) {
76 if (NULL != node && NULL != node->
parent) {
122 rightChild->
left = node;
124 node->
right = rcLeftSub;
125 if (NULL != rcLeftSub) {
139 node->
parent = rightChild;
148 leftChild->
right = node;
150 node->
left = lcRightSub;
151 if (NULL != lcRightSub) {
152 lcRightSub->
parent = node;
174 if (NULL != node1->
parent) {
196 struct element * node = *tree;
197 struct element * new_node = NULL;
201 element->
next = NULL;
202 element->
last = NULL;
206 element->
left = NULL;
207 element->
right = NULL;
211 *tree = node = new_node = element;
214 while (NULL != node) {
216 if (NULL == node->
left) {
217 node->
left = element;
219 new_node = node = node->
left;
224 }
else if (element->
size > node->
size) {
225 if (NULL == node->
right) {
226 node->
right = element;
228 new_node = node = node->
right;
234 if (NULL == node->
next) {
235 node->
next = element;
236 node->
last = element;
239 node->
last = element;
246 if (NULL != new_node) {
252 if (node->
parent == NULL) {
329 while (NULL != node->
left) {
341 struct element * node = *tree;
342 struct element * del_node;
343 struct element * child;
347 while (NULL != node) {
351 }
else if (element->
size > node->
size) {
354 if (NULL != node->
next) {
355 if (NULL != node->
parent) {
365 if (NULL != node->
left) {
369 if (NULL != node->
right) {
396 if (NULL != node->
left && NULL != node->
right) {
400 struct element * tmpparent = successor->
parent;
401 struct element * tmpleft = successor->
left;
402 struct element * tmpright = successor->
right;
410 if (node->
right == successor) {
411 successor->
right = node;
417 tmpparent->
left = node;
420 node->
color = tmpcolor;
421 node->
left = tmpleft;
422 node->
right = tmpright;
453 if (NULL == node->
parent) {
536 if (NULL != node && NULL != node->
parent) {
545 if (NULL != s->
right) {
550 if (NULL != s->
left) {
570 struct element * previous = tree;
584 if (previous == node->
right) {
591 if ((NULL == node->
left || previous == node->
left)) {
599 if (NULL != node->
right) {
620 struct element * previous = tree;
634 if ((NULL == node->
left && NULL == node->
right)
635 || previous == node->
right) {
647 if ((NULL == node->
left || previous == node->
left)) {
654 if (NULL != node->
right) {
676 printf(
"%s %010zu:%p(%02d)",
681 for (i=0; i<depth; i++) printf(
"-");
685 while (NULL != node) {
686 printf(
" %s %010zu:%p(%02d)",
691 for (i=0; i<depth; i++) printf(
"-");
699 while (NULL != node) {
700 printf(
"free node: ");
736 printf(
"can't find segmenet of minimum size: %d\n", 10);
744 printf(
"can't find segmenet of minimum size: %d\n", 64);
752 printf(
"can't find segmenet of minimum size: %d\n", 90);
772 printf(
"up to free: %p\n", found);
779 printf(
"up to free: %p\n", found);
786 printf(
"up to free: %p\n", found);
struct element * newElement(size_t size)
void post(struct element *tree, void(*cb)(struct element *, int))
int main(int argc, char *argv[])
struct element * deleteOneChild(struct element **, struct element *)
void rotateRight(struct element **tree, struct element *node)
struct element * grandparent(struct element *node)
struct element * insertElement(struct element **tree, struct element *element)
void traverse(struct element *tree, void(*cb)(struct element *, int))
static void(* cb)(const void *)
struct element * findInOrderSuccessor(struct element *tree)
void cleanup(struct element *node, int depth)
struct element * deleteElement(struct element **tree, struct element *element)
void replaceNode(struct element **tree, struct element *node1, struct element *node2)
void rotateLeft(struct element **tree, struct element *node)
struct element * sibling(struct element *node)
struct element * uncle(struct element *node)
struct element * findElement(struct element *tree, size_t size)
void printElement(struct element *node, int depth)