/[svn]/ircd-hybrid/trunk/src/hash.c
ViewVC logotype

Diff of /ircd-hybrid/trunk/src/hash.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 9088 by michael, Sun Oct 13 09:52:35 2019 UTC revision 9089 by michael, Sun Oct 27 21:27:12 2019 UTC
# Line 41  Line 41 
41  #include "dbuf.h"  #include "dbuf.h"
42    
43    
 static unsigned int hashf_xor_key;  
   
44  /* The actual hash tables, They MUST be of the same HASHSIZE, variable  /* The actual hash tables, They MUST be of the same HASHSIZE, variable
45   * size tables could be supported but the rehash routine should also   * size tables could be supported but the rehash routine should also
46   * rebuild the transformation maps, I kept the tables of equal size   * rebuild the transformation maps, I kept the tables of equal size
# Line 53  static struct Client *clientTable[HASHSI Line 51  static struct Client *clientTable[HASHSI
51  static struct Channel *channelTable[HASHSIZE];  static struct Channel *channelTable[HASHSIZE];
52    
53    
 /* hash_init()  
  *  
  * inputs       - NONE  
  * output       - NONE  
  * side effects - Initialize the maps used by hash  
  *                functions and clear the tables  
  */  
 void  
 hash_init(void)  
 {  
   do  
     hashf_xor_key = genrand_int32() % 256;  /* better than nothing --adx */  
   while (!hashf_xor_key);  
 }  
   
54  /*  /*
55   * New hash function based on the Fowler/Noll/Vo (FNV) algorithm from   * New hash function based on the Fowler/Noll/Vo (FNV) algorithm from
56   * http://www.isthe.com/chongo/tech/comp/fnv/   * http://www.isthe.com/chongo/tech/comp/fnv/
# Line 78  hash_init(void) Line 61  hash_init(void)
61  unsigned int  unsigned int
62  strhash(const char *name)  strhash(const char *name)
63  {  {
64      static unsigned int hashf_xor_key = 0;
65    const unsigned char *p = (const unsigned char *)name;    const unsigned char *p = (const unsigned char *)name;
66    unsigned int hval = FNV1_32_INIT;    unsigned int hval = FNV1_32_INIT;
67    
68    if (EmptyString(p))    if (EmptyString(p))
69      return 0;      return 0;
70    
71      if (hashf_xor_key == 0)
72        do
73          hashf_xor_key = genrand_int32() % 256;  /* better than nothing --adx */
74        while (hashf_xor_key == 0);
75    
76    for (; *p; ++p)    for (; *p; ++p)
77    {    {
78      hval += (hval << 1) + (hval << 4) +      hval += (hval << 1) + (hval << 4) +
# Line 266  hash_find_client(const char *name) Line 255  hash_find_client(const char *name)
255    
256        while (prev = client_p, (client_p = client_p->hnext))        while (prev = client_p, (client_p = client_p->hnext))
257        {        {
258          if (!irccmp(name, client_p->name))          if (irccmp(name, client_p->name) == 0)
259          {          {
260            prev->hnext = client_p->hnext;            prev->hnext = client_p->hnext;
261            client_p->hnext = clientTable[hashv];            client_p->hnext = clientTable[hashv];
# Line 294  hash_find_id(const char *name) Line 283  hash_find_id(const char *name)
283    
284        while (prev = client_p, (client_p = client_p->idhnext))        while (prev = client_p, (client_p = client_p->idhnext))
285        {        {
286          if (!strcmp(name, client_p->id))          if (strcmp(name, client_p->id) == 0)
287          {          {
288            prev->idhnext = client_p->idhnext;            prev->idhnext = client_p->idhnext;
289            client_p->idhnext = idTable[hashv];            client_p->idhnext = idTable[hashv];
# Line 312  struct Client * Line 301  struct Client *
301  hash_find_server(const char *name)  hash_find_server(const char *name)
302  {  {
303    const unsigned int hashv = strhash(name);    const unsigned int hashv = strhash(name);
304    struct Client *client_p = NULL;    struct Client *client_p;
305    
306    if (IsDigit(*name) && strlen(name) == IRC_MAXSID)    if (IsDigit(*name) && strlen(name) == IRC_MAXSID)
307      return hash_find_id(name);      return hash_find_id(name);
# Line 327  hash_find_server(const char *name) Line 316  hash_find_server(const char *name)
316        while (prev = client_p, (client_p = client_p->hnext))        while (prev = client_p, (client_p = client_p->hnext))
317        {        {
318          if ((IsServer(client_p) || IsMe(client_p)) &&          if ((IsServer(client_p) || IsMe(client_p)) &&
319              !irccmp(name, client_p->name))              irccmp(name, client_p->name) == 0)
320          {          {
321            prev->hnext = client_p->hnext;            prev->hnext = client_p->hnext;
322            client_p->hnext = clientTable[hashv];            client_p->hnext = clientTable[hashv];
# Line 353  struct Channel * Line 342  struct Channel *
342  hash_find_channel(const char *name)  hash_find_channel(const char *name)
343  {  {
344    const unsigned int hashv = strhash(name);    const unsigned int hashv = strhash(name);
345    struct Channel *channel = NULL;    struct Channel *channel;
346    
347    if ((channel = channelTable[hashv]))    if ((channel = channelTable[hashv]))
348    {    {
# Line 363  hash_find_channel(const char *name) Line 352  hash_find_channel(const char *name)
352    
353        while (prev = channel, (channel = channel->hnextch))        while (prev = channel, (channel = channel->hnextch))
354        {        {
355          if (!irccmp(name, channel->name))          if (irccmp(name, channel->name) == 0)
356          {          {
357            prev->hnextch = channel->hnextch;            prev->hnextch = channel->hnextch;
358            channel->hnextch = channelTable[hashv];            channel->hnextch = channelTable[hashv];
# Line 557  void Line 546  void
546  safe_list_channels(struct Client *source_p, bool only_unmasked_channels)  safe_list_channels(struct Client *source_p, bool only_unmasked_channels)
547  {  {
548    struct ListTask *const lt = source_p->connection->list_task;    struct ListTask *const lt = source_p->connection->list_task;
549    struct Channel *channel = NULL;    struct Channel *channel;
550    
551    if (only_unmasked_channels == false)    if (only_unmasked_channels == false)
552    {    {

Legend:
Removed from v.9088  
changed lines
  Added in v.9089

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28