MCPcopy Create free account
hub / github.com/GJDuck/e9patch / pool_tdelete

Function pool_tdelete

examples/stdlib.c:5478–5502  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5476}
5477
5478static void *pool_tdelete(struct malloc_pool_s *pool, const void *key,
5479 void **root, int (*compare)(const void *, const void *))
5480{
5481 if (root == NULL)
5482 return NULL;
5483 struct tree_s *t = (struct tree_s *)root;
5484 struct node_s *n = t->root;
5485 int cmp = 0;
5486 while (n != NULL)
5487 {
5488 cmp = compare(key, n->key);
5489 if (cmp < 0)
5490 n = TREE_LEFT(n);
5491 else if (cmp > 0)
5492 n = TREE_RIGHT(n);
5493 else
5494 {
5495 struct node_s *parent = TREE_PARENT(n);
5496 n = tree_remove(t, n);
5497 pool_free(pool, n);
5498 return (parent == NULL? (void *)root: parent);
5499 }
5500 }
5501 return NULL;
5502}
5503static void *tdelete(const void *key, void **root,
5504 int (*compare)(const void *, const void *))
5505{

Callers 1

tdeleteFunction · 0.85

Calls 3

tree_removeFunction · 0.85
pool_freeFunction · 0.85
compareFunction · 0.70

Tested by

no test coverage detected