#ifndef HASH_METHODS_H_INCLUDED
#define HASH_METHODS_H_INCLUDED
/*****************************************************************************/
/* HEADER FILE */
/*****************************************************************************/
/*
$Archive: $
$Revision: $
$Date: $
$Author: $
Description: Declaration of the class that contains a collection of
hashing functions
TOOL And XML FORMS License
==========================
Except where otherwise noted, all of the documentation
and software included in the TOOL package is
copyrighted by Michael Swartzendruber.
Copyright (C) 2005 Michael John Swartzendruber.
All rights reserved.
Access to this code, whether intentional or accidental,
does NOT IMPLY any transfer of rights.
This software is provided "as-is," without any express
or implied warranty. In no event shall the author be held
liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for
any purpose, including commercial applications, and to
alter and redistribute it, provided that the following
conditions are met:
1. All redistributions of source code files must retain
all copyright notices that are currently in place,
and this list of conditions without modification.
2. The origin of this software must not be misrepresented;
you must not claim that you wrote the original software.
3. If you use this software in another product, an acknowledgment
in the product documentation would be appreciated but is
not required.
4. Modified versions in source or binary form must be plainly
marked as such, and must not be misrepresented as being
the original software.
*/
/*****************************************************************************/
#define CHAR_BIT 8
#define BITS_IN_AN_INT ( sizeof( int ) * CHAR_BIT )
#define THREE_QUARTERS ( (int) ( (BITS_IN_AN_INT * 3 ) / 4) )
#define ONE_EIGHTH ( (int) ( BITS_IN_AN_INT / 8 ) )
#define HIGH_BITS ( ~( (unsigned int) (~0) >> ONE_EIGHTH ) )
class CharHashes
{
public:
CharHashes( void ){ GenerateTable(); };
~CharHashes( void ){;};
unsigned long JenkinsHash( const unsigned char* pchKey,
unsigned long lLength,
unsigned long lSeed );
unsigned long WeinbergerHash( const unsigned char* pchKey );
unsigned long ElfHash( const unsigned char* pchKey );
unsigned long TypicalHash( const unsigned char* pchKey,
unsigned long lPrime );
unsigned long AdditiveHash( const unsigned char* pchKey,
unsigned long lLength,
unsigned long lPrime );
unsigned long RotatingHash( const unsigned char* pchKey,
unsigned long lLength,
unsigned long lPrime );
unsigned long CRCHash( const unsigned char* pchKey,
unsigned long lLength,
unsigned long lMask );
unsigned long UniversalHash( const unsigned char* pchKey,
unsigned long lLength,
unsigned long lMask );
unsigned long ZobristHash( const unsigned char* pchKey,
unsigned long lLength,
unsigned long lMask );
unsigned long PearsonHash( const unsigned char* pchKey,
unsigned long lLength );
protected:
unsigned long MaxHashSize( unsigned long ulN );
unsigned long MakeMask( unsigned long ulN );
private:
unsigned long CRCHash( const unsigned char* pchKey,
unsigned long lLength,
unsigned long lMask,
unsigned long laTable[ 256 ] );
unsigned long UniversalHash( const unsigned char* pchKey,
unsigned long lLength,
unsigned long lMask,
unsigned long laTable[ CHAR_BIT ] );
unsigned long ZobristHash( const unsigned char* pchKey,
unsigned long lLength,
unsigned long lMask,
unsigned long laTable[ CHAR_BIT ][ 256 ] );
unsigned long PearsonHash( const unsigned char* pchKey,
unsigned long lLength,
const unsigned long achTable[ 256 ] );
void GenerateTable( void );
void MixBits( unsigned long& rulA, unsigned long& rulB, unsigned long& rulC );
private:
unsigned long m_CRCTable[ CHAR_BIT ][ 256 ];
};
#endif
/*****************************************************************************/
/* Check-in history */
/*
*$Log: $
*/
/*****************************************************************************/