X-Git-Url: https://jfr.im/git/irc/rqf/shadowircd.git/blobdiff_plain/9802490cbbdd66a932dfc455d13c4178a39d4a24..7bab07d4d30245bf5ba272b236dc7b1c1e309c4d:/src/hash.c diff --git a/src/hash.c b/src/hash.c index 6f2bd65..561c7dc 100644 --- a/src/hash.c +++ b/src/hash.c @@ -26,7 +26,6 @@ #include "stdinc.h" #include "ircd_defs.h" -#include "tools.h" #include "s_conf.h" #include "channel.h" #include "client.h" @@ -36,16 +35,15 @@ #include "ircd.h" #include "numeric.h" #include "send.h" -#include "memory.h" #include "msg.h" #include "cache.h" #include "s_newconf.h" -dlink_list *clientTable; -dlink_list *channelTable; -dlink_list *idTable; -dlink_list *resvTable; -dlink_list *hostTable; +rb_dlink_list *clientTable; +rb_dlink_list *channelTable; +rb_dlink_list *idTable; +rb_dlink_list *resvTable; +rb_dlink_list *hostTable; /* * look in whowas.c for the missing ...[WW_MAX]; entry @@ -91,11 +89,11 @@ dlink_list *hostTable; void init_hash(void) { - clientTable = MyMalloc(sizeof(dlink_list) * U_MAX); - idTable = MyMalloc(sizeof(dlink_list) * U_MAX); - channelTable = MyMalloc(sizeof(dlink_list) * CH_MAX); - hostTable = MyMalloc(sizeof(dlink_list) * HOST_MAX); - resvTable = MyMalloc(sizeof(dlink_list) * R_MAX); + clientTable = rb_malloc(sizeof(rb_dlink_list) * U_MAX); + idTable = rb_malloc(sizeof(rb_dlink_list) * U_MAX); + channelTable = rb_malloc(sizeof(rb_dlink_list) * CH_MAX); + hostTable = rb_malloc(sizeof(rb_dlink_list) * HOST_MAX); + resvTable = rb_malloc(sizeof(rb_dlink_list) * R_MAX); } #ifndef RICER_HASHING @@ -109,7 +107,8 @@ fnv_hash_upper(const unsigned char *s, int bits) h ^= ToUpper(*s++); h += (h<<1) + (h<<4) + (h<<7) + (h << 8) + (h << 24); } - h = (h >> bits) ^ (h & ((2^bits)-1)); + if (bits < 32) + h = ((h >> bits) ^ h) & ((1<> bits) ^ (h & ((2^bits)-1)); + if (bits < 32) + h = ((h >> bits) ^ h) & ((1<> bits) ^ (h & ((2^bits)-1)); + if (bits < 32) + h = ((h >> bits) ^ h) & ((1<> bits) ^ (h & ((2^bits)-1)); + if (bits < 32) + h = ((h >> bits) ^ h) & ((1<data; @@ -404,7 +406,7 @@ struct Client * find_client(const char *name) { struct Client *target_p; - dlink_node *ptr; + rb_dlink_node *ptr; unsigned int hashv; s_assert(name != NULL); @@ -417,7 +419,7 @@ find_client(const char *name) hashv = hash_nick(name); - DLINK_FOREACH(ptr, clientTable[hashv].head) + RB_DLINK_FOREACH(ptr, clientTable[hashv].head) { target_p = ptr->data; @@ -436,7 +438,7 @@ struct Client * find_named_client(const char *name) { struct Client *target_p; - dlink_node *ptr; + rb_dlink_node *ptr; unsigned int hashv; s_assert(name != NULL); @@ -445,7 +447,7 @@ find_named_client(const char *name) hashv = hash_nick(name); - DLINK_FOREACH(ptr, clientTable[hashv].head) + RB_DLINK_FOREACH(ptr, clientTable[hashv].head) { target_p = ptr->data; @@ -464,7 +466,7 @@ struct Client * find_server(struct Client *source_p, const char *name) { struct Client *target_p; - dlink_node *ptr; + rb_dlink_node *ptr; unsigned int hashv; if(EmptyString(name)) @@ -479,7 +481,7 @@ find_server(struct Client *source_p, const char *name) hashv = hash_nick(name); - DLINK_FOREACH(ptr, clientTable[hashv].head) + RB_DLINK_FOREACH(ptr, clientTable[hashv].head) { target_p = ptr->data; @@ -493,11 +495,11 @@ find_server(struct Client *source_p, const char *name) /* find_hostname() * - * finds a hostname dlink list from the hostname hash table. - * we return the full dlink list, because you can have multiple + * finds a hostname rb_dlink list from the hostname hash table. + * we return the full rb_dlink list, because you can have multiple * entries with the same hostname */ -dlink_node * +rb_dlink_node * find_hostname(const char *hostname) { unsigned int hashv; @@ -518,7 +520,7 @@ struct Channel * find_channel(const char *name) { struct Channel *chptr; - dlink_node *ptr; + rb_dlink_node *ptr; unsigned int hashv; s_assert(name != NULL); @@ -527,7 +529,7 @@ find_channel(const char *name) hashv = hash_channel(name); - DLINK_FOREACH(ptr, channelTable[hashv].head) + RB_DLINK_FOREACH(ptr, channelTable[hashv].head) { chptr = ptr->data; @@ -553,7 +555,7 @@ struct Channel * get_or_create_channel(struct Client *client_p, const char *chname, int *isnew) { struct Channel *chptr; - dlink_node *ptr; + rb_dlink_node *ptr; unsigned int hashv; int len; const char *s = chname; @@ -579,7 +581,7 @@ get_or_create_channel(struct Client *client_p, const char *chname, int *isnew) hashv = hash_channel(s); - DLINK_FOREACH(ptr, channelTable[hashv].head) + RB_DLINK_FOREACH(ptr, channelTable[hashv].head) { chptr = ptr->data; @@ -596,11 +598,11 @@ get_or_create_channel(struct Client *client_p, const char *chname, int *isnew) chptr = allocate_channel(s); - dlinkAdd(chptr, &chptr->node, &global_channel_list); + rb_dlinkAdd(chptr, &chptr->node, &global_channel_list); - chptr->channelts = CurrentTime; /* doesn't hurt to set it here */ + chptr->channelts = rb_current_time(); /* doesn't hurt to set it here */ - dlinkAddAlloc(chptr, &channelTable[hashv]); + rb_dlinkAddAlloc(chptr, &channelTable[hashv]); return chptr; } @@ -613,7 +615,7 @@ struct ConfItem * hash_find_resv(const char *name) { struct ConfItem *aconf; - dlink_node *ptr; + rb_dlink_node *ptr; unsigned int hashv; s_assert(name != NULL); @@ -622,7 +624,7 @@ hash_find_resv(const char *name) hashv = hash_resv(name); - DLINK_FOREACH(ptr, resvTable[hashv].head) + RB_DLINK_FOREACH(ptr, resvTable[hashv].head) { aconf = ptr->data; @@ -640,8 +642,8 @@ void clear_resv_hash(void) { struct ConfItem *aconf; - dlink_node *ptr; - dlink_node *next_ptr; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; int i; HASH_WALK_SAFE(i, R_MAX, ptr, next_ptr, resvTable) @@ -653,7 +655,7 @@ clear_resv_hash(void) continue; free_conf(ptr->data); - dlinkDestroy(ptr, &resvTable[i]); + rb_dlinkDestroy(ptr, &resvTable[i]); } HASH_WALK_END } @@ -663,14 +665,16 @@ output_hash(struct Client *source_p, const char *name, int length, int *counts, { unsigned long total = 0; int i; + char buf[128]; sendto_one_numeric(source_p, RPL_STATSDEBUG, "B :%s Hash Statistics", name); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "B :Size: %d Empty: %d (%.3f%%)", - length, counts[0], + snprintf(buf, sizeof buf, "%.3f%%", (float) ((counts[0]*100) / (float) length)); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "B :Size: %d Empty: %d (%s)", + length, counts[0], buf); for(i = 1; i < 11; i++) { @@ -679,10 +683,14 @@ output_hash(struct Client *source_p, const char *name, int length, int *counts, /* dont want to divide by 0! --fl */ if(counts[0] != length) - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "B :Average depth: %.3f/%.3f Highest depth: %d", + { + snprintf(buf, sizeof buf, "%.3f/%.3f", (float) (total / (length - counts[0])), - (float) (total / length), deepest); + (float) (total / length)); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "B :Average depth: %s Highest depth: %d", + buf, deepest); + } for(i = 0; i < 11; i++) { @@ -694,7 +702,7 @@ output_hash(struct Client *source_p, const char *name, int length, int *counts, static void -count_hash(struct Client *source_p, dlink_list *table, int length, const char *name) +count_hash(struct Client *source_p, rb_dlink_list *table, int length, const char *name) { int counts[11]; int deepest = 0; @@ -704,13 +712,13 @@ count_hash(struct Client *source_p, dlink_list *table, int length, const char *n for(i = 0; i < length; i++) { - if(dlink_list_length(&table[i]) >= 10) + if(rb_dlink_list_length(&table[i]) >= 10) counts[10]++; else - counts[dlink_list_length(&table[i])]++; + counts[rb_dlink_list_length(&table[i])]++; - if(dlink_list_length(&table[i]) > deepest) - deepest = dlink_list_length(&table[i]); + if(rb_dlink_list_length(&table[i]) > deepest) + deepest = rb_dlink_list_length(&table[i]); } output_hash(source_p, name, length, counts, deepest);