{"id":150,"date":"2020-08-04T06:19:34","date_gmt":"2020-08-04T06:19:34","guid":{"rendered":"https:\/\/michaeljohnsteiner.com\/?p=150"},"modified":"2020-08-04T06:19:34","modified_gmt":"2020-08-04T06:19:34","slug":"comparerex-cs","status":"publish","type":"post","link":"https:\/\/michaeljohnsteiner.com\/index.php\/2020\/08\/04\/comparerex-cs\/","title":{"rendered":"ComparerEx.cs"},"content":{"rendered":"\n<p>Custom Comparer using mapped Hashing<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" 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\n[Serializable]\npublic class ComparerEx&lt;T> : IEqualityComparer&lt;T>\n{\n    private static Type _type;\n    private static Mapping64BitToHash32Bit Hash;\n    public bool Equals(T x, T y)\n    {\n        if (x == null || y == null)\n            return false;\n        if (_type == null)\n            _type = x.GetType();\n        if (_type.IsArray)\n        {\n            var xb = x.GetBytesObject(_type);\n            var yb = y.GetBytesObject(_type);\n            return xb.Compare(yb);\n        }\n        return x.Equals(y);\n    }\n    public unsafe int GetHashCode(T obj)\n    {\n        if (_type == null) _type = obj.GetType();\n        if (Hash  == null) Hash  = new Mapping64BitToHash32Bit();\n        var objB   = obj.GetBytesObject(_type);\n        return Hash.ComputeHash(objB).ToInt();\n    }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Custom Comparer using mapped Hashing<\/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\/150"}],"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=150"}],"version-history":[{"count":1,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/posts\/150\/revisions"}],"predecessor-version":[{"id":151,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/posts\/150\/revisions\/151"}],"wp:attachment":[{"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/media?parent=150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/categories?post=150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/tags?post=150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}