0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-10-04 06:38:58 +02:00

ircd: monitor: use irc_radixtree instead of home-grown hashtable

This commit is contained in:
William Pitcock 2016-01-23 10:35:40 -05:00
parent b9a32bd24b
commit 3de2266243

View file

@ -37,44 +37,31 @@
#include "hash.h" #include "hash.h"
#include "numeric.h" #include "numeric.h"
#include "send.h" #include "send.h"
#include "irc_radixtree.h"
static rb_dlink_list monitorTable[MONITOR_HASH_SIZE]; static struct irc_radixtree *monitor_tree;
static rb_bh *monitor_heap;
void void
init_monitor(void) init_monitor(void)
{ {
monitor_heap = rb_bh_create(sizeof(struct monitor), MONITOR_HEAP_SIZE, "monitor_heap"); monitor_tree = irc_radixtree_create("monitor lists", irc_radixtree_irccasecanon);
}
static inline unsigned int
hash_monitor_nick(const char *name)
{
return fnv_hash_upper((const unsigned char *)name, MONITOR_HASH_BITS);
} }
struct monitor * struct monitor *
find_monitor(const char *name, int add) find_monitor(const char *name, int add)
{ {
struct monitor *monptr; struct monitor *monptr;
rb_dlink_node *ptr;
unsigned int hashv = hash_monitor_nick(name); monptr = irc_radixtree_retrieve(monitor_tree, name);
if (monptr != NULL)
RB_DLINK_FOREACH(ptr, monitorTable[hashv].head) return monptr;
{
monptr = ptr->data;
if(!irccmp(monptr->name, name))
return monptr;
}
if(add) if(add)
{ {
monptr = rb_bh_alloc(monitor_heap); monptr = rb_malloc(sizeof(*monptr));
rb_strlcpy(monptr->name, name, sizeof(monptr->name)); rb_strlcpy(monptr->name, name, sizeof(monptr->name));
monptr->hashv = hashv; irc_radixtree_add(monitor_tree, monptr->name, monptr);
rb_dlinkAdd(monptr, &monptr->node, &monitorTable[hashv]);
return monptr; return monptr;
} }
@ -87,8 +74,8 @@ free_monitor(struct monitor *monptr)
if (rb_dlink_list_length(&monptr->users) > 0) if (rb_dlink_list_length(&monptr->users) > 0)
return; return;
rb_dlinkDelete(&monptr->node, &monitorTable[monptr->hashv]); irc_radixtree_delete(monitor_tree, monptr->name);
rb_bh_free(monitor_heap, monptr); rb_free(monptr);
} }
/* monitor_signon() /* monitor_signon()