ackfuss-4.4.0/board/
ackfuss-4.4.0/help/e/
ackfuss-4.4.0/help/f/
ackfuss-4.4.0/help/h/
ackfuss-4.4.0/help/l/
ackfuss-4.4.0/help/n/
ackfuss-4.4.0/help/q/
ackfuss-4.4.0/help/s/
ackfuss-4.4.0/help/u/
ackfuss-4.4.0/help/v/
ackfuss-4.4.0/help/y/
ackfuss-4.4.0/help/z/
ackfuss-4.4.0/player/c/
/***************************************************************************
 * _/_/_/_/  _/    _/  _/_/_/_/ _/_/_/_/ AckFUSS is modified ACK!MUD 4.3.1 *
 * _/        _/    _/  _/       _/       copyright Matt Goff (Kline) 2008  *
 * _/_/      _/    _/  _/_/_/_/ _/_/_/_/                                   *
 * _/        _/    _/        _/       _/ Support for this code is provided *
 * _/        _/_/_/_/  _/_/_/_/ _/_/_/_/ at www.ackmud.net -- check it out!*
 ***************************************************************************/

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "globals.h"
#include "hash.h"

#ifndef DEC_DB_H
#include "h/db.h"
#endif

/*
 * Deals with generic hashing tables.
 */


void *get_hash_entry( hash_table * hash_head, int key )
{
   int a;
   HASH_ENTRY *rvalue;
   HASH_ENTRY **hash_table;

   a = key % hash_head->max_hash;
   hash_table = hash_head->table;


   for( rvalue = hash_table[a]; rvalue != NULL; rvalue = rvalue->next )
      if( rvalue->key == key )
         break;

   if( rvalue != NULL )
      return rvalue->reference;
   else
      return NULL;
}

void add_hash_entry( hash_table * hash_head, int key, void *entry )
{
   int a;
   HASH_ENTRY *temp;
   HASH_ENTRY **hash_table;

   a = key % hash_head->max_hash;
   hash_table = hash_head->table;

   temp = new HASH_ENTRY;
   temp->key = key;
   temp->reference = entry;
   temp->next = hash_table[a];

   hash_table[a] = temp;
}

void del_hash_entry( hash_table * hash_head, int key )
{
   int a;
   HASH_ENTRY *prev_entry;
   HASH_ENTRY *search_entry;
   HASH_ENTRY **hash_table;

   a = key % hash_head->max_hash;
   hash_table = hash_head->table;

   prev_entry = NULL;
   for( search_entry = hash_table[a]; search_entry != NULL; search_entry = search_entry->next )
   {
      if( search_entry->key == key )
         break;
      prev_entry = search_entry;
   }

   if( search_entry != NULL )
   {
      if( prev_entry == NULL )
         hash_table[a] = NULL;
      else
         prev_entry->next = search_entry->next;
      delete search_entry;
   }
}

hash_table *create_hash_table( int max_hash )
{
   int a;
   hash_table *hash_head;
   HASH_ENTRY **hash_table;

   hash_table = (HASH_ENTRY **)getmem( sizeof( HASH_ENTRY * ) * max_hash );
   hash_head = (struct hash_table_tp *)getmem( sizeof( struct hash_table_tp ) );

   hash_head->max_hash = max_hash;
   hash_head->table = hash_table;

   for( a = 0; a < max_hash; a++ )
      hash_table[a] = NULL;

   return hash_head;

}

void clear_hash_table( hash_table * hash_head )
{
   int a;
   HASH_ENTRY *entry, *next_entry;
   HASH_ENTRY **hash_table;

   hash_table = hash_head->table;

   for( a = 0; a < hash_head->max_hash; a++ )
   {
      if( hash_table[a] != NULL )
      {
         for( entry = hash_table[a]; entry != NULL; entry = next_entry )
         {
            next_entry = entry->next;
            delete entry;
         }
         hash_table[a] = NULL;
      }
   }
}

void delete_hash_table( hash_table * hash_head )
{

   int a;
   HASH_ENTRY *entry, *next_entry;
   HASH_ENTRY **hash_table;
   hash_table = hash_head->table;

   for( a = 0; a < hash_head->max_hash; a++ )
   {
      if( hash_table[a] != NULL )
      {
         for( entry = hash_table[a]; entry != NULL; entry = next_entry )
         {
            next_entry = entry->next;
            delete entry;
         }
         hash_table[a] = NULL;
      }
   }
   dispose( hash_table, sizeof( HASH_ENTRY * ) * hash_head->max_hash );
   dispose( hash_head, sizeof( *hash_head ) );
}