91 element->
right = NULL;
104 while (NULL != tree) {
105 if (tree->
size == size) {
110 if (size > tree->
size) {
128 if (NULL != node && NULL != node->
parent) {
174 rightChild->
left = node;
176 node->
right = rcLeftSub;
177 if (NULL != rcLeftSub) {
191 node->
parent = rightChild;
200 leftChild->
right = node;
202 node->
left = lcRightSub;
203 if (NULL != lcRightSub) {
204 lcRightSub->
parent = node;
226 if (NULL != node1->
parent) {
253 element->
next = NULL;
254 element->
last = NULL;
258 element->
left = NULL;
259 element->
right = NULL;
263 *tree = node = new_node = element;
266 while (NULL != node) {
268 if (NULL == node->
left) {
269 node->
left = element;
271 new_node = node = node->
left;
276 }
else if (element->
size > node->
size) {
277 if (NULL == node->
right) {
278 node->
right = element;
280 new_node = node = node->
right;
286 if (NULL == node->
next) {
287 node->
next = element;
288 node->
last = element;
291 node->
last = element;
298 if (NULL != new_node) {
304 if (node->
parent == NULL) {
381 while (NULL != node->
left) {
397 while (NULL != node) {
401 }
else if (element->
size > node->
size) {
404 if (NULL != node->
next) {
405 if (NULL != node->
parent) {
415 if (NULL != node->
left) {
419 if (NULL != node->
right) {
446 if (NULL != node->
left && NULL != node->
right) {
460 if (node->
right == successor) {
461 successor->
right = node;
467 tmpparent->
left = node;
470 node->
color = tmpcolor;
471 node->
left = tmpleft;
472 node->
right = tmpright;
503 if (NULL == node->
parent) {
586 if (NULL != node && NULL != node->
parent) {
595 if (NULL != s->
right) {
600 if (NULL != s->
left) {
632 if (previous == node->
right) {
639 if ((NULL == node->
left || previous == node->
left)) {
647 if (NULL != node->
right) {
682 if (((NULL == node->
left || previous == node->
left)
683 && NULL == node->
right)
684 || previous == node->
right) {
696 if ((NULL == node->
left || previous == node->
left)) {
703 if (NULL != node->
right) {
725 printf(
"%s %010zu:%p(%02d)",
730 for (i=0; i<depth; i++) printf(
"-");
734 while (NULL != node) {
735 printf(
" %s %010zu:%p(%02d)",
740 for (i=0; i<depth; i++) printf(
"-");
749 while (NULL != node) {
762 while (NULL != segment) {
792 size = (0>=
size)?1:(0!=size%psize)?(size/psize)+1:size/psize;
820 size_t _size = nmemb *
size;
823 memset(mem, 0, _size);
858 return segment->
size;
void * memCalloc(size_t nmemb, size_t size)
void * memMalloc(size_t size)
struct memSegment * uncle(struct memSegment *node)
struct memSegment * sibling(struct memSegment *node)
struct memSegment * findInOrderSuccessor(struct memSegment *tree)
void traverse(struct memSegment *tree, void(*cb)(struct memSegment *, int))
static void(* cb)(const void *)
void replaceNode(struct memSegment **tree, struct memSegment *node1, struct memSegment *node2)
void * memNewRef(void *mem)
void cleanup(struct memSegment *node, int depth)
struct memSegment * deleteElement(struct memSegment **tree, struct memSegment *element)
void rotateRight(struct memSegment **tree, struct memSegment *node)
struct memSegment * newElement(size_t size)
struct memSegment * segments
struct memSegment * parent
void printElement(struct memSegment *node, int depth)
size_t memGetSize(void *mem)
void rotateLeft(struct memSegment **tree, struct memSegment *node)
void post(struct memSegment *tree, void(*cb)(struct memSegment *, int))
struct memSegment * findElement(struct memSegment *tree, size_t size)
static void segmentFree(struct memSegment *segment, int depth)
struct memSegment * grandparent(struct memSegment *node)
struct memSegment * right
struct memSegment * insertElement(struct memSegment **tree, struct memSegment *element)