summaryrefslogtreecommitdiff
path: root/zen/stl_tools.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2016-05-24 22:10:57 +0200
committerDaniel Wilhelm <daniel@wili.li>2016-05-24 22:10:57 +0200
commit9043b32bb1835628c5a1d8be4a271c848443c629 (patch)
tree98ccb4936562731d9cae02a486441dfd446e8a4e /zen/stl_tools.h
parent8.0 (diff)
downloadFreeFileSync-9043b32bb1835628c5a1d8be4a271c848443c629.tar.gz
FreeFileSync-9043b32bb1835628c5a1d8be4a271c848443c629.tar.bz2
FreeFileSync-9043b32bb1835628c5a1d8be4a271c848443c629.zip
8.1
Diffstat (limited to 'zen/stl_tools.h')
-rw-r--r--zen/stl_tools.h21
1 files changed, 16 insertions, 5 deletions
diff --git a/zen/stl_tools.h b/zen/stl_tools.h
index b78dd5dd..058609e6 100644
--- a/zen/stl_tools.h
+++ b/zen/stl_tools.h
@@ -62,6 +62,7 @@ bool equal(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2);
size_t hashBytes(const unsigned char* ptr, size_t len);
+size_t hashBytesAppend(size_t hashVal, const unsigned char* ptr, size_t len);
//support for custom string classes in std::unordered_set/map
@@ -216,20 +217,30 @@ size_t hashBytes(const unsigned char* ptr, size_t len)
//http://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
#ifdef ZEN_BUILD_32BIT
const size_t basis = 2166136261U;
- const size_t prime = 16777619U;
#elif defined ZEN_BUILD_64BIT
const size_t basis = 14695981039346656037ULL;
+#endif
+ return hashBytesAppend(basis, ptr, len);
+}
+
+
+inline
+size_t hashBytesAppend(size_t hashVal, const unsigned char* ptr, size_t len)
+{
+#ifdef ZEN_BUILD_32BIT
+ const size_t prime = 16777619U;
+#elif defined ZEN_BUILD_64BIT
const size_t prime = 1099511628211ULL;
#endif
- size_t val = basis;
for (size_t i = 0; i < len; ++i)
{
- val ^= static_cast<size_t>(ptr[i]);
- val *= prime;
+ hashVal ^= static_cast<size_t>(ptr[i]);
+ hashVal *= prime;
}
- return val;
+ return hashVal;
}
+
}
#endif //STL_TOOLS_H_84567184321434
bgstack15