summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2018-03-26 21:38:38 +0200
committerEugen Wissner <belka@caraus.de>2018-03-27 05:18:46 +0200
commit92f21a95cfcff3266945435e6e3132b9d5809775 (patch)
tree9843efce8fade8e42ccac9e427dc46290b8b5661 /source
parent72140a8583a3b6865e032d891104ef1b029e3c03 (diff)
downloadtanya-92f21a95cfcff3266945435e6e3132b9d5809775.tar.gz
Add hashing pointers
Diffstat (limited to 'source')
-rw-r--r--source/tanya/hash/lookup.d20
1 files changed, 14 insertions, 6 deletions
diff --git a/source/tanya/hash/lookup.d b/source/tanya/hash/lookup.d
index 2ca5b66..b006239 100644
--- a/source/tanya/hash/lookup.d
+++ b/source/tanya/hash/lookup.d
@@ -38,7 +38,11 @@ private struct FNV
void opCall(T)(auto ref T key)
{
- static if (isScalarType!T)
+ static if (is(typeof(key.toHash()) == size_t))
+ {
+ opCall(key.toHash()); // Combine user-defined hashes
+ }
+ else static if (isScalarType!T || isPointer!T)
{
(() @trusted => add((cast(const ubyte*) &key)[0 .. T.sizeof]))();
}
@@ -50,10 +54,6 @@ private struct FNV
{
add(key);
}
- else static if (is(typeof(key.toHash()) == size_t))
- {
- opCall(key.toHash()); // Combine user-defined hashes
- }
else static if (isInputRange!T && !isInfinite!T)
{
foreach (e; key)
@@ -186,7 +186,6 @@ static if (size_t.sizeof == 4) @nogc nothrow pure @safe unittest
assert(hash(HashRange()) == 0x6222e842U);
assert(hash(ToHashRange()) == 1268118805U);
}
-
static if (size_t.sizeof == 8) @nogc nothrow pure @safe unittest
{
assert(hash('a') == 0xaf63dc4c8601ec8cUL);
@@ -194,6 +193,15 @@ static if (size_t.sizeof == 8) @nogc nothrow pure @safe unittest
assert(hash(ToHashRange()) == 12161962213042174405UL);
}
+static if (size_t.sizeof == 4) @nogc nothrow pure @system unittest
+{
+ assert(hash(cast(void*) 0x6e6f6863) == 0xac297727U);
+}
+static if (size_t.sizeof == 8) @nogc nothrow pure @system unittest
+{
+ assert(hash(cast(void*) 0x77206f676e6f6863) == 0xd1edd10b507344d0UL);
+}
+
/*
* These are official FNV-1a test vectors and they are in the public domain.
*/