// file: hash_table.h
//
// this is the header file for the Hash_table class
//

// The hash function we use here converts the key to an integer,
// divided by the size of the index range and take the reminder as the
// result.  The size is often a prime number to get the affect of
// spreading the keys quite uniformly.  We usually hope that the index
// obtained from the keys can achieve a good spread (uniform); and at
// the same time ensure that the result is in the proper range and
// with few collisions. The larger the number of values to be stored
// in a hash table, larger is the size needed. For instance, there are
// more than 20,000 words to be hashed in a SWITCHBOARD application.
//

// make sure definitions are made only once
//
#ifndef __ISIP_HASH_TABLE
#define __ISIP_HASH_TABLE

// isip include files
//
#ifndef __ISIP_HASH_CELL
#include <hash_cell.h>
#endif

#ifndef __HASH_TABLE_CONSTANTS
#include "hash_table_constants.h"
#endif

// Hash_table: a class that defines a hash table of objects
//

class Hash_table {

  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
protected:

  // contents of the hash_table
  //
  Hash_cell** cells_d;                 // the hash_cell stored in hash_table 
  int_4 size_d;                         // size of the hash table
  char_1 mode_d;

  //---------------------------------------------------------------------------
  //
  // public methods
  //
  //---------------------------------------------------------------------------
public:

  // required methods
  //
  char_1* name_cc();
  volatile void error_handler_cc(char_1* mname, char_1* msg);
  logical_1 debug_cc(FILE *fp, char_1* message);
  int_4 size_cc();
  
  // destructors/constructors
  //
  ~Hash_table();                                 // destructor
  Hash_table(char_1 mode = HASH_TABLE_DEF_MODE);        // default
  Hash_table(int_4 num, char_1 mode = HASH_TABLE_DEF_MODE); // overloaded
  Hash_table(Hash_table& table);                 // copy

  // set methods
  //
  logical_1 set_size_cc(int_4 size);
  logical_1 set_cells_cc(Hash_cell** cells_a);

  // get methods
  //
  int_4 get_size_cc() {
    return size_d;
  }
  
  int_4 get_num_cells_cc();

  Hash_cell** get_cells_cc() {
    return cells_d;
  }
 
  // hash table insert methods
  //
  Hash_cell* hash_insert_cc(Hash_cell* hash_cell);

  // hash table lookup methods
  //
  Hash_cell* hash_lookup_cc(char_1* str) {
    int_4 index = (int_4)0;
    return hash_lookup_cc(str, index);
  }
  
  Hash_cell* hash_lookup_cc(char_1* str, int_4& index);
  
  Hash_cell* hash_lookup_cc(int_4* vec, int_4 size) {
    int_4 index = (int_4)0;
    return (hash_lookup_cc(vec, size, index));
  }
  Hash_cell* hash_lookup_cc(int_4* vec, int_4 size, int_4& index);
  
  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
private:

  // hash table index method for string entry
  //
  int_4 hash_string_cc(char_1* str);
 
  // hash table index method for vector entry
  //
  int_4 hash_vector_cc(int_4* vec, int_4 size);
 
};

// end of file
//
# endif
