]> jfr.im git - solanum.git/blobdiff - ircd/hash.c
Add a comment explaining match_arrange_stars
[solanum.git] / ircd / hash.c
index 396b00c62be8f0f4e267ce9667e8253609b610d7..cd8e8aa8dc31c4262bf7f167d21b0d548f5f6d75 100644 (file)
@@ -27,7 +27,6 @@
 #include "s_conf.h"
 #include "channel.h"
 #include "client.h"
-#include "common.h"
 #include "hash.h"
 #include "match.h"
 #include "ircd.h"
 #include "cache.h"
 #include "s_newconf.h"
 #include "s_assert.h"
-#include "irc_dictionary.h"
-#include "irc_radixtree.h"
+#include "rb_dictionary.h"
+#include "rb_radixtree.h"
 
-struct Dictionary *client_connid_tree = NULL;
-struct Dictionary *client_zconnid_tree = NULL;
-struct irc_radixtree *client_id_tree = NULL;
-struct irc_radixtree *client_name_tree = NULL;
+rb_dictionary *client_connid_tree = NULL;
+rb_radixtree *client_id_tree = NULL;
+rb_radixtree *client_name_tree = NULL;
 
-struct irc_radixtree *channel_tree = NULL;
-struct irc_radixtree *resv_tree = NULL;
-struct irc_radixtree *hostname_tree = NULL;
+rb_radixtree *channel_tree = NULL;
+rb_radixtree *resv_tree = NULL;
+rb_radixtree *hostname_tree = NULL;
 
 /*
  * look in whowas.c for the missing ...[WW_MAX]; entry
@@ -60,25 +58,24 @@ struct irc_radixtree *hostname_tree = NULL;
 void
 init_hash(void)
 {
-       client_connid_tree = irc_dictionary_create("client connid", irc_uint32cmp);
-       client_zconnid_tree = irc_dictionary_create("client zconnid", irc_uint32cmp);
-       client_id_tree = irc_radixtree_create("client id", NULL);
-       client_name_tree = irc_radixtree_create("client name", irc_radixtree_irccasecanon);
+       client_connid_tree = rb_dictionary_create("client connid", rb_uint32cmp);
+       client_id_tree = rb_radixtree_create("client id", NULL);
+       client_name_tree = rb_radixtree_create("client name", irccasecanon);
 
-       channel_tree = irc_radixtree_create("channel", irc_radixtree_irccasecanon);
-       resv_tree = irc_radixtree_create("resv", irc_radixtree_irccasecanon);
+       channel_tree = rb_radixtree_create("channel", irccasecanon);
+       resv_tree = rb_radixtree_create("resv", irccasecanon);
 
-       hostname_tree = irc_radixtree_create("hostname", irc_radixtree_irccasecanon);
+       hostname_tree = rb_radixtree_create("hostname", irccasecanon);
 }
 
-u_int32_t
+uint32_t
 fnv_hash_upper(const unsigned char *s, int bits)
 {
-       u_int32_t h = FNV1_32_INIT;
+       uint32_t h = FNV1_32_INIT;
 
        while (*s)
        {
-               h ^= ToUpper(*s++);
+               h ^= irctoupper(*s++);
                h += (h<<1) + (h<<4) + (h<<7) + (h << 8) + (h << 24);
        }
        if (bits < 32)
@@ -86,10 +83,10 @@ fnv_hash_upper(const unsigned char *s, int bits)
        return h;
 }
 
-u_int32_t
+uint32_t
 fnv_hash(const unsigned char *s, int bits)
 {
-       u_int32_t h = FNV1_32_INIT;
+       uint32_t h = FNV1_32_INIT;
 
        while (*s)
        {
@@ -101,10 +98,10 @@ fnv_hash(const unsigned char *s, int bits)
        return h;
 }
 
-u_int32_t
+uint32_t
 fnv_hash_len(const unsigned char *s, int bits, int len)
 {
-       u_int32_t h = FNV1_32_INIT;
+       uint32_t h = FNV1_32_INIT;
        const unsigned char *x = s + len;
        while (*s && s < x)
        {
@@ -116,14 +113,14 @@ fnv_hash_len(const unsigned char *s, int bits, int len)
        return h;
 }
 
-u_int32_t
+uint32_t
 fnv_hash_upper_len(const unsigned char *s, int bits, int len)
 {
-       u_int32_t h = FNV1_32_INIT;
+       uint32_t h = FNV1_32_INIT;
        const unsigned char *x = s + len;
        while (*s && s < x)
        {
-               h ^= ToUpper(*s++);
+               h ^= irctoupper(*s++);
                h += (h<<1) + (h<<4) + (h<<7) + (h << 8) + (h << 24);
        }
        if (bits < 32)
@@ -141,7 +138,7 @@ add_to_id_hash(const char *name, struct Client *client_p)
        if(EmptyString(name) || (client_p == NULL))
                return;
 
-       irc_radixtree_add(client_id_tree, name, client_p);
+       rb_radixtree_add(client_id_tree, name, client_p);
 }
 
 /* add_to_client_hash()
@@ -156,7 +153,7 @@ add_to_client_hash(const char *name, struct Client *client_p)
        if(EmptyString(name) || (client_p == NULL))
                return;
 
-       irc_radixtree_add(client_name_tree, name, client_p);
+       rb_radixtree_add(client_name_tree, name, client_p);
 }
 
 /* add_to_hostname_hash()
@@ -173,7 +170,7 @@ add_to_hostname_hash(const char *hostname, struct Client *client_p)
        if(EmptyString(hostname) || (client_p == NULL))
                return;
 
-       list = irc_radixtree_retrieve(hostname_tree, hostname);
+       list = rb_radixtree_retrieve(hostname_tree, hostname);
        if (list != NULL)
        {
                rb_dlinkAddAlloc(client_p, list);
@@ -181,7 +178,7 @@ add_to_hostname_hash(const char *hostname, struct Client *client_p)
        }
 
        list = rb_malloc(sizeof(*list));
-       irc_radixtree_add(hostname_tree, hostname, list);
+       rb_radixtree_add(hostname_tree, hostname, list);
        rb_dlinkAddAlloc(client_p, list);
 }
 
@@ -197,7 +194,7 @@ add_to_resv_hash(const char *name, struct ConfItem *aconf)
        if(EmptyString(name) || aconf == NULL)
                return;
 
-       irc_radixtree_add(resv_tree, name, aconf);
+       rb_radixtree_add(resv_tree, name, aconf);
 }
 
 /* del_from_id_hash()
@@ -212,7 +209,7 @@ del_from_id_hash(const char *id, struct Client *client_p)
        if(EmptyString(id) || client_p == NULL)
                return;
 
-       irc_radixtree_delete(client_id_tree, id);
+       rb_radixtree_delete(client_id_tree, id);
 }
 
 /* del_from_client_hash()
@@ -228,7 +225,7 @@ del_from_client_hash(const char *name, struct Client *client_p)
        if(EmptyString(name) || client_p == NULL)
                return;
 
-       irc_radixtree_delete(client_name_tree, name);
+       rb_radixtree_delete(client_name_tree, name);
 }
 
 /* del_from_channel_hash()
@@ -244,7 +241,7 @@ del_from_channel_hash(const char *name, struct Channel *chptr)
        if(EmptyString(name) || chptr == NULL)
                return;
 
-       irc_radixtree_delete(channel_tree, name);
+       rb_radixtree_delete(channel_tree, name);
 }
 
 /* del_from_hostname_hash()
@@ -259,7 +256,7 @@ del_from_hostname_hash(const char *hostname, struct Client *client_p)
        if(hostname == NULL || client_p == NULL)
                return;
 
-       list = irc_radixtree_retrieve(hostname_tree, hostname);
+       list = rb_radixtree_retrieve(hostname_tree, hostname);
        if (list == NULL)
                return;
 
@@ -267,7 +264,7 @@ del_from_hostname_hash(const char *hostname, struct Client *client_p)
 
        if (rb_dlink_list_length(list) == 0)
        {
-               irc_radixtree_delete(hostname_tree, hostname);
+               rb_radixtree_delete(hostname_tree, hostname);
                rb_free(list);
        }
 }
@@ -284,7 +281,7 @@ del_from_resv_hash(const char *name, struct ConfItem *aconf)
        if(EmptyString(name) || aconf == NULL)
                return;
 
-       irc_radixtree_delete(resv_tree, name);
+       rb_radixtree_delete(resv_tree, name);
 }
 
 /* find_id()
@@ -297,7 +294,7 @@ find_id(const char *name)
        if(EmptyString(name))
                return NULL;
 
-       return irc_radixtree_retrieve(client_id_tree, name);
+       return rb_radixtree_retrieve(client_id_tree, name);
 }
 
 /* find_client()
@@ -315,7 +312,7 @@ find_client(const char *name)
        if(IsDigit(*name))
                return (find_id(name));
 
-       return irc_radixtree_retrieve(client_name_tree, name);
+       return rb_radixtree_retrieve(client_name_tree, name);
 }
 
 /* find_named_client()
@@ -329,7 +326,7 @@ find_named_client(const char *name)
        if(EmptyString(name))
                return NULL;
 
-       return irc_radixtree_retrieve(client_name_tree, name);
+       return rb_radixtree_retrieve(client_name_tree, name);
 }
 
 /* find_server()
@@ -351,7 +348,7 @@ find_server(struct Client *source_p, const char *name)
                return(target_p);
        }
 
-       target_p = irc_radixtree_retrieve(client_name_tree, name);
+       target_p = rb_radixtree_retrieve(client_name_tree, name);
        if (target_p != NULL)
        {
                if(IsServer(target_p) || IsMe(target_p))
@@ -375,7 +372,7 @@ find_hostname(const char *hostname)
        if(EmptyString(hostname))
                return NULL;
 
-       hlist = irc_radixtree_retrieve(hostname_tree, hostname);
+       hlist = rb_radixtree_retrieve(hostname_tree, hostname);
        if (hlist == NULL)
                return NULL;
 
@@ -393,7 +390,7 @@ find_channel(const char *name)
        if(EmptyString(name))
                return NULL;
 
-       return irc_radixtree_retrieve(channel_tree, name);
+       return rb_radixtree_retrieve(channel_tree, name);
 }
 
 /*
@@ -408,7 +405,7 @@ find_channel(const char *name)
  *  block, if it didn't exist before).
  */
 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, bool *isnew)
 {
        struct Channel *chptr;
        int len;
@@ -429,26 +426,26 @@ get_or_create_channel(struct Client *client_p, const char *chname, int *isnew)
                }
                len = CHANNELLEN;
                t = LOCAL_COPY(s);
