A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://www.ncbi.nlm.nih.gov/IEB/ToolBox/CPP_DOC/doxyhtml/checksum_8cpp_source.html below:

NCBI C++ ToolKit: src/util/checksum.cpp Source File

43 #include "checksum/murmurhash/MurmurHash2.cxx" 44 #include "checksum/murmurhash/MurmurHash3.cxx" 47 #define USE_CRC32C_INTEL 49 #ifdef USE_CRC32C_INTEL 50 # undef USE_CRC32C_INTEL 51 # if defined(NCBI_COMPILER_GCC) || defined(NCBI_COMPILER_ICC) \ 52  || defined(NCBI_COMPILER_ANY_CLANG) 53 # if defined(__x86_64__) || defined(__i386__) 57 # define USE_CRC32C_INTEL 59 # if defined(__x86_64__) 60 # define HAVE_CRC32C_64 62 # elif defined(NCBI_COMPILER_MSVC) 63 # if defined(_M_X64) || defined(_M_IX86) 65 # define USE_CRC32C_INTEL 68 # define HAVE_CRC32C_64 82 #define TABLES_COUNT 8 83 #define NCBI_USE_PRECOMPILED_CRC32_TABLES 1 86 static const char sx_Start

[] =

"/* Original file checksum: "

;

87 static const char sx_End

[] =

" */"

;

93 #ifdef NCBI_USE_PRECOMPILED_CRC32_TABLES 103 #ifdef USE_CRC32C_INTEL 104  static bool

s_IsCRC32CIntelEnabled(

void

);

123

: m_Method(other.m_Method),

124

m_CharCount(other.m_CharCount)

136  if

