Hash Class Reference

The Hash class handles minimal perfect hashing. More...

Inheritance diagram for Hash:

List of all members.


Public Member Functions

 Hash (FILE *file, char *memoryPool, long int *offset)
 ~Hash ()
int getIndex (int *w)

Public Attributes

int randomTableLength
int nrOfSamples
int gLength
int * random1
int * random2
int * gTable
int depth
bool doMemoryMapping

Detailed Description

The Hash class handles minimal perfect hashing.

The theory from: ["An Optimal Algorithm for Generating Minimal Perfect Hash Functions", Z.J. Czech, G. Havas and B.S. Majewski]. is used to construct and use the hash function. This class only loads, stores and uses the hash function. The class TrainHash is able to create new hash functions.

The implementation of Hash is fine tuned for use in the shout software package. It is possible to query for data slots with as key either a bigram, a trigram or 4-gram. (getIndex with *w different length, depending on how it is trained).


Constructor & Destructor Documentation

Hash::Hash ( FILE *  file,
char *  memoryPool,
long int *  offset 
)

This constructor will load the hash function.

References depth, doMemoryMapping, WriteFileLittleBigEndian::freadEndianSafe(), gLength, gTable, nrOfSamples, random1, random2, and randomTableLength.

Here is the call graph for this function:

Hash::~Hash (  ) 

The destructor deletes the data needed for the hash function.

References doMemoryMapping, gTable, random1, and random2.


Member Function Documentation

int Hash::getIndex ( int *  w  ) 

Query for a data slot index given a key of depth 'depth' (w is a pointer to int[depth]). The user is responsible for checking if the returned index is valid. (Because this is a minimal perfect hash, all slots will contain data. If a non-existing key is queried, it will be randomly mapped to an existing slot.)

Reimplemented in TrainHash.

References depth, gLength, gTable, nrOfSamples, random1, random2, and randomTableLength.

Referenced by LanguageModel::checkValidity(), LanguageModel::get4GramIndex(), LanguageModel::getAllP(), LanguageModel::getBiGramIndex(), and LanguageModel::getTriGramIndex().


Member Data Documentation

Referenced by Hash(), and ~Hash().