ircd: hash: channels are no longer a hashtable
This commit is contained in:
parent
730b914c17
commit
9b74b99268
2 changed files with 11 additions and 51 deletions
|
@ -30,7 +30,6 @@
|
||||||
struct Dictionary;
|
struct Dictionary;
|
||||||
struct irc_radixtree;
|
struct irc_radixtree;
|
||||||
|
|
||||||
extern rb_dlink_list *channelTable;
|
|
||||||
extern rb_dlink_list *hostTable;
|
extern rb_dlink_list *hostTable;
|
||||||
|
|
||||||
extern struct Dictionary *nd_dict;
|
extern struct Dictionary *nd_dict;
|
||||||
|
|
57
ircd/hash.c
57
ircd/hash.c
|
@ -42,7 +42,6 @@
|
||||||
#include "irc_dictionary.h"
|
#include "irc_dictionary.h"
|
||||||
#include "irc_radixtree.h"
|
#include "irc_radixtree.h"
|
||||||
|
|
||||||
rb_dlink_list *channelTable;
|
|
||||||
rb_dlink_list *hostTable;
|
rb_dlink_list *hostTable;
|
||||||
|
|
||||||
struct Dictionary *client_connid_tree = NULL;
|
struct Dictionary *client_connid_tree = NULL;
|
||||||
|
@ -50,6 +49,7 @@ struct Dictionary *client_zconnid_tree = NULL;
|
||||||
struct irc_radixtree *client_id_tree = NULL;
|
struct irc_radixtree *client_id_tree = NULL;
|
||||||
struct irc_radixtree *client_name_tree = NULL;
|
struct irc_radixtree *client_name_tree = NULL;
|
||||||
|
|
||||||
|
struct irc_radixtree *channel_tree = NULL;
|
||||||
struct irc_radixtree *resv_tree = NULL;
|
struct irc_radixtree *resv_tree = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -63,7 +63,6 @@ struct irc_radixtree *resv_tree = NULL;
|
||||||
void
|
void
|
||||||
init_hash(void)
|
init_hash(void)
|
||||||
{
|
{
|
||||||
channelTable = rb_malloc(sizeof(rb_dlink_list) * CH_MAX);
|
|
||||||
hostTable = rb_malloc(sizeof(rb_dlink_list) * HOST_MAX);
|
hostTable = rb_malloc(sizeof(rb_dlink_list) * HOST_MAX);
|
||||||
|
|
||||||
client_connid_tree = irc_dictionary_create("client connid", irc_uint32cmp);
|
client_connid_tree = irc_dictionary_create("client connid", irc_uint32cmp);
|
||||||
|
@ -71,6 +70,7 @@ init_hash(void)
|
||||||
client_id_tree = irc_radixtree_create("client id", NULL);
|
client_id_tree = irc_radixtree_create("client id", NULL);
|
||||||
client_name_tree = irc_radixtree_create("client name", irc_radixtree_irccasecanon);
|
client_name_tree = irc_radixtree_create("client name", irc_radixtree_irccasecanon);
|
||||||
|
|
||||||
|
channel_tree = irc_radixtree_create("channel", irc_radixtree_irccasecanon);
|
||||||
resv_tree = irc_radixtree_create("resv", irc_radixtree_irccasecanon);
|
resv_tree = irc_radixtree_create("resv", irc_radixtree_irccasecanon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,16 +134,6 @@ fnv_hash_upper_len(const unsigned char *s, int bits, int len)
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* hash_channel()
|
|
||||||
*
|
|
||||||
* hashes a channel name, based on first 30 chars only for efficiency
|
|
||||||
*/
|
|
||||||
static u_int32_t
|
|
||||||
hash_channel(const char *name)
|
|
||||||
{
|
|
||||||
return fnv_hash_upper_len((const unsigned char *) name, CH_MAX_BITS, 30);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* hash_hostname()
|
/* hash_hostname()
|
||||||
*
|
*
|
||||||
* hashes a hostname, based on first 30 chars only, as thats likely to
|
* hashes a hostname, based on first 30 chars only, as thats likely to
|
||||||
|
@ -254,16 +244,13 @@ del_from_client_hash(const char *name, struct Client *client_p)
|
||||||
void
|
void
|
||||||
del_from_channel_hash(const char *name, struct Channel *chptr)
|
del_from_channel_hash(const char *name, struct Channel *chptr)
|
||||||
{
|
{
|
||||||
unsigned int hashv;
|
|
||||||
|
|
||||||
s_assert(name != NULL);
|
s_assert(name != NULL);
|
||||||
s_assert(chptr != NULL);
|
s_assert(chptr != NULL);
|
||||||
|
|
||||||
if(EmptyString(name) || chptr == NULL)
|
if(EmptyString(name) || chptr == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
hashv = hash_channel(name);
|
irc_radixtree_delete(channel_tree, name);
|
||||||
rb_dlinkFindDestroy(chptr, &channelTable[hashv]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* del_from_hostname_hash()
|
/* del_from_hostname_hash()
|
||||||
|
@ -398,25 +385,11 @@ find_hostname(const char *hostname)
|
||||||
struct Channel *
|
struct Channel *
|
||||||
find_channel(const char *name)
|
find_channel(const char *name)
|
||||||
{
|
{
|
||||||
struct Channel *chptr;
|
|
||||||
rb_dlink_node *ptr;
|
|
||||||
unsigned int hashv;
|
|
||||||
|
|
||||||
s_assert(name != NULL);
|
s_assert(name != NULL);
|
||||||
if(EmptyString(name))
|
if(EmptyString(name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
hashv = hash_channel(name);
|
return irc_radixtree_retrieve(channel_tree, name);
|
||||||
|
|
||||||
RB_DLINK_FOREACH(ptr, channelTable[hashv].head)
|
|
||||||
{
|
|
||||||
chptr = ptr->data;
|
|
||||||
|
|
||||||
if(irccmp(name, chptr->chname) == 0)
|
|
||||||
return chptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -434,8 +407,6 @@ struct Channel *
|
||||||
get_or_create_channel(struct Client *client_p, const char *chname, int *isnew)
|
get_or_create_channel(struct Client *client_p, const char *chname, int *isnew)
|
||||||
{
|
{
|
||||||
struct Channel *chptr;
|
struct Channel *chptr;
|
||||||
rb_dlink_node *ptr;
|
|
||||||
unsigned int hashv;
|
|
||||||
int len;
|
int len;
|
||||||
const char *s = chname;
|
const char *s = chname;
|
||||||
|
|
||||||
|
@ -458,30 +429,22 @@ get_or_create_channel(struct Client *client_p, const char *chname, int *isnew)
|
||||||
s = t;
|
s = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
hashv = hash_channel(s);
|
chptr = irc_radixtree_retrieve(channel_tree, s);
|
||||||
|
if (chptr != NULL)
|
||||||
RB_DLINK_FOREACH(ptr, channelTable[hashv].head)
|
|
||||||
{
|
{
|
||||||
chptr = ptr->data;
|
if (isnew != NULL)
|
||||||
|
|
||||||
if(irccmp(s, chptr->chname) == 0)
|
|
||||||
{
|
|
||||||
if(isnew != NULL)
|
|
||||||
*isnew = 0;
|
*isnew = 0;
|
||||||
return chptr;
|
return chptr;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(isnew != NULL)
|
if(isnew != NULL)
|
||||||
*isnew = 1;
|
*isnew = 1;
|
||||||
|
|
||||||
chptr = allocate_channel(s);
|
chptr = allocate_channel(s);
|
||||||
|
|
||||||
rb_dlinkAdd(chptr, &chptr->node, &global_channel_list);
|
|
||||||
|
|
||||||
chptr->channelts = rb_current_time(); /* doesn't hurt to set it here */
|
chptr->channelts = rb_current_time(); /* doesn't hurt to set it here */
|
||||||
|
|
||||||
rb_dlinkAddAlloc(chptr, &channelTable[hashv]);
|
rb_dlinkAdd(chptr, &chptr->node, &global_channel_list);
|
||||||
|
irc_radixtree_add(channel_tree, chptr->chname, chptr);
|
||||||
|
|
||||||
return chptr;
|
return chptr;
|
||||||
}
|
}
|
||||||
|
@ -626,7 +589,5 @@ count_hash(struct Client *source_p, rb_dlink_list *table, int length, const char
|
||||||
void
|
void
|
||||||
hash_stats(struct Client *source_p)
|
hash_stats(struct Client *source_p)
|
||||||
{
|
{
|
||||||
count_hash(source_p, channelTable, CH_MAX, "Channel");
|
|
||||||
sendto_one_numeric(source_p, RPL_STATSDEBUG, "B :--");
|
|
||||||
count_hash(source_p, hostTable, HOST_MAX, "Hostname");
|
count_hash(source_p, hostTable, HOST_MAX, "Hostname");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue