Minimal xxHash Library for .NET / Unity (XXH32/XXH64)
Runtime/Hashing/MiniXXHash.cs
HeaderDoc
Copyright (c) 2023-2024 https://github.com/sator-imaging Licensed under the BSD 2-Clause License
xxHash (XXH32/XXH64) implementation for Unity in a single file with no dependency.
This is useful for processing UTF-8 string bytes that are not needed to be treated
as C# string (UTF-16) but required to compare difference. ex: Dictionary
XXH32 and XXH64 are older than XXH3 series but it still works enough on small data.
HOW TO USE
var hash32 = MiniXXHash.XXH32(byteArrayOrSpan, seed);
var hash64 = MiniXXHash.XXH64(byteArrayOrSpan, length, seed);
var fromString = MiniXXHash.XXH64("XXH64", seed, clearSharedBuffer: false);
// use own buffer instead of shared array pool when hashing string repeatedly.
Span<byte> buffer = stackalloc byte[256];
var fromString = MiniXXHash.XXH32("use own buffer", seed, buffer);
To test reference implementation, select the following menu command in Unity.
Unity Editor > TEST > Minimal xxHash > Run Tests
SEE ALSO
xxHash - Fast Hash algorithm Copyright (C) 2012-2020 Yann Collet Copyright (C) 2019-2020 Devin Hussey (easyaspi314)
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
You can contact the author at :
- xxHash homepage: http://www.xxhash.com
- xxHash source repository : https://github.com/Cyan4973/xxHash
This is a compact, 100% standalone reference XXH32 single-run implementation.
Instead of focusing on performance hacks, this focuses on cleanliness, conformance, portability and simplicity.
This file aims to be 100% compatible with C90/C++98, with the additional requirement of stdint.h. No library functions are used.