33 #include <sys/types.h> 55 namespace Fnv1aImplementation {
149 #if !defined(__FNV_H__) 156 #define FNV_VERSION "5.0.2" 162 typedef uint32_t Fnv32_t; //PDB 172 #define FNV0_32_INIT ((Fnv1aImplementation::Fnv32_t)0) 188 #define FNV1_32_INIT ((Fnv1aImplementation::Fnv32_t)0x811c9dc5) 190 #define FNV1_32A_INIT FNV1_32_INIT 197 #define HAVE_64BIT_LONG_LONG 204 #if defined(HAVE_64BIT_LONG_LONG) 220 #if defined(HAVE_64BIT_LONG_LONG) 221 #define FNV0_64_INIT ((Fnv1aImplementation::Fnv64_t)0) 223 extern const Fnv64_t fnv0_64_init;
224 #define FNV0_64_INIT (Fnv1aImplementation::fnv0_64_init) 240 #if defined(HAVE_64BIT_LONG_LONG) 241 #define FNV1_64_INIT ((Fnv1aImplementation::Fnv64_t)0xcbf29ce484222325ULL) 243 #define FNV1A_64_INIT FNV1_64_INIT 245 extern const fnv1_64_init;
246 extern const Fnv64_t fnv1a_64_init;
247 #define FNV1_64_INIT (fnv1_64_init) 249 #define FNV1A_64_INIT (fnv1a_64_init) 362 #define FNV_32_PRIME ((Fnv1aImplementation::Fnv32_t)0x01000193) 381 unsigned char *bp = (
unsigned char *)buf;
382 unsigned char *be = bp + len;
393 #if defined(NO_FNV_GCC_OPTIMIZATION) 396 hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
420 unsigned char *s = (
unsigned char *)str;
431 #if defined(NO_FNV_GCC_OPTIMIZATION) 434 hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
510 #if !defined(HAVE_64BIT_LONG_LONG) 511 const Fnv64_t fnv1a_64_init = { 0x84222325, 0xcbf29ce4 };
519 #if defined(HAVE_64BIT_LONG_LONG) 520 #define FNV_64_PRIME ((Fnv1aImplementation::Fnv64_t)0x100000001b3ULL) 522 #define FNV_64_PRIME_LOW ((unsigned long)0x1b3) 523 #define FNV_64_PRIME_SHIFT (8) 544 unsigned char *bp = (
unsigned char *)buf;
545 unsigned char *be = bp + len;
547 #if defined(HAVE_64BIT_LONG_LONG) 557 #if defined(NO_FNV_GCC_OPTIMIZATION) 560 hval += (hval << 1) + (hval << 4) + (hval << 5) +
561 (hval << 7) + (hval << 8) + (hval << 40);
567 unsigned long val[4];
568 unsigned long tmp[4];
573 val[0] = hval.w32[0];
574 val[1] = (val[0] >> 16);
576 val[2] = hval.w32[1];
577 val[3] = (val[2] >> 16);
586 val[0] ^= (
unsigned long)*bp++;
600 tmp[0] = val[0] * FNV_64_PRIME_LOW;
601 tmp[1] = val[1] * FNV_64_PRIME_LOW;
602 tmp[2] = val[2] * FNV_64_PRIME_LOW;
603 tmp[3] = val[3] * FNV_64_PRIME_LOW;
605 tmp[2] += val[0] << FNV_64_PRIME_SHIFT;
606 tmp[3] += val[1] << FNV_64_PRIME_SHIFT;
608 tmp[1] += (tmp[0] >> 16);
609 val[0] = tmp[0] & 0xffff;
610 tmp[2] += (tmp[1] >> 16);
611 val[1] = tmp[1] & 0xffff;
612 val[3] = tmp[3] + (tmp[2] >> 16);
613 val[2] = tmp[2] & 0xffff;
624 hval.w32[1] = ((val[3]<<16) | val[2]);
625 hval.w32[0] = ((val[1]<<16) | val[0]);
649 unsigned char *s = (
unsigned char *)str;
651 #if defined(HAVE_64BIT_LONG_LONG) 662 #if defined(NO_FNV_GCC_OPTIMIZATION) 665 hval += (hval << 1) + (hval << 4) + (hval << 5) +
666 (hval << 7) + (hval << 8) + (hval << 40);
672 unsigned long val[4];
673 unsigned long tmp[4];
678 val[0] = hval.w32[0];
679 val[1] = (val[0] >> 16);
681 val[2] = hval.w32[1];
682 val[3] = (val[2] >> 16);
704 tmp[0] = val[0] * FNV_64_PRIME_LOW;
705 tmp[1] = val[1] * FNV_64_PRIME_LOW;
706 tmp[2] = val[2] * FNV_64_PRIME_LOW;
707 tmp[3] = val[3] * FNV_64_PRIME_LOW;
709 tmp[2] += val[0] << FNV_64_PRIME_SHIFT;
710 tmp[3] += val[1] << FNV_64_PRIME_SHIFT;
712 tmp[1] += (tmp[0] >> 16);
713 val[0] = tmp[0] & 0xffff;
714 tmp[2] += (tmp[1] >> 16);
715 val[1] = tmp[1] & 0xffff;
716 val[3] = tmp[3] + (tmp[2] >> 16);
717 val[2] = tmp[2] & 0xffff;
723 val[0] ^= (
unsigned long)(*s++);
729 hval.w32[1] = ((val[3]<<16) | val[2]);
730 hval.w32[0] = ((val[1]<<16) | val[0]);
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define FNV_32_PRIME
32 bit magic FNV-1a prime
ns3::Hash::Function::Fnv1a declaration.
Fnv32_t fnv_32a_buf(void *buf, size_t len, Fnv32_t hashval)
fnv_32a_buf - perform a 32 bit Fowler/Noll/Vo FNV-1a hash on a buffer
uint64_t Fnv64_t
64 bit FNV-0 hash
#define FNV1_32A_INIT
32 bit FNV-1 and FNV-1a non-zero initial basis
uint32_t m_hash32
Cache last hash value, for incremental hashing.
uint64_t GetHash64(const char *buffer, const size_t size)
Compute 64-bit hash of a byte buffer.
Fnv64_t fnv_64a_buf(void *buf, size_t len, Fnv64_t hashval)
fnv_64a_buf - perform a 64 bit Fowler/Noll/Vo FNV-1a hash on a buffer
uint32_t Fnv32_t
32 bit FNV-0 hash type
Fnv32_t fnv_32a_str(char *buf, Fnv32_t hashval)
fnv_32a_str - perform a 32 bit Fowler/Noll/Vo FNV-1a hash on a string
#define FNV1A_64_INIT
64 bit FNV-1 non-zero initial basis
Fnv64_t fnv_64a_str(char *buf, Fnv64_t hashval)
fnv_64a_str - perform a 64 bit Fowler/Noll/Vo FNV-1a hash on a buffer
#define FNV_64_PRIME
FNV-1a defines the initial basis to be non-zero.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Fnv64_t fnv_64_str(char *str, Fnv64_t hval)
fnv_64a_str - perform a 64 bit Fowler/Noll/Vo FNV-1a hash on a buffer
uint32_t GetHash32(const char *buffer, const size_t size)
Compute 32-bit hash of a byte buffer.
Fnv32_t fnv_32_str(char *str, Fnv32_t hval)
fnv_32a_str - perform a 32 bit Fowler/Noll/Vo FNV-1a hash on a string
virtual void clear(void)
Restore initial state.
uint64_t m_hash64
Cache last hash value, for incremental hashing.
Fnv64_t fnv_64_buf(void *buf, size_t len, Fnv64_t hval)
fnv_64a_buf - perform a 64 bit Fowler/Noll/Vo FNV-1a hash on a buffer
Fnv32_t fnv_32_buf(void *buf, size_t len, Fnv32_t hval)
fnv_32a_buf - perform a 32 bit Fowler/Noll/Vo FNV-1a hash on a buffer