Optimize lookups by CID and nick.

This used to be a linear search O(n), but is now done
as a red-black tree O(log n) instead.

These operations can be further opimized with a hash-table
which would acheive near constant time lookups.
This commit is contained in:
Jan Vidar Krey
2013-03-23 22:11:05 +01:00
parent 52211a6bac
commit cd5c4ee622
4 changed files with 28 additions and 23 deletions

View File

@@ -157,7 +157,7 @@ static struct rb_node* rb_tree_insert_r(struct rb_tree* tree, struct rb_node* no
struct rb_tree* rb_tree_create(rb_tree_compare compare, rb_tree_alloc a, rb_tree_free f)
{
struct rb_tree* tree = a(sizeof(struct rb_tree));
struct rb_tree* tree = a ? a(sizeof(struct rb_tree)) : hub_malloc(sizeof(struct rb_tree));
tree->compare = compare;
tree->alloc = a ? a : hub_malloc;
tree->free = f ? f : hub_free;