diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2024-10-29 14:49:26 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-29 14:49:26 +0800 |
| commit | f65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch) | |
| tree | ea1d61342cd29368e19135000ec2948813096205 /source/core/slang-stable-hash.h | |
| parent | a729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff) | |
format
* format
* Minor test fixes
* enable checking cpp format in ci
Diffstat (limited to 'source/core/slang-stable-hash.h')
| -rw-r--r-- | source/core/slang-stable-hash.h | 128 |
1 files changed, 64 insertions, 64 deletions
diff --git a/source/core/slang-stable-hash.h b/source/core/slang-stable-hash.h index 30a47121e..b804cc194 100644 --- a/source/core/slang-stable-hash.h +++ b/source/core/slang-stable-hash.h @@ -6,87 +6,87 @@ namespace Slang { - // - // Types - // +// +// Types +// - struct StableHashCode64 - { - uint64_t hash; - explicit operator uint64_t() const { return hash; } - bool operator==(StableHashCode64 other) const { return other.hash == hash; }; - bool operator!=(StableHashCode64 other) const { return other.hash != hash; }; - }; +struct StableHashCode64 +{ + uint64_t hash; + explicit operator uint64_t() const { return hash; } + bool operator==(StableHashCode64 other) const { return other.hash == hash; }; + bool operator!=(StableHashCode64 other) const { return other.hash != hash; }; +}; - struct StableHashCode32 - { - uint32_t hash; - explicit operator uint32_t() const { return hash; } - bool operator==(StableHashCode32 other) const { return other.hash == hash; }; - bool operator!=(StableHashCode32 other) const { return other.hash != hash; }; - }; +struct StableHashCode32 +{ + uint32_t hash; + explicit operator uint32_t() const { return hash; } + bool operator==(StableHashCode32 other) const { return other.hash == hash; }; + bool operator!=(StableHashCode32 other) const { return other.hash != hash; }; +}; - /* The 'Stable' hash code functions produce hashes that must be +/* The 'Stable' hash code functions produce hashes that must be - * The same result for the same inputs on all targets - * Rarely change - as their values can change the output of the Slang API/Serialization +* The same result for the same inputs on all targets +* Rarely change - as their values can change the output of the Slang API/Serialization - Hash value used from the 'Stable' functions can also be used as part of serialization - - so it is in effect part of the API. +Hash value used from the 'Stable' functions can also be used as part of serialization - +so it is in effect part of the API. - In effect this means changing a 'Stable' algorithm will typically require doing a new release. - */ - inline StableHashCode64 getStableHashCode64(const char* buffer, size_t numChars) +In effect this means changing a 'Stable' algorithm will typically require doing a new release. +*/ +inline StableHashCode64 getStableHashCode64(const char* buffer, size_t numChars) +{ + uint64_t hash = 0; + for (size_t i = 0; i < numChars; ++i) { - uint64_t hash = 0; - for (size_t i = 0; i < numChars; ++i) - { - hash = uint64_t(buffer[i]) + (hash << 6) + (hash << 16) - hash; - } - return StableHashCode64{hash}; + hash = uint64_t(buffer[i]) + (hash << 6) + (hash << 16) - hash; } + return StableHashCode64{hash}; +} - template<typename T> - inline StableHashCode64 getStableHashCode64(const T& t) - { - static_assert(std::has_unique_object_representations_v<T>); - return getStableHashCode64(reinterpret_cast<const char*>(&t), sizeof(T)); - } +template<typename T> +inline StableHashCode64 getStableHashCode64(const T& t) +{ + static_assert(std::has_unique_object_representations_v<T>); + return getStableHashCode64(reinterpret_cast<const char*>(&t), sizeof(T)); +} - inline StableHashCode32 getStableHashCode32(const char* buffer, size_t numChars) +inline StableHashCode32 getStableHashCode32(const char* buffer, size_t numChars) +{ + uint32_t hash = 0; + for (size_t i = 0; i < numChars; ++i) { - uint32_t hash = 0; - for (size_t i = 0; i < numChars; ++i) - { - hash = uint32_t(buffer[i]) + (hash << 6) + (hash << 16) - hash; - } - return StableHashCode32{hash}; + hash = uint32_t(buffer[i]) + (hash << 6) + (hash << 16) - hash; } + return StableHashCode32{hash}; +} - template<typename T> - inline StableHashCode32 getStableHashCode32(const T& t) - { - static_assert(std::has_unique_object_representations_v<T>); - return getStableHashCode32(reinterpret_cast<const char*>(&t), sizeof(T)); - } +template<typename T> +inline StableHashCode32 getStableHashCode32(const T& t) +{ + static_assert(std::has_unique_object_representations_v<T>); + return getStableHashCode32(reinterpret_cast<const char*>(&t), sizeof(T)); +} - inline StableHashCode64 combineStableHash(StableHashCode64 h) - { - return h; - } +inline StableHashCode64 combineStableHash(StableHashCode64 h) +{ + return h; +} - inline StableHashCode32 combineStableHash(StableHashCode32 h) - { - return h; - } +inline StableHashCode32 combineStableHash(StableHashCode32 h) +{ + return h; +} - // A left fold with a mixing operation - template<typename H, typename... Hs> - H combineStableHash(H n, H m, Hs... args) - { - return combineStableHash(H{(n.hash * 16777619) ^ m.hash}, args...); - } +// A left fold with a mixing operation +template<typename H, typename... Hs> +H combineStableHash(H n, H m, Hs... args) +{ + return combineStableHash(H{(n.hash * 16777619) ^ m.hash}, args...); } +} // namespace Slang // > Please draw a small horse in ASCII art: // |
