<NME> hash.h
<BEF> ADDFILE
<MSG> Adding a hash function for debugging and more later.

<DFF> @@ -0,0 +1,80 @@
+#pragma once
+
+////////////////////////////////////////////////////////////////////////////////
+// The MIT License (MIT)
+//
+// Copyright (c) 2017 Nicholas Frechette & Animation Compression Library contributors
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+////////////////////////////////////////////////////////////////////////////////
+
+#include <stdint.h>
+#include <type_traits>
+
+namespace acl
+{
+	namespace hash_impl
+	{
+		template <typename ResultType, ResultType OffsetBasis, ResultType Prime>
+		class fnv1a_impl final
+		{
+		public:
+			constexpr fnv1a_impl() noexcept
+				: m_state(OffsetBasis)
+			{}
+
+			void update(const void* data, size_t size) noexcept
+			{
+				const uint8_t* cdata = static_cast<const uint8_t*>(data);
+				ResultType acc = m_state;
+				for (size_t i = 0; i < size; ++i)
+				{
+					const ResultType next = cdata[i];
+					acc = (acc ^ next) * Prime;
+				}
+				m_state = acc;
+			}
+
+			constexpr ResultType digest() const noexcept { return m_state; }
+
+		private:
+			static_assert(std::is_unsigned<ResultType>::value, "need unsigned integer");
+
+			ResultType m_state;
+		};
+	}
+
+	using fnv1a_32 = hash_impl::fnv1a_impl<uint32_t, 2166136261u, 16777619u>;
+
+	using fnv1a_64 = hash_impl::fnv1a_impl<uint64_t, 14695981039346656037ull, 1099511628211ull>;
+
+	inline uint32_t hash32(const void* buffer, size_t buffer_size)
+	{
+		fnv1a_32 hashfn = fnv1a_32();
+		hashfn.update(buffer, buffer_size);
+		return hashfn.digest();
+	}
+
+	inline uint64_t hash64(const void* buffer, size_t buffer_size)
+	{
+		fnv1a_64 hashfn = fnv1a_64();
+		hashfn.update(buffer, buffer_size);
+		return hashfn.digest();
+	}
+}

