MCPcopy Create free account
hub / github.com/DFHack/dfhack / getHash

Function getHash

depends/lodepng/lodepng.cpp:1544–1561  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1542
1543
1544static unsigned getHash(const unsigned char* data, size_t size, size_t pos) {
1545 unsigned result = 0;
1546 if(pos + 2 < size) {
1547 /*A simple shift and xor hash is used. Since the data of PNGs is dominated
1548 by zeroes due to the filters, a better hash does not have a significant
1549 effect on speed in traversing the chain, and causes more time spend on
1550 calculating the hash.*/
1551 result ^= ((unsigned)data[pos + 0] << 0u);
1552 result ^= ((unsigned)data[pos + 1] << 4u);
1553 result ^= ((unsigned)data[pos + 2] << 8u);
1554 } else {
1555 size_t amount, i;
1556 if(pos >= size) return 0;
1557 amount = size - pos;
1558 for(i = 0; i != amount; ++i) result ^= ((unsigned)data[pos + i] << (i * 8u));
1559 }
1560 return result & HASH_BIT_MASK;
1561}
1562
1563static unsigned countZeros(const unsigned char* data, size_t size, size_t pos) {
1564 const unsigned char* start = data + pos;

Callers 1

encodeLZ77Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected