NCBI C++ ToolKit
Public Types | Public Member Functions | Static Public Member Functions | List of all members
CHash Class Reference

Search Toolkit Book for CHash

CHash – Hash calculator. More...

#include <util/checksum.hpp>

+ Inheritance diagram for CHash:
+ Collaboration diagram for CHash:

Public Types

enum  EMethod {
  eCRC32 = CChecksumBase::eCRC32C , eCRC32ZIP = CChecksumBase::eCRC32ZIP , eCRC32INSD = CChecksumBase::eCRC32INSD , eCRC32CKSUM = CChecksumBase::eCRC32CKSUM ,
  eCRC32C = CChecksumBase::eCRC32C , eAdler32 = CChecksumBase::eAdler32 , eCityHash32 = CChecksumBase::eCityHash32 , eCityHash64 = CChecksumBase::eCityHash64 ,
  eFarmHash32 = CChecksumBase::eFarmHash32 , eFarmHash64 = CChecksumBase::eFarmHash64 , eMurmurHash2_32 = CChecksumBase::eMurmurHash2_32 , eMurmurHash2_64 = CChecksumBase::eMurmurHash2_64 ,
  eMurmurHash3_32 = CChecksumBase::eMurmurHash3_32 , eDefault = eCityHash64
}
 Method used to compute hash. More...
 

Public Member Functions

 CHash (EMethod method=eDefault)
 Default constructor. More...
 
 CHash (const CHash &other)
 Copy constructor. More...
 
CHashoperator= (const CHash &other)
 Assignment operator. More...
 
EMethod GetMethod (void) const
 Get current method used to compute hash. More...
 
void Calculate (const CTempString str)
 Calculate hash. More...
 
void Calculate (const char *str, size_t len)
 
void Reset (EMethod method)
 Reset the object to prepare it to the next computation using another method. More...
 
- Public Member Functions inherited from CChecksumBase
 CChecksumBase (EMethodDef method)
 Default constructor. More...
 
 ~CChecksumBase ()
 Destructor. More...
 
 CChecksumBase (const CChecksumBase &other)
 Copy constructor. More...
 
CChecksumBaseoperator= (const CChecksumBase &other)
 Assignment operator. More...
 
size_t GetSize (void) const
 Return size of checksum/hash in bytes, depending on used method. More...
 
size_t GetBits (void) const
 Return size of checksum/hash in bits (32, 64). More...
 
Uint4 GetResult32 (void) const
 Return calculated result. More...
 
Uint8 GetResult64 (void) const
 Return calculated result. More...
 
string GetResultHex (void) const
 Return string with checksum/hash in hexadecimal form. More...
 
EMethodDef x_GetMethod (void) const
 

Static Public Member Functions

static void SetSeed (Uint8 seed)
 Unique seed used by some hash methods. More...
 
static void Calculate (const CTempString str, EMethod method, Uint4 &hash)
 Static methods for simplified one line calculations. More...
 
static void Calculate (const CTempString str, EMethod method, Uint8 &hash)
 
static void Calculate (const char *str, size_t len, EMethod method, Uint4 &hash)
 
static void Calculate (const char *str, size_t len, EMethod method, Uint8 &hash)
 
- Static Public Member Functions inherited from CChecksumBase
static void InitTables (void)
 Initialize static tables used in CRC32 calculation. More...
 
static void PrintTables (CNcbiOstream &out)
 Print C++ code for CRC32 tables for direct inclusion into library. More...
 

Additional Inherited Members

- Protected Types inherited from CChecksumBase
enum  EMethodDef {
  eNone , eCRC32 , eCRC32ZIP , eCRC32INSD ,
  eCRC32CKSUM , eCRC32C , eAdler32 , eMD5 ,
  eCityHash32 , eCityHash64 , eFarmHash32 , eFarmHash64 ,
  eMurmurHash2_32 , eMurmurHash2_64 , eMurmurHash3_32
}
 All supported methods for CHash and CCheksum. More...
 
- Protected Member Functions inherited from CChecksumBase
void x_Update (const char *str, size_t len)
 Update current control sum with data provided. More...
 
void x_Reset (EMethodDef method)
 Reset the object to prepare it to the next computation using selected method. More...
 
void x_Free (void)
 Cleanup (used in destructor and assignment operator). More...
 
- Protected Attributes inherited from CChecksumBase
EMethodDef m_Method
 Current method. More...
 
size_t m_CharCount
 Number of processed chars. More...
 
union {
   Uint4   CChecksumBase::v32
 Used to store 32-bit results. More...
 
   Uint8   CChecksumBase::v64
 Used to store 64-bit results. More...
 
   CMD5 *   CChecksumBase::md5
 Used for MD5 calculation. More...
 
m_Value
 Checksum/Hash computation result. More...
 
- Static Protected Attributes inherited from CChecksumBase
static Uint8 m_Seed = 0
 Unique seed used by some hash methods. More...
 

Detailed Description

CHash – Hash calculator.

This class is used to compute hash.

Note
This class may use static tables (for CRC32 based methods only). This presents a potential race condition in MT programs. To avoid races call static InitTables() method before first concurrent use of CHash if use it with CRC32-based methods.
Attention
You should not use some CHash methods for persistent storage, like CityHash, FarmHash or Murmur. Many hash methods designed to be used inside current process only, here and now. Please use CChecksum class if you need to store checksums for later usage.
Some hash methods have 32/64 bit variants. Usually 32-bit version works faster on 32-bit machines and vice versa.
See also
CChecksumBase::EMethods, NHash, CChecksum

Definition at line 194 of file checksum.hpp.


The documentation for this class was generated from the following files:
Modified on Wed Sep 04 14:58:46 2024 by modify_doxy.py rev. 669887