summaryrefslogtreecommitdiff
path: root/plugins/ShellExt/src/utils.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-08-29 20:53:23 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-08-29 20:53:23 +0000
commit552985214842965925143997a08fe98baf738679 (patch)
tree607340c0780a0076e21d5429f1a13d6b53ebe677 /plugins/ShellExt/src/utils.cpp
parentc5f30ade3d3f2a9a3ba3952230a7f625f81b93ca (diff)
- logging disabled for the future times
- fixed crash when groups are enabled; - fixed incompatibility with Windows 7's Explorer; - correct error codes for COM; - version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@5886 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/ShellExt/src/utils.cpp')
-rw-r--r--plugins/ShellExt/src/utils.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/plugins/ShellExt/src/utils.cpp b/plugins/ShellExt/src/utils.cpp
new file mode 100644
index 0000000000..22e033fb42
--- /dev/null
+++ b/plugins/ShellExt/src/utils.cpp
@@ -0,0 +1,65 @@
+#include "stdafx.h"
+
+#ifdef LOG_ENABLED
+extern TCHAR tszLogPath[];
+
+void logA(const char *format, ...)
+{
+ FILE *out = _tfopen(tszLogPath, _T("a+"));
+ if (out) {
+ va_list args;
+ va_start(args, format);
+ vfprintf(out, format, args);
+ va_end(args);
+ fclose(out);
+ }
+}
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
+
+UINT murmur_hash(const char *str)
+{
+ size_t len = lstrlenA(str);
+
+ // 'm' and 'r' are mixing constants generated offline.
+ // They're not really 'magic', they just happen to work well.
+ const unsigned int m = 0x5bd1e995;
+ const int r = 24;
+
+ // Initialize the hash to a 'random' value
+ unsigned int h = (unsigned)len;
+
+ // Mix 4 bytes at a time into the hash
+ const unsigned char *data = (const unsigned char*)str;
+
+ while (len >= 4) {
+ unsigned int k = *(unsigned int*)data;
+
+ k *= m;
+ k ^= k >> r;
+ k *= m;
+
+ h *= m;
+ h ^= k;
+
+ data += 4;
+ len -= 4;
+ }
+
+ // Handle the last few bytes of the input array
+ switch(len) {
+ case 3: h ^= data[2] << 16;
+ case 2: h ^= data[1] << 8;
+ case 1: h ^= data[0];
+ h *= m;
+ }
+
+ // Do a few final mixes of the hash to ensure the last few
+ // bytes are well-incorporated.
+ h ^= h >> 13;
+ h *= m;
+ h ^= h >> 15;
+
+ return h;
+}