{"id":126,"date":"2020-07-30T08:45:01","date_gmt":"2020-07-30T08:45:01","guid":{"rendered":"https:\/\/michaeljohnsteiner.com\/?p=126"},"modified":"2021-05-04T11:11:39","modified_gmt":"2021-05-04T11:11:39","slug":"arraycomparer-cs","status":"publish","type":"post","link":"https:\/\/michaeljohnsteiner.com\/index.php\/2020\/07\/30\/arraycomparer-cs\/","title":{"rendered":"ArrayComparer.cs"},"content":{"rendered":"\n<p>Byte Array Comparer Class<\/p>\n\n\n\n<p>Updated: Dec-22,2020<br>Updated: May-04,2021<br><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">using System;\nusing System.Collections.Generic;\n[Serializable]\npublic class ArrayComparer : IEqualityComparer&lt;byte[]>\n{\n    private const ulong M = 0x10000000;\n    public bool Equals(byte[] x, byte[] y)\n    {\n        if (x == null || y == null)\n            return false;\n        if (x.Length != y.Length)\n            return false;\n        return x.Compare(y);\n    }\n    public unsafe int GetHashCode(byte[] obj)\n    {\n        var cbSize = obj.Length;\n        var hash   = 0x811C9DC5;\n        fixed (byte* pb = obj)\n        {\n            var nb = pb;\n            while (cbSize >= 4)\n            {\n                hash   ^= *(uint*) nb;\n                hash   *= 0x1000193;\n                hash   %= 0x10000000;\n                nb     += 4;\n                cbSize -= 4;\n            }\n            switch (cbSize &amp; 3)\n            {\n                case 3:\n                    hash ^= *(uint*) (nb + 2);\n                    hash *= 0x1000193;\n                    hash %= 0x10000000;\n                    goto case 2;\n                case 2:\n                    hash ^= *(uint*) (nb + 1);\n                    hash *= 0x1000193;\n                    hash %= 0x10000000;\n                    goto case 1;\n                case 1:\n                    hash ^= *nb;\n                    hash *= 0x1000193;\n                    hash %= 0x10000000;\n                    break;\n            }\n        }\n        return (int) hash;\n    }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Byte Array Comparer Class Updated: Dec-22,2020Updated: May-04,2021<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/posts\/126"}],"collection":[{"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/comments?post=126"}],"version-history":[{"count":3,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/posts\/126\/revisions"}],"predecessor-version":[{"id":412,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/posts\/126\/revisions\/412"}],"wp:attachment":[{"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/media?parent=126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/categories?post=126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/tags?post=126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}