X-Git-Url: https://jfr.im/git/irc/rqf/shadowircd.git/blobdiff_plain/f42e9cebeea0101a5193ca6ac0c5a7689d49f95b..af81d5a0b09446188fd6f9c292b51519f2c1cedd:/src/hash.c diff --git a/src/hash.c b/src/hash.c index 95efc55..9c0e7ec 100644 --- a/src/hash.c +++ b/src/hash.c @@ -41,13 +41,11 @@ #include "cache.h" #include "s_newconf.h" -dlink_list *clientTable; -dlink_list *channelTable; -dlink_list *idTable; -dlink_list *resvTable; -dlink_list *hostTable; -dlink_list *helpTable; -dlink_list *ndTable; +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 @@ -93,13 +91,11 @@ dlink_list *ndTable; void init_hash(void) { - clientTable = MyMalloc(sizeof(dlink_list) * U_MAX); - idTable = MyMalloc(sizeof(dlink_list) * U_MAX); - ndTable = 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); - helpTable = MyMalloc(sizeof(dlink_list) * HELP_MAX); + clientTable = MyMalloc(sizeof(rb_dlink_list) * U_MAX); + idTable = MyMalloc(sizeof(rb_dlink_list) * U_MAX); + channelTable = MyMalloc(sizeof(rb_dlink_list) * CH_MAX); + hostTable = MyMalloc(sizeof(rb_dlink_list) * HOST_MAX); + resvTable = MyMalloc(sizeof(rb_dlink_list) * R_MAX); } #ifndef RICER_HASHING @@ -113,7 +109,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<hashv = hash_nick(name); - dlinkAdd(nd, &nd->hnode, &ndTable[nd->hashv]); + rb_dlinkAddAlloc(aconf, &resvTable[hashv]); } /* del_from_id_hash() @@ -328,7 +296,7 @@ del_from_id_hash(const char *id, struct Client *client_p) return; hashv = hash_id(id); - dlinkFindDestroy(client_p, &idTable[hashv]); + rb_dlinkFindDestroy(client_p, &idTable[hashv]); } /* del_from_client_hash() @@ -347,7 +315,7 @@ del_from_client_hash(const char *name, struct Client *client_p) return; hashv = hash_nick(name); - dlinkFindDestroy(client_p, &clientTable[hashv]); + rb_dlinkFindDestroy(client_p, &clientTable[hashv]); } /* del_from_channel_hash() @@ -366,7 +334,7 @@ del_from_channel_hash(const char *name, struct Channel *chptr) return; hashv = hash_channel(name); - dlinkFindDestroy(chptr, &channelTable[hashv]); + rb_dlinkFindDestroy(chptr, &channelTable[hashv]); } /* del_from_hostname_hash() @@ -383,7 +351,7 @@ del_from_hostname_hash(const char *hostname, struct Client *client_p) hashv = hash_hostname(hostname); - dlinkFindDestroy(client_p, &hostTable[hashv]); + rb_dlinkFindDestroy(client_p, &hostTable[hashv]); } /* del_from_resv_hash() @@ -402,22 +370,7 @@ del_from_resv_hash(const char *name, struct ConfItem *aconf) hashv = hash_resv(name); - dlinkFindDestroy(aconf, &resvTable[hashv]); -} - -void -clear_help_hash(void) -{ - dlink_node *ptr; - dlink_node *next_ptr; - int i; - - HASH_WALK_SAFE(i, HELP_MAX, ptr, next_ptr, helpTable) - { - free_cachefile(ptr->data); - dlinkDestroy(ptr, &helpTable[i]); - } - HASH_WALK_END + rb_dlinkFindDestroy(aconf, &resvTable[hashv]); } /* find_id() @@ -428,7 +381,7 @@ struct Client * find_id(const char *name) { struct Client *target_p; - dlink_node *ptr; + rb_dlink_node *ptr; unsigned int hashv; if(EmptyString(name)) @@ -455,7 +408,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); @@ -487,7 +440,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); @@ -515,7 +468,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)) @@ -544,11 +497,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; @@ -569,7 +522,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); @@ -604,7 +557,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; @@ -647,11 +600,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 */ - dlinkAddAlloc(chptr, &channelTable[hashv]); + rb_dlinkAddAlloc(chptr, &channelTable[hashv]); return chptr; } @@ -664,7 +617,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); @@ -687,36 +640,12 @@ hash_find_resv(const char *name) return NULL; } -struct cachefile * -hash_find_help(const char *name, int flags) -{ - struct cachefile *hptr; - dlink_node *ptr; - unsigned int hashv; - - if(EmptyString(name)) - return NULL; - - hashv = hash_help(name); - - DLINK_FOREACH(ptr, helpTable[hashv].head) - { - hptr = ptr->data; - - if((irccmp(name, hptr->name) == 0) && - (hptr->flags & flags)) - return hptr; - } - - return NULL; -} - 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) @@ -728,34 +657,11 @@ clear_resv_hash(void) continue; free_conf(ptr->data); - dlinkDestroy(ptr, &resvTable[i]); + rb_dlinkDestroy(ptr, &resvTable[i]); } HASH_WALK_END } -struct nd_entry * -hash_find_nd(const char *name) -{ - struct nd_entry *nd; - dlink_node *ptr; - unsigned int hashv; - - if(EmptyString(name)) - return NULL; - - hashv = hash_nick(name); - - DLINK_FOREACH(ptr, ndTable[hashv].head) - { - nd = ptr->data; - - if(!irccmp(name, nd->name)) - return nd; - } - - return NULL; -} - static void output_hash(struct Client *source_p, const char *name, int length, int *counts, int deepest) { @@ -792,7 +698,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; @@ -802,13 +708,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);