Skip to content

Commit

Permalink
Merge pull request #51 from vibe-d/router_hash_function
Browse files Browse the repository at this point in the history
Use Murmur Hash instead of MD5 in order to speed up match tree generation
  • Loading branch information
s-ludwig authored Dec 17, 2024
2 parents 8cf9b23 + 738f5c3 commit ce803e3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions source/vibe/http/router.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public import vibe.http.server;

import vibe.core.log;

import std.digest.murmurhash : MurmurHash3;
import std.functional;


Expand Down Expand Up @@ -1300,13 +1301,11 @@ struct LinkedSetBacking(T) {

LinkedSetHash getHash(Handle sh)
const {
import std.digest.md : md5Of;

// NOTE: the returned hash is order independent, to avoid bogus
// mismatches when comparing lists of different order
LinkedSetHash ret = cast(LinkedSetHash)md5Of([]);
LinkedSetHash ret = linkedSetHashOf(null);
while (sh != Handle.init) {
auto h = cast(LinkedSetHash)md5Of(cast(const(ubyte)[])(&m_storage[sh.index].value)[0 .. 1]);
auto h = linkedSetHashOf(cast(const(ubyte)[])(&m_storage[sh.index].value)[0 .. 1]);
foreach (i; 0 .. ret.length) ret[i] ^= h[i];
sh.index = m_storage[sh.index].next;
}
Expand Down Expand Up @@ -1372,7 +1371,15 @@ unittest {
assert(b.getItems(s).equal([11, 7, 3, 5]));
}

alias LinkedSetHasher = MurmurHash3!(128, 64);
alias LinkedSetHash = ulong[16/ulong.sizeof];
LinkedSetHash linkedSetHashOf(scope const(ubyte)[] bytes)
{
LinkedSetHasher h;
h.start();
h.put(bytes);
return cast(LinkedSetHash)h.finish();
}

private struct Stack(E)
{
Expand Down

0 comments on commit ce803e3

Please sign in to comment.