3ds Max C++ API Reference
Loading...
Searching...
No Matches
fnv1a.hpp File Reference
#include <stddef.h>

Functions

size_t fnv1a_hash_bytes (const unsigned char *first, size_t count)
 From https://github.com/microsoft/VCSamples/ in file VC2015Samples/_Hash_seq/fnv1a.hpp The internal hash function std::_Hash_seq(const unsigned char *), used to implement std::hash on some string types, was visible in recent versions of the Standard Library is not anymore visible (VC2017 15.3).
size_t fnv1a_hash_string (const char *string)
size_t fnv1a_hash_string (const wchar_t *string)

Function Documentation

◆ fnv1a_hash_bytes()

size_t fnv1a_hash_bytes ( const unsigned char * first,
size_t count )
inline

From https://github.com/microsoft/VCSamples/ in file VC2015Samples/_Hash_seq/fnv1a.hpp The internal hash function std::_Hash_seq(const unsigned char *), used to implement std::hash on some string types, was visible in recent versions of the Standard Library is not anymore visible (VC2017 15.3).

To remove this dependency, add the header (fnv1a.hpp) to any affected code, and then find and replace _Hash_seq by fnv1a_hash_bytes. You'll get identical behavior to the internal implementation in _Hash_seq.

48 {
49 #if defined(_WIN64)
50 static_assert(sizeof(size_t) == 8, "This code is for 64-bit size_t.");
51 const size_t fnv_offset_basis = 14695981039346656037ULL;
52 const size_t fnv_prime = 1099511628211ULL;
53
54 #else /* defined(_WIN64) */
55 static_assert(sizeof(size_t) == 4, "This code is for 32-bit size_t.");
56 const size_t fnv_offset_basis = 2166136261U;
57 const size_t fnv_prime = 16777619U;
58 #endif /* defined(_WIN64) */
59
60 size_t result = fnv_offset_basis;
61 for (size_t next = 0; next < count; ++next)
62 { // fold in another byte
63 result ^= (size_t)first[next];
64 result *= fnv_prime;
65 }
66 return (result);
67}
MAXMEM_EXTERN_C UtilExport size_t(__cdecl *MAX_msize)(void *memblock)

◆ fnv1a_hash_string() [1/2]

size_t fnv1a_hash_string ( const char * string)
inline
70{
71#if defined(_WIN64)
72 static_assert(sizeof(size_t) == 8, "This code is for 64-bit size_t.");
73 const size_t fnv_offset_basis = 14695981039346656037ULL;
74 const size_t fnv_prime = 1099511628211ULL;
75
76#else /* defined(_WIN64) */
77 static_assert(sizeof(size_t) == 4, "This code is for 32-bit size_t.");
78 const size_t fnv_offset_basis = 2166136261U;
79 const size_t fnv_prime = 16777619U;
80#endif /* defined(_WIN64) */
81
82 size_t result = fnv_offset_basis;
83 while (*string)
84 { // fold in another byte
85 result ^= (size_t)(*string);
86 result *= fnv_prime;
87 string++;
88 }
89 return (result);
90}

◆ fnv1a_hash_string() [2/2]

size_t fnv1a_hash_string ( const wchar_t * string)
inline
94{
95#if defined(_WIN64)
96 static_assert(sizeof(size_t) == 8, "This code is for 64-bit size_t.");
97 const size_t fnv_offset_basis = 14695981039346656037ULL;
98 const size_t fnv_prime = 1099511628211ULL;
99
100#else /* defined(_WIN64) */
101 static_assert(sizeof(size_t) == 4, "This code is for 32-bit size_t.");
102 const size_t fnv_offset_basis = 2166136261U;
103 const size_t fnv_prime = 16777619U;
104#endif /* defined(_WIN64) */
105
106 size_t result = fnv_offset_basis;
107 while (*string)
108 { // fold in another byte
109 result ^= (size_t)(*string);
110 result *= fnv_prime;
111 string++;
112 }
113 return (result);
114}