Core: xxHash64Stream

git-svn-id: svn://ultimatepp.org/upp/trunk@10114 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2016-07-30 12:38:24 +00:00
parent 2d1901317a
commit 97a01e693b
2 changed files with 50 additions and 0 deletions

View file

@ -75,4 +75,20 @@ public:
int xxHash(const void *data, size_t len);
int xxHash(const String& s);
class xxHash64Stream : public OutStream {
byte context[12 * 8];
virtual void Out(const void *data, dword size);
public:
int64 Finish();
void Reset(dword seed = 0);
xxHash64Stream(dword seed = 0);
};
int64 xxHash64(const void *data, size_t len);
int64 xxHash64(const String& s);
#endif

View file

@ -38,4 +38,38 @@ int xxHash(const String& s)
return xxHash(~s, s.GetCount());
}
xxHash64Stream::xxHash64Stream(dword seed)
{
STATIC_ASSERT(sizeof(context) >= sizeof(XXH64_state_t));
Reset(seed);
}
void xxHash64Stream::Reset(dword seed)
{
XXH64_reset((XXH64_state_t *)context, seed);
}
void xxHash64Stream::Out(const void *data, dword size)
{
XXH64_update((XXH64_state_t *)context, data, size);
}
int64 xxHash64Stream::Finish()
{
Flush();
return XXH64_digest((XXH64_state_t *)context);
}
int64 xxHash64(const void *data, size_t len)
{
xxHash64Stream h;
h.Put64(data, len);
return h.Finish();
}
int64 xxHash64(const String& s)
{
return xxHash64(~s, s.GetCount());
}
};