TRF Language Model
wb-lhash.h File Reference

linear hash, using 'open address' to handle collision More...

#include <iostream>
#include <cstring>
#include <cmath>

Go to the source code of this file.

Classes

class  wb::LHash< KeyT, DataT >
 a linear hash table More...
 
class  wb::LHashIter< KeyT, DataT >
 the iter of LHash More...
 
class  wb::LHash< KeyT, DataT >
 a linear hash table More...
 
struct  wb::LHash< KeyT, DataT >::Unit
 the Unit of hash More...
 
class  wb::LHashIter< KeyT, DataT >
 the iter of LHash More...
 

Namespaces

 wb
 define all the code written by Bin Wang.
 

Macros

#define Bit2Size(bits)   ( (int)(1<<(bits)) )
 
#define HashMask(nbits)   (~((~0L)<<(nbits)))
 

Functions

template<class KeyT >
KeyT wb::Map_copyKey (KeyT key)
 Copy a key. More...
 
const char * wb::Map_copyKey (const char *key)
 Copy a string key. More...
 
template<class KeyT >
void wb::Map_freeKey (KeyT key)
 Free a key. More...
 
void wb::Map_freeKey (const char *key)
 Free a key, if the key is string. More...
 
set key to no-key
template<class KeyT >
void wb::Map_noKey (KeyT *&key)
 
void wb::Map_noKey (int &key)
 
void wb::Map_noKey (short int &key)
 
void wb::Map_noKey (long int &key)
 
void wb::Map_noKey (long long &key)
 
void wb::Map_noKey (unsigned &key)
 
void wb::Map_noKey (short unsigned &key)
 
void wb::Map_noKey (long unsigned &key)
 
void wb::Map_noKey (float &key)
 
void wb::Map_noKey (double &key)
 
no-key detection

detect if the key is no-key

template<class KeyT >
bool wb::Map_noKeyP (KeyT *key)
 
bool wb::Map_noKeyP (int key)
 
bool wb::Map_noKeyP (short int key)
 
bool wb::Map_noKeyP (long int key)
 
bool wb::Map_noKeyP (long long key)
 
bool wb::Map_noKeyP (unsigned key)
 
bool wb::Map_noKeyP (short unsigned key)
 
bool wb::Map_noKeyP (long unsigned key)
 
bool wb::Map_noKeyP (float key)
 
bool wb::Map_noKeyP (double &key)
 
Compare two Keys

Return if the input keys are equal.

template<class KeyT >
bool wb::Map_equalKey (KeyT key1, KeyT key2)
 
bool wb::Map_equalKey (float key1, float key2)
 
bool wb::Map_equalKey (double key1, double key2)
 
bool wb::Map_equalKey (const char *pStr1, const char *pStr2)
 
HashKey

Hashing functions. (We provide versions for integral types and char strings; user has to add more specialized definitions.)

unsigned long wb::LHash_hashKey (unsigned long key, unsigned maxBits)
 
template<class KeyT >
unsigned long wb::LHash_hashKey (KeyT *key, unsigned maxBits)
 hash for pointer More...
 
unsigned long wb::LHash_hashKey (int key, unsigned maxBits)
 hash for integral More...
 
unsigned long wb::LHash_hashKey (float key, unsigned maxBits)
 hash for float More...
 
unsigned long wb::LHash_hashKey (double key, unsigned maxBits)
 hash for double More...
 
unsigned long wb::LHash_hashKey (const char *key, unsigned maxBits)
 hash for string More...
 
SortFunction

sort function for LHashIter

template<class KeyT >
bool wb::LHash_IncSort (KeyT k1, KeyT k2)
 
bool wb::LHash_IncSort (const char *p1, const char *p2)
 

Variables

const int wb::cn_MinLHashBits = 3
 if the bits of hash less than this value, using linear table More...
 
const int wb::cn_MaxLHashBits = 31
 the maximum bits number support by hast More...
 
const float wb::cf_HashRatio = 0.8f
 fill-rate of the hash. More...
 
no-key values
  • for signed type, no-key is the smallest negative value
  • for unsigned type, no-key is the largest value
  • for float/double type, no-key is a large float/double
const short wb::c_ShortNokeyValue = (short)(1u << (sizeof(short) * 8 - 1))
 nokey value for short More...
 
const int wb::c_IntNokeyValue = (int)(1u << (sizeof(int) * 8 - 1))
 nokey value for int More...
 
const long wb::c_LongNokeyValue = (long)(1uL << (sizeof(long) * 8 - 1))
 nokey value for long More...
 
const long long wb::c_LLongNokeyValue = (long long)(1LL << (sizeof(long long) * 8 - 1))
 nokey value for longlong More...
 
const short unsigned wb::c_UShortNokeyValue = ~(short unsigned)0
 nokey value for unsigned short More...
 
const unsigned wb::c_UIntNokeyValue = ~(unsigned)0
 nokey value for unsigned int More...
 
const long unsigned wb::c_ULongNokeyValue = ~(long unsigned)0
 nokey value for unsigned long More...
 
const float wb::c_floatNokeyValue = 1e15
 nokey value for float More...
 
const double wb::c_doubleNokeyValue = 1e20
 nokey value for double More...
 

Detailed Description

linear hash, using 'open address' to handle collision

Author
WangBin
Date
2016-04-29

Definition in file wb-lhash.h.

Macro Definition Documentation

§ Bit2Size

#define Bit2Size (   bits)    ( (int)(1<<(bits)) )

Definition at line 34 of file wb-lhash.h.

§ HashMask

#define HashMask (   nbits)    (~((~0L)<<(nbits)))

Definition at line 121 of file wb-lhash.h.