{'commit': 'diff --git a/includes/acl/core/hash.h b/includes/acl/core/hash.h\nnew file mode 100644\nindex 00000000..241d7653\n--- /dev/null\n+++ b/includes/acl/core/hash.h\n@@ -0,0 +1,80 @@\n+#pragma once\n+\n+////////////////////////////////////////////////////////////////////////////////\n+// The MIT License (MIT)\n+//\n+// Copyright (c) 2017 Nicholas Frechette & Animation Compression Library contributors\n+//\n+// Permission is hereby granted, free of charge, to any person obtaining a copy\n+// of this software and associated documentation files (the "Software"), to deal\n+// in the Software without restriction, including without limitation the rights\n+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+// copies of the Software, and to permit persons to whom the Software is\n+// furnished to do so, subject to the following conditions:\n+//\n+// The above copyright notice and this permission notice shall be included in all\n+// copies or substantial portions of the Software.\n+//\n+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n+// SOFTWARE.\n+////////////////////////////////////////////////////////////////////////////////\n+\n+#include <stdint.h>\n+#include <type_traits>\n+\n+namespace acl\n+{\n+\tnamespace hash_impl\n+\t{\n+\t\ttemplate <typename ResultType, ResultType OffsetBasis, ResultType Prime>\n+\t\tclass fnv1a_impl final\n+\t\t{\n+\t\tpublic:\n+\t\t\tconstexpr fnv1a_impl() noexcept\n+\t\t\t\t: m_state(OffsetBasis)\n+\t\t\t{}\n+\n+\t\t\tvoid update(const void* data, size_t size) noexcept\n+\t\t\t{\n+\t\t\t\tconst uint8_t* cdata = static_cast<const uint8_t*>(data);\n+\t\t\t\tResultType acc = m_state;\n+\t\t\t\tfor (size_t i = 0; i < size; ++i)\n+\t\t\t\t{\n+\t\t\t\t\tconst ResultType next = cdata[i];\n+\t\t\t\t\tacc = (acc ^ next) * Prime;\n+\t\t\t\t}\n+\t\t\t\tm_state = acc;\n+\t\t\t}\n+\n+\t\t\tconstexpr ResultType digest() const noexcept { return m_state; }\n+\n+\t\tprivate:\n+\t\t\tstatic_assert(std::is_unsigned<ResultType>::value, "need unsigned integer");\n+\n+\t\t\tResultType m_state;\n+\t\t};\n+\t}\n+\n+\tusing fnv1a_32 = hash_impl::fnv1a_impl<uint32_t, 2166136261u, 16777619u>;\n+\n+\tusing fnv1a_64 = hash_impl::fnv1a_impl<uint64_t, 14695981039346656037ull, 1099511628211ull>;\n+\n+\tinline uint32_t hash32(const void* buffer, size_t buffer_size)\n+\t{\n+\t\tfnv1a_32 hashfn = fnv1a_32();\n+\t\thashfn.update(buffer, buffer_size);\n+\t\treturn hashfn.digest();\n+\t}\n+\n+\tinline uint64_t hash64(const void* buffer, size_t buffer_size)\n+\t{\n+\t\tfnv1a_64 hashfn = fnv1a_64();\n+\t\thashfn.update(buffer, buffer_size);\n+\t\treturn hashfn.digest();\n+\t}\n+}\n', 'commit_subject': 'Adding a hash function for debugging and more later.', 'repo_name': 'nfrechette/acl', 'committer': {'name': 'Nicholas Frechette', 'email': '4afa1ee64a5cb1edca81e75e933c58ad9445b064@gmail.com', 'time_sec': '1502759959', 'tz_offset': '-240', 'date': {'seconds': '1502759959'}}, 'commit_tree': '180983df4f279cc009f8ad9718dc1f6953edd200', 'commit_message': 'Adding a hash function for debugging and more later.\n', 'language_name': 'C', 'license': 'mit', 'hunks': '@@ -0,0 +1,80 @@\n+#pragma once\n+\n+////////////////////////////////////////////////////////////////////////////////\n+// The MIT License (MIT)\n+//\n+// Copyright (c) 2017 Nicholas Frechette & Animation Compression Library contributors\n+//\n+// Permission is hereby granted, free of charge, to any person obtaining a copy\n+// of this software and associated documentation files (the "Software"), to deal\n+// in the Software without restriction, including without limitation the rights\n+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+// copies of the Software, and to permit persons to whom the Software is\n+// furnished to do so, subject to the following conditions:\n+//\n+// The above copyright notice and this permission notice shall be included in all\n+// copies or substantial portions of the Software.\n+//\n+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n+// SOFTWARE.\n+////////////////////////////////////////////////////////////////////////////////\n+\n+#include <stdint.h>\n+#include <type_traits>\n+\n+namespace acl\n+{\n+\tnamespace hash_impl\n+\t{\n+\t\ttemplate <typename ResultType, ResultType OffsetBasis, ResultType Prime>\n+\t\tclass fnv1a_impl final\n+\t\t{\n+\t\tpublic:\n+\t\t\tconstexpr fnv1a_impl() noexcept\n+\t\t\t\t: m_state(OffsetBasis)\n+\t\t\t{}\n+\n+\t\t\tvoid update(const void* data, size_t size) noexcept\n+\t\t\t{\n+\t\t\t\tconst uint8_t* cdata = static_cast<const uint8_t*>(data);\n+\t\t\t\tResultType acc = m_state;\n+\t\t\t\tfor (size_t i = 0; i < size; ++i)\n+\t\t\t\t{\n+\t\t\t\t\tconst ResultType next = cdata[i];\n+\t\t\t\t\tacc = (acc ^ next) * Prime;\n+\t\t\t\t}\n+\t\t\t\tm_state = acc;\n+\t\t\t}\n+\n+\t\t\tconstexpr ResultType digest() const noexcept { return m_state; }\n+\n+\t\tprivate:\n+\t\t\tstatic_assert(std::is_unsigned<ResultType>::value, "need unsigned integer");\n+\n+\t\t\tResultType m_state;\n+\t\t};\n+\t}\n+\n+\tusing fnv1a_32 = hash_impl::fnv1a_impl<uint32_t, 2166136261u, 16777619u>;\n+\n+\tusing fnv1a_64 = hash_impl::fnv1a_impl<uint64_t, 14695981039346656037ull, 1099511628211ull>;\n+\n+\tinline uint32_t hash32(const void* buffer, size_t buffer_size)\n+\t{\n+\t\tfnv1a_32 hashfn = fnv1a_32();\n+\t\thashfn.update(buffer, buffer_size);\n+\t\treturn hashfn.digest();\n+\t}\n+\n+\tinline uint64_t hash64(const void* buffer, size_t buffer_size)\n+\t{\n+\t\tfnv1a_64 hashfn = fnv1a_64();\n+\t\thashfn.update(buffer, buffer_size);\n+\t\treturn hashfn.digest();\n+\t}\n+}\n', 'addition_count': 80, 'deletion_count': 0, 'src_file': '/dev/null', 'tgt_file': 'b/includes/acl/core/hash.h', 'file_extension': '.h', 'before_file': 'ADDFILE', 'message': 'Adding a hash function for debugging and more later.\n', 'author_name': 'Nicholas Frechette', 'lang': 'h'}