(&other ==

this

){

157  return m_Value

.md5->GetHexSum();

191 #ifdef USE_CRC32C_INTEL 192  if

( s_IsCRC32CIntelEnabled() ) {

288

m_LineCount(other.m_LineCount)

319  if

( buffer_str.size() !=

len

+ 1 ) {

322  return

memcmp(line, buffer_str.data(),

len

) == 0;

332  out

<< setprecision(8);

381  while

((

n

=

f

.Read(

buf

,

sizeof

(

buf

))) > 0) {

406  while

( !is.eof() ) {

408

is.read(

buf

,

sizeof

(

buf

));

409  size_t n

= (size_t)is.gcount();

413  if

(is.fail() && !is.eof()) {

427  if

( !is.is_open() ) {

430  while

( !is.eof() ) {

432

is.read(

buf

,

sizeof

(

buf

));

433  size_t count

= (size_t)is.gcount();

471 template

<

size_t

kCRC32Tables>

476  const size_t

kLineSize = 4;

477  out

<<

"static const TCRC32Table "

<< name <<

"["

<<kCRC32Tables<<

"] = {"

;

478  for

(

size_t

k = 0; k < kCRC32Tables; ++k ) {

487  if

(

i

% kLineSize == 0 ) {

492  out

<<

"0x"

<<

hex

<< setw(8) << setfill(

'0'

) <<

table

[k][

i

];

496  out

<< dec <<

"\n};\n"

<< endl;

500 #ifdef NCBI_USE_PRECOMPILED_CRC32_TABLES 519 #define CRC32_POLYNOMIAL 0x04c11db7 522 #define CRC32C_POLYNOMIAL 0x1edc6f41 537 Uint4

s_CalcByteCRC32Forward(

size_t byte

,

Uint4

polynomial)

539  Uint4

byteCRC =

byte

<< 24;

540  for

(

int

j = 0; j < 8; ++j ) {

541  if

( byteCRC & 0x80000000U )

542

byteCRC = (byteCRC << 1) ^ polynomial;

544

byteCRC = (byteCRC << 1);

551 Uint4

s_CalcByteCRC32Reverse(

size_t byte

,

Uint4

reversed_polynomial)

554  for

(

int

j = 0; j < 8; ++j ) {

556

byteCRC = (byteCRC >> 1) ^ reversed_polynomial;

558

byteCRC = (byteCRC >> 1);

569  for

(

size_t i

= 1;

i

<

size

; ++

i

) {

573  size_t

hibits =

i

& (

i

-1);

574  size_t

lobit =

i

& ~(

i

-1);

599 template

<

size_t

kCRC32Tables>

611  table

[0][

i

] = s_CalcByteCRC32Forward(

i

, polynomial);

616  for

(

size_t

k = 1; k < kCRC32Tables; ++k ) {

619

checksum = (checksum << 8) ^ table[0][checksum >> 24];

620  table

[k][

i

] = checksum;

626 template

<

size_t

kCRC32Tables>

631  Uint4

reversed_polynomial = 0;

632  for

(

size_t i

= 0;

i

< 32; ++

i

) {

633

reversed_polynomial = (reversed_polynomial << 1)|(polynomial & 1);

643  table

[0][

i

] = s_CalcByteCRC32Reverse(

i

, reversed_polynomial);

648  for

(

size_t

k = 1; k < kCRC32Tables; ++k ) {

651

checksum = (checksum >> 8) ^

table

[0][checksum & 0xff];

652  table

[k][

i

] = checksum;

679 #define s_UpdateCRC32Forward_1(crc, str, table) \ 681  Uint4 v = *(const Uint1*)(str) ^ ((crc) >> 24); \ 682  (crc) = ((crc) << 8) ^ (table)[0][v]; \ 685 #define s_UpdateCRC32Forward_2(crc, str, table) \ 687  Uint4 v = *(const Uint2*)(str); \ 689  (crc) = ((crc) << 16) ^ \ 690  (table)[0][(((crc)>>16)^(v>>8)) & 0xff] ^ \ 691  (table)[1][(((crc)>>24)^(v )) & 0xff]; \ 694 #define s_UpdateCRC32Forward_4(crc, str, table) \ 696  Uint4 v = *(const Uint4*)(str); \ 699  (table)[0][(((crc) )^(v>>24)) & 0xff] ^ \ 700  (table)[1][(((crc)>> 8)^(v>>16)) & 0xff] ^ \ 701  (table)[2][(((crc)>>16)^(v>> 8)) & 0xff] ^ \ 702  (table)[3][(((crc)>>24)^(v )) & 0xff]; \ 705 #define s_UpdateCRC32Forward_8(crc, str, table) \ 707  Uint4 v0 = ((const Uint4*)(str))[0]; \ 708  Uint4 v1 = ((const Uint4*)(str))[1]; \ 711  (table)[0][( (v1>>24)) ] ^ \ 712  (table)[1][( (v1>>16)) & 0xff] ^ \ 713  (table)[2][( (v1>> 8)) & 0xff] ^ \ 714  (table)[3][( (v1 )) & 0xff] ^ \ 715  (table)[4][(((crc) )^(v0>>24)) & 0xff] ^ \ 716  (table)[5][(((crc)>> 8)^(v0>>16)) & 0xff] ^ \ 717  (table)[6][(((crc)>>16)^(v0>> 8)) & 0xff] ^ \ 718  (table)[7][(((crc)>>24)^(v0 )) & 0xff]; \ 722 #define s_UpdateCRC32Reverse_1(crc, str, table) \ 724  Uint4 v = *(const Uint1*)(str); \ 726  (crc) = ((crc) >> 8) ^ \ 727  (table)[0][v & 0xff]; \ 730 #define s_UpdateCRC32Reverse_2(crc, str, table) \ 732  Uint4 v = *(const Uint2*)(str); \ 734  (crc) = ((crc) >> 16) ^ \ 735  (table)[1][(v ) & 0xff] ^ \ 736  (table)[0][(v>>8) & 0xff]; \ 739 #define s_UpdateCRC32Reverse_4(crc, str, table) \ 741  Uint4 v = *(const Uint4*)(str); \ 744  (table)[3][(v ) & 0xff] ^ \ 745  (table)[2][(v>> 8) & 0xff] ^ \ 746  (table)[1][(v>>16) & 0xff] ^ \ 747  (table)[0][(v>>24) ]; \ 750 #define s_UpdateCRC32Reverse_8(crc, str, table) \ 752  Uint4 v0 = ((const Uint4*)(str))[0]; \ 753  Uint4 v1 = ((const Uint4*)(str))[1]; \ 756  (table)[7][(v0 ) & 0xff] ^ \ 757  (table)[6][(v0>> 8) & 0xff] ^ \ 758  (table)[5][(v0>>16) & 0xff] ^ \ 759  (table)[4][(v0>>24) ] ^ \ 760  (table)[3][(v1 ) & 0xff] ^ \ 761  (table)[2][(v1>> 8) & 0xff] ^ \ 762  (table)[1][(v1>>16) & 0xff] ^ \ 763  (table)[0][(v1>>24) ]; \ 767 template

<

size_t

kCRC32Tables>

772 #if TABLES_COUNT >= 2 778 # if TABLES_COUNT >= 4 784 # if TABLES_COUNT >= 8 785  while

(

count

>= 8 ) {

796  while

(

count

>= 4 ) {

808  while

(

count

>= 2 ) {

828 template

<

size_t

kCRC32Tables>

833 #if TABLES_COUNT >= 2 839 # if TABLES_COUNT >= 4 845 # if TABLES_COUNT >= 8 846  while

(

count

>= 8 ) {

857  while

(

count

>= 4 ) {

869  while

(

count

>= 2 ) {

889 #ifdef USE_CRC32C_INTEL 891 #if !defined(NCBI_COMPILER_MSVC) && !defined(bit_SSE4_2) 895 void

call_cpuid(

unsigned

level,

896  unsigned

*

a

,

unsigned

*

b

,

unsigned

* c,

unsigned

* d)

898 #if defined(__i386__) && defined(__PIC__) 900

__asm__(

"xchgl %%ebx, %k1;" 903

:

"=a"

(*

a

),

"=&r"

(*

b

),

"=c"

(*c),

"=d"

(*d)

905 #elif defined(__x86_64__) && defined(__PIC__) 907

__asm__(

"xchgq %%rbx, %q1;" 910

:

"=a"

(*

a

),

"=&r"

(*

b

),

"=c"

(*c),

"=d"

(*d)

914

:

"=a"

(*

a

),

"=b"

(*

b

),

"=c"

(*c),

"=d"

(*d)

919 unsigned

get_cpuid_max(

unsigned

extended)

921  unsigned a

,

b

, c, d;

924  const unsigned

HAS_CPUID_FLAG = 0x00200000;

936

:

"=&r"

(

a

),

"=&r"

(

b

)

937

:

"i"

(HAS_CPUID_FLAG));

938  if

( !((

a

^

b

) & HAS_CPUID_FLAG) )

941

call_cpuid(extended, &

a

, &

b

, &c, &d);

945 bool

get_cpuid(

unsigned

level,

946  unsigned

*

a

,

unsigned

*

b

,

unsigned

*c,

unsigned

*d)

948  if

( get_cpuid_max(level & 0x80000000U) < level) {

951

call_cpuid (level,

a

,

b

, c, d);

954 # define __get_cpuid get_cpuid 955 # define bit_SSE4_2 (1<<20) 958 bool

s_IsCRC32CIntelEnabled(

void

)

960  static volatile bool

enabled, initialized;

961  if

( !initialized ) {

962 #ifdef NCBI_COMPILER_MSVC 967

enabled = (

a

[2] & (1<<20)) != 0;

970  unsigned a

,

b

, c, d;

971

enabled = __get_cpuid(1, &

a

, &

b

, &c, &d) && (c & bit_SSE4_2);

981 #ifdef NCBI_COMPILER_MSVC 986

__asm__(

"crc32b %1, %0" 996 #ifdef NCBI_COMPILER_MSVC 1001

__asm__(

"crc32w %1, %0" 1011 #ifdef NCBI_COMPILER_MSVC 1016

__asm__(

"crc32l %1, %0" 1023 #ifdef HAVE_CRC32C_64 1027 #ifdef NCBI_COMPILER_MSVC 1032

__asm__(

"crc32q %1, %0" 1048

checksum = s_CRC32C(checksum,

str

);

1053

checksum = s_CRC32C(checksum, (

const Uint2

*)

str

);

1057 #ifdef HAVE_CRC32C_64 1061

checksum = s_CRC32C(checksum, (

const Uint4

*)

str

);

1065  Uint8

crc = checksum;

1066  while

(

count

>= 8 ) {

1067

crc = s_CRC32C(crc, (

const Uint8

*)

str

);

1071

checksum =

Uint4

(crc);

1073

checksum = s_CRC32C(checksum, (

const Uint4

*)

str

);

1080  while

(

count

>= 4 ) {

1081

checksum = s_CRC32C(checksum, (

const Uint4

*)

str

);

1088

checksum = s_CRC32C(checksum, (

const Uint2

*)

str

);

1093

checksum = s_CRC32C(checksum,

str

);

1109 #define ADJUST_ADLER(a) a = (a & 0xffff) + (a >> 16) * (0x10000-MOD_ADLER) 1110 #define FINALIZE_ADLER(a) if (a >= MOD_ADLER) a -= MOD_ADLER 1112  Uint4 a

= sum & 0xffff,

b

= sum >> 16;

1114  const size_t

kMaxLen = 5548u;

1116  if

(

len

>= kMaxLen ) {

1118  for

(

size_t i

= 0;

i

< kMaxLen/4; ++

i

) {

1126  for

(

size_t i

=

len

>> 2;

i

; --

i

) {

1146  return

(

b

<< 16) |

a

;

1171 #ifdef USE_CRC32C_INTEL 1172  if

( s_IsCRC32CIntelEnabled() ) {

1325  case eStreamIO

:

return "eStreamError"

;

1326  case eFileIO

:

return "eFileError"

;

1338

: m_Checksum(method)

1349  size_t

* bytes_written)

1352  if

(bytes_written) {

1353

*bytes_written =

count

;

uint32_t MurmurHash2(const void *key, int len, uint32_t seed)

uint64_t MurmurHash64A(const void *key, int len, uint64_t seed)

void MurmurHash3_x86_32(const void *key, int len, uint32_t seed, void *out)

static void s_PrintTable(CNcbiOstream &out, const char *name, const TCRC32Table(&table)[kCRC32Tables])

static const char sx_CharCount[]

#define s_UpdateCRC32Reverse_4(crc, str, table)

#define s_UpdateCRC32Reverse_2(crc, str, table)

CChecksum & ComputeFileChecksum_deprecated(const string &path, CChecksum &checksum)

static Uint4 s_UpdateAdler32(Uint4 sum, const char *data, size_t len)

static void s_InitTableCRC32Reverse()

#define s_UpdateCRC32Forward_1(crc, str, table)

static const size_t kCRC32Size

static const char sx_End[]

#define s_UpdateCRC32Forward_4(crc, str, table)

#define s_UpdateCRC32Forward_2(crc, str, table)

static const char sx_LineCount[]

#define FINALIZE_ADLER(a)

static Uint4 s_UpdateCRC32Forward(Uint4 checksum, const char *str, size_t count, const TCRC32Table(&table)[kCRC32Tables])

static void s_InitTableCRC32Forward()

Uint4 TCRC32Table[kCRC32Size]

#define s_UpdateCRC32Reverse_1(crc, str, table)

static const char sx_Start[]

#define s_UpdateCRC32Forward_8(crc, str, table)

static Uint4 s_UpdateCRC32Reverse(Uint4 checksum, const char *str, size_t count, const TCRC32Table(&table)[kCRC32Tables])

#define s_UpdateCRC32Reverse_8(crc, str, table)

static void s_InitTableCRC32CReverse()

Checksum and hash calculation classes.

uint32 CityHash32(const char *buf, size_t len)

uint64 CityHash64(const char *buf, size_t len)

CChecksumBase – Base class with auxiliary methods for CHash and CChecksum.

CChecksum – Checksum calculator.

Class for support low level input/output for files.

CHash – Hash calculator.

CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:

CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...

Include a standard set of the NCBI C++ Toolkit most basic headers.

static const TCRC32Table s_CRC32CTableReverse[TABLES_COUNT]

static const TCRC32Table s_CRC32TableReverse[TABLES_COUNT]

static const TCRC32Table s_CRC32TableForward[TABLES_COUNT]

std::ofstream out("events_result.xml")

main entry point for tests

static const char * str(char *buf, int n)

static Uint4 MurmurHash3_x86_32(const CTempString str, Uint4 seed=0)

MurmurHash3 (32-bit version only)

size_t GetBits(void) const

Return size of checksum/hash in bits (32, 64).

union CChecksumBase::@940 m_Value

Checksum/Hash computation result.

size_t m_CharCount

Number of processed chars.

CNcbiOstream & WriteChecksum(CNcbiOstream &out) const

Write checksum calculation results into output stream.

CHash(EMethod method=eDefault)

Default constructor.

EMethodDef m_Method

Current method.

Uint8 v64

Used to store 64-bit results.

void AddFile(const string &file_path)

Update checksum with the file data.

CChecksum(EMethod method=eDefault)

Default constructor.

static void InitTables(void)

Initialize static tables used in CRC32 calculation.

void x_Free(void)

Cleanup (used in destructor and assignment operator).

virtual const char * GetErrCodeString(void) const override

Translate from an error code value to its string representation.

static Uint4 MurmurHash2(const CTempString str, Uint4 seed=0)

MurmurHash2.

static void SetSeed(Uint8 seed)

Unique seed used by some hash methods.

CMD5 * md5

Used for MD5 calculation.

virtual ERW_Result Flush(void)

Flush pending data (if any) down to the output device.

string GetResultHex(void) const

Return string with checksum/hash in hexadecimal form.

CNcbiOstream & WriteHexSum(CNcbiOstream &out) const

CChecksumStreamWriter(CChecksum::EMethod method)

Construct object to compute checksum for written data.

EMethod

Method used to compute hash.

static void PrintTables(CNcbiOstream &out)

Print C++ code for CRC32 tables for direct inclusion into library.

bool ValidChecksumLineLong(const char *line, size_t len) const

Check for checksum line.

static Uint4 CityHash32(const CTempString str)

CityHash.

static Uint8 CityHash64(const CTempString str)

virtual ERW_Result Write(const void *buf, size_t count, size_t *bytes_written=0)

Virtual methods from IWriter.

virtual ~CChecksumStreamWriter(void)

Uint4 GetChecksum(void) const

Return calculated checksum.

EMethodDef

All supported methods for CHash and CCheksum.

CChecksum m_Checksum

Checksum calculator.

void x_Update(const char *str, size_t len)

Update current control sum with data provided.

static Uint8 FarmHash64(const CTempString str)

CChecksumBase & operator=(const CChecksumBase &other)

Assignment operator.

CChecksum ComputeFileChecksum(const string &path, CChecksum::EMethod method)

Compute checksum for the given file.

static Uint8 MurmurHash64A(const CTempString str, Uint8 seed=0)

CNcbiOstream & WriteChecksumData(CNcbiOstream &out) const

Uint8 GetResult64(void) const

Return calculated result.

size_t m_LineCount

Number of processed lines.

CChecksum & operator=(const CChecksum &other)

Assignment operator.

CChecksumBase(EMethodDef method)

Default constructor.

void AddChars(const char *str, size_t len)

Update current control sum with data provided.

Uint4 GetResult32(void) const

Return calculated result.

~CChecksumBase()

Destructor.

EMethod GetMethod(void) const

Get current method used to compute checksum.

Uint4 ComputeFileCRC32(const string &path)

Compute CRC32 checksum for the given file.

void x_Reset(EMethodDef method)

Reset the object to prepare it to the next computation using selected method.

static Uint4 FarmHash32(const CTempString str)

FarmHash.

EMethod

Method used to compute control sum.

void AddStream(CNcbiIstream &is)

Update checksum with the stream data.

static Uint8 m_Seed

Unique seed used by some hash methods.

CHash & operator=(const CHash &other)

Assignment operator.

void Calculate(const CTempString str)

Calculate hash.

@ eCityHash32

CityHash, 32-bit result.

@ eFarmHash32

FarmHash, 32-bit result.

@ eCRC32INSD

Inverted CRC32ZIP.

@ eMurmurHash2_64

MurmurHash2 for x64, 64-bit result.

@ eAdler32

A bit faster than CRC32ZIP, not recommended for small data sizes.

@ eCRC32

32-bit Cyclic Redundancy Check.

@ eMurmurHash3_32

MurmurHash3 for x86, 32-bit result.

@ eCityHash64

CityHash, 64-bit result.

@ eMurmurHash2_32

MurmurHash2 for x86, 32-bit result.

@ eCRC32ZIP

Exact zip CRC32.

@ eCRC32CKSUM

CRC32 implemented by cksum utility.

@ eFarmHash64

FarmHash, 64-bit result.

@ eMD5

Message Digest version 5.

@ eCRC32C

CRC32C (Castagnoli).

#define NCBI_THROW(exception_class, err_code, message)

Generic macro to throw an exception, given the exception class, error code and message string.

TErrCode GetErrCode(void) const

virtual const char * GetErrCodeString(void) const

Get error code interpreted as text.

#define NCBI_RETHROW(prev_exception, exception_class, err_code, message)

Generic macro to re-throw an exception.

@ eRead

File can be read.

@ eOpen

Open an existing file, or create a new one.

uint8_t Uint1

1-byte (8-bit) unsigned integer

uint32_t Uint4

4-byte (32-bit) unsigned integer

uint16_t Uint2

2-byte (16-bit) unsigned integer

uint64_t Uint8

8-byte (64-bit) unsigned integer

#define END_NCBI_SCOPE

End previously defined NCBI scope.

#define BEGIN_NCBI_SCOPE

Define ncbi namespace.

ERW_Result

Result codes for I/O operations.

IO_PREFIX::ostream CNcbiOstream

Portable alias for ostream.

IO_PREFIX::istream CNcbiIstream

Portable alias for istream.

IO_PREFIX::ifstream CNcbiIfstream

Portable alias for ifstream.

@ eRW_Success

Everything is okay, I/O completed.

static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)

Convert numeric value to string.

unsigned int

A callback function used to compare two keys in a database.

<!DOCTYPE HTML >< html > n< header > n< title > PubSeq Gateway Help Page</title > n< style > n table

static void hex(unsigned char c)

static void byte(MDB_val *v)

const struct ncbi::grid::netcache::search::fields::SIZE size

uint32_t Hash32(const char *s, size_t len)

uint64_t Hash64(const char *s, size_t len)

Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...

std::istream & in(std::istream &in_, double &x_)

static uint32_t _mm_crc32_u8(uint32_t, uint8_t)

static uint64_t _mm_crc32_u64(uint64_t crc, uint64_t v)

static uint32_t _mm_crc32_u32(uint32_t crc, uint32_t v)

static uint32_t _mm_crc32_u16(uint32_t crc, uint16_t v)


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4