-               *(t + CHANNELLEN) = '\0';
+               t[len] = '\0';
                s = t;
        }
 
-       chptr = irc_radixtree_retrieve(channel_tree, s);
+       chptr = rb_radixtree_retrieve(channel_tree, s);
        if (chptr != NULL)
        {
                if (isnew != NULL)
-                       *isnew = 0;
+                       *isnew = false;
                return chptr;
        }
 
        if(isnew != NULL)
-               *isnew = 1;
+               *isnew = true;
 
        chptr = allocate_channel(s);
        chptr->channelts = rb_current_time();   /* doesn't hurt to set it here */
 
        rb_dlinkAdd(chptr, &chptr->node, &global_channel_list);
-       irc_radixtree_add(channel_tree, chptr->chname, chptr);
+       rb_radixtree_add(channel_tree, chptr->chname, chptr);
 
        return chptr;
 }
@@ -466,7 +463,7 @@ hash_find_resv(const char *name)
        if(EmptyString(name))
                return NULL;
 
-       aconf = irc_radixtree_retrieve(resv_tree, name);
+       aconf = rb_radixtree_retrieve(resv_tree, name);
        if (aconf != NULL)
        {
                aconf->port++;
@@ -480,55 +477,33 @@ void
 clear_resv_hash(void)
 {
        struct ConfItem *aconf;
-       struct irc_radixtree_iteration_state iter;
+       rb_radixtree_iteration_state iter;
 
-       IRC_RADIXTREE_FOREACH(aconf, &iter, resv_tree)
+       RB_RADIXTREE_FOREACH(aconf, &iter, resv_tree)
        {
                /* skip temp resvs */
                if(aconf->hold)
                        continue;
 
-               irc_radixtree_delete(resv_tree, aconf->host);
+               rb_radixtree_delete(resv_tree, aconf->host);
                free_conf(aconf);
        }
 }
 
 void
-add_to_zconnid_hash(struct Client *client_p)
+add_to_cli_connid_hash(struct Client *client_p, uint32_t id)
 {
-       irc_dictionary_add(client_zconnid_tree, IRC_UINT_TO_POINTER(client_p->localClient->zconnid), client_p);
+       rb_dictionary_add(client_connid_tree, RB_UINT_TO_POINTER(id), client_p);
 }
 
 void
-del_from_zconnid_hash(struct Client *client_p)
+del_from_cli_connid_hash(uint32_t id)
 {
-       irc_dictionary_delete(client_zconnid_tree, IRC_UINT_TO_POINTER(client_p->localClient->zconnid));
-}
-
-void
-add_to_cli_connid_hash(struct Client *client_p)
-{
-       irc_dictionary_add(client_connid_tree, IRC_UINT_TO_POINTER(client_p->localClient->connid), client_p);
-}
-
-void
-del_from_cli_connid_hash(struct Client *client_p)
-{
-       irc_dictionary_delete(client_connid_tree, IRC_UINT_TO_POINTER(client_p->localClient->connid));
+       rb_dictionary_delete(client_connid_tree, RB_UINT_TO_POINTER(id));
 }
 
 struct Client *
 find_cli_connid_hash(uint32_t connid)
 {
-       struct Client *target_p;
-
-       target_p = irc_dictionary_retrieve(client_connid_tree, IRC_UINT_TO_POINTER(connid));
-       if (target_p != NULL)
-               return target_p;
-
-       target_p = irc_dictionary_retrieve(client_zconnid_tree, IRC_UINT_TO_POINTER(connid));
-       if (target_p != NULL)
-               return target_p;
-
-       return NULL;
+       return rb_dictionary_retrieve(client_connid_tree, RB_UINT_TO_POINTER(connid));
 }