git-svn-id: svn://db.shs.com.ru/pip@840 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include "piplatform.h"
|
||||
#include "pip_export.h"
|
||||
#include "pip_defs.h"
|
||||
#include "string.h"
|
||||
|
||||
//! Version of PIP in hex - 0x##(Major)##(Minor)##(Revision)
|
||||
#define PIP_VERSION ((PIP_VERSION_MAJOR << 16) | (PIP_VERSION_MINOR < 8) | PIP_VERSION_REVISION)
|
||||
@@ -459,6 +460,46 @@ uint letobe_i(uint v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF
|
||||
|
||||
#endif
|
||||
|
||||
/// \brief Generic hash function, impements murmur3/32 algorithm
|
||||
inline uint piHash(const uchar * data, uint len, uint seed = 0) {
|
||||
if (!data || len <= 0) return 0u;
|
||||
uint h = seed;
|
||||
if (len > 3) {
|
||||
uint i = len >> 2;
|
||||
do {
|
||||
uint k;
|
||||
memcpy(&k, data, sizeof(uint));
|
||||
data += sizeof(uint);
|
||||
k *= 0xcc9e2d51;
|
||||
k = (k << 15) | (k >> 17);
|
||||
k *= 0x1b873593;
|
||||
h ^= k;
|
||||
h = (h << 13) | (h >> 19);
|
||||
h = h * 5 + 0xe6546b64;
|
||||
} while (--i);
|
||||
}
|
||||
if (len & 3) {
|
||||
uint i = len & 3;
|
||||
uint k = 0;
|
||||
do {
|
||||
k <<= 8;
|
||||
k |= data[i - 1];
|
||||
} while (--i);
|
||||
k *= 0xcc9e2d51;
|
||||
k = (k << 15) | (k >> 17);
|
||||
k *= 0x1b873593;
|
||||
h ^= k;
|
||||
}
|
||||
h ^= len;
|
||||
h ^= h >> 16;
|
||||
h *= 0x85ebca6b;
|
||||
h ^= h >> 13;
|
||||
h *= 0xc2b2ae35;
|
||||
h ^= h >> 16;
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
#define piRoundf piRound<float>
|
||||
#define piRoundd piRound<double>
|
||||
#define piFloorf piFloor<float>
|
||||
|
||||
Reference in New Issue
Block a user