http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheMergeSqlQuerySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheMergeSqlQuerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheMergeSqlQuerySelfTest.java index e8c4e75..c92c7dc 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheMergeSqlQuerySelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheMergeSqlQuerySelfTest.java @@ -123,44 +123,6 @@ public class IgniteCacheMergeSqlQuerySelfTest extends IgniteCacheAbstractInsertS /** * */ - public void testFieldsListIdentity() { - if (!isBinaryMarshaller()) - return; - - fail("https://issues.apache.org/jira/browse/IGNITE-4889"); - - IgniteCache<Key3, Person> p = ignite(0).cache("K32P").withKeepBinary(); - - p.query(new SqlFieldsQuery( - "merge into Person (key, strKey, id, firstName) values (1, 'aa', ?, ?), (2, 'bb', 2, 'Alex')").setArgs(1, "Sergi")); - - assertEquals(createPerson(1, "Sergi"), p.get(new Key3(1))); - - assertEquals(createPerson(2, "Alex"), p.get(new Key3(2))); - } - - /** - * - */ - public void testCustomIdentity() { - if (!isBinaryMarshaller()) - return; - - fail("https://issues.apache.org/jira/browse/IGNITE-4889"); - - IgniteCache<Key4, Person> p = ignite(0).cache("K42P").withKeepBinary(); - - p.query(new SqlFieldsQuery( - "merge into Person (key, strKey, id, firstName) values (1, 'aa', ?, ?), (2, 'bb', 2, 'Alex')").setArgs(1, "Sergi")); - - assertEquals(createPerson(1, "Sergi"), p.get(new Key4(1))); - - assertEquals(createPerson(2, "Alex"), p.get(new Key4(2))); - } - - /** - * - */ public void testNestedFieldsHandling() { IgniteCache<Integer, AllTypes> p = ignite(0).cache("I2AT");
http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/binary/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/Makefile.am b/modules/platforms/cpp/binary/Makefile.am index d310f33..d3c2072 100644 --- a/modules/platforms/cpp/binary/Makefile.am +++ b/modules/platforms/cpp/binary/Makefile.am @@ -52,7 +52,6 @@ libignite_binary_la_SOURCES = \ src/binary/binary_reader.cpp \ src/binary/binary_type.cpp \ src/binary/binary_raw_reader.cpp \ - src/binary/binary_array_identity_resolver.cpp \ src/impl/binary/binary_type_manager.cpp \ src/impl/binary/binary_utils.cpp \ src/impl/binary/binary_reader_impl.cpp \ http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/binary/include/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/Makefile.am b/modules/platforms/cpp/binary/include/Makefile.am index 9c51326..a73d5de 100644 --- a/modules/platforms/cpp/binary/include/Makefile.am +++ b/modules/platforms/cpp/binary/include/Makefile.am @@ -27,8 +27,6 @@ nobase_include_HEADERS = \ ignite/binary/binary_consts.h \ ignite/binary/binary_type.h \ ignite/binary/binary_object.h \ - ignite/binary/binary_identity_resolver.h \ - ignite/binary/binary_array_identity_resolver.h \ ignite/impl/binary/binary_type_handler.h \ ignite/impl/binary/binary_id_resolver.h \ ignite/impl/binary/binary_type_manager.h \ @@ -42,7 +40,6 @@ nobase_include_HEADERS = \ ignite/impl/binary/binary_utils.h \ ignite/impl/binary/binary_object_header.h \ ignite/impl/binary/binary_object_impl.h \ - ignite/impl/binary/binary_type_impl.h \ ignite/impl/interop/interop_memory.h \ ignite/impl/interop/interop.h \ ignite/impl/interop/interop_stream_position_guard.h \ http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/binary/include/ignite/binary/binary_array_identity_resolver.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/binary/binary_array_identity_resolver.h b/modules/platforms/cpp/binary/include/ignite/binary/binary_array_identity_resolver.h deleted file mode 100644 index 70c5ed4..0000000 --- a/modules/platforms/cpp/binary/include/ignite/binary/binary_array_identity_resolver.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * Declares ignite::binary::BinaryArrayIdentityResolver class template. - */ - -#ifndef _IGNITE_BINARY_BINARY_ARRAY_IDENTITY_RESOLVER -#define _IGNITE_BINARY_BINARY_ARRAY_IDENTITY_RESOLVER - -#include <stdint.h> - -#include <ignite/common/common.h> -#include <ignite/binary/binary_identity_resolver.h> - -namespace ignite -{ - namespace binary - { - class BinaryObject; - - /** - * Binary array identity resolver. - */ - class IGNITE_IMPORT_EXPORT BinaryArrayIdentityResolver : public BinaryIdentityResolver - { - public: - /** - * Default constructor. - */ - BinaryArrayIdentityResolver(); - - /** - * Destructor. - */ - virtual ~BinaryArrayIdentityResolver(); - - /** - * Get binary object hash code. - * - * @param obj Binary object. - * @return Hash code. - */ - virtual int32_t GetHashCode(const BinaryObject& obj); - }; - } -} - -#endif //_IGNITE_BINARY_BINARY_ARRAY_IDENTITY_RESOLVER http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/binary/include/ignite/binary/binary_identity_resolver.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/binary/binary_identity_resolver.h b/modules/platforms/cpp/binary/include/ignite/binary/binary_identity_resolver.h deleted file mode 100644 index ce10012..0000000 --- a/modules/platforms/cpp/binary/include/ignite/binary/binary_identity_resolver.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * Declares ignite::binary::BinaryIdentityResolver class. - */ - -#ifndef _IGNITE_BINARY_BINARY_IDENTITY_RESOLVER -#define _IGNITE_BINARY_BINARY_IDENTITY_RESOLVER - -#include <stdint.h> - -#include <ignite/common/common.h> - -#include <ignite/binary/binary_object.h> - -namespace ignite -{ - namespace binary - { - /** - * Binary identity resolver. - */ - class IGNITE_IMPORT_EXPORT BinaryIdentityResolver - { - public: - /** - * Destructor. - */ - virtual ~BinaryIdentityResolver() - { - // No-op. - } - - /** - * Get binary object hash code. - * - * @param obj Binary object. - * @return Hash code. - */ - virtual int32_t GetHashCode(const BinaryObject& obj) = 0; - }; - } -} - -#endif //_IGNITE_BINARY_BINARY_IDENTITY_RESOLVER http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/binary/include/ignite/binary/binary_object.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/binary/binary_object.h b/modules/platforms/cpp/binary/include/ignite/binary/binary_object.h index ff4bd10..4edbe84 100644 --- a/modules/platforms/cpp/binary/include/ignite/binary/binary_object.h +++ b/modules/platforms/cpp/binary/include/ignite/binary/binary_object.h @@ -29,10 +29,16 @@ namespace ignite { - namespace binary + namespace impl { - class BinaryArrayIdentityResolver; + namespace binary + { + class BinaryWriterImpl; + } + } + namespace binary + { /** * Binary object. * @@ -41,7 +47,7 @@ namespace ignite */ class IGNITE_IMPORT_EXPORT BinaryObject { - friend class BinaryArrayIdentityResolver; + friend class ignite::impl::binary::BinaryWriterImpl; public: /// @cond INTERNAL /** http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/binary/include/ignite/binary/binary_type.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/binary/binary_type.h b/modules/platforms/cpp/binary/include/ignite/binary/binary_type.h index f65c652..6657313 100644 --- a/modules/platforms/cpp/binary/include/ignite/binary/binary_type.h +++ b/modules/platforms/cpp/binary/include/ignite/binary/binary_type.h @@ -87,16 +87,6 @@ int32_t GetFieldId(const char* name) \ } /** - * @def IGNITE_BINARY_GET_HASH_CODE_ZERO(T) - * Implementation of GetHashCode() function which always returns 0. - */ -#define IGNITE_BINARY_GET_HASH_CODE_ZERO(T) \ -int32_t GetHashCode(const T& obj) \ -{ \ - return 0; \ -} - -/** * @def IGNITE_BINARY_IS_NULL_FALSE(T) * Implementation of IsNull() function which always returns false. */ http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_type_impl.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_type_impl.h b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_type_impl.h deleted file mode 100644 index 08c60c0..0000000 --- a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_type_impl.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _IGNITE_IMPL_BINARY_BINARY_TYPE_IMP -#define _IGNITE_IMPL_BINARY_BINARY_TYPE_IMP - -#include <stdint.h> - -#include <ignite/common/utils.h> - -#include <ignite/binary/binary_type.h> -#include <ignite/binary/binary_object.h> -#include <ignite/binary/binary_array_identity_resolver.h> - -#include <ignite/reference.h> - -/** - * Some SFINAE magic to check existence of the specified method with the - * specified signature in the BinaryType<T> class. - * - * This macro declares checker for the method. - */ -#define IGNITE_DECLARE_BINARY_TYPE_METHOD_CHECKER(method, sign) \ - template<typename T> \ - class IsDeclaredBinaryType##method \ - { \ - typedef char one; \ - typedef char two[2]; \ - \ - template<class U, U> struct test; \ - \ - template<typename C> static one& helper(test<sign, &C::method>*); \ - template<typename C> static two& helper(...); \ - \ - public: \ - const static bool value = \ - (sizeof(helper< ignite::binary::BinaryType<T> >(0)) == sizeof(one)); \ - } - -namespace ignite -{ - namespace impl - { - namespace binary - { - IGNITE_DECLARE_BINARY_TYPE_METHOD_CHECKER(GetHashCode, int32_t(ignite::binary::BinaryType<T>::*)(const T&)); - IGNITE_DECLARE_BINARY_TYPE_METHOD_CHECKER(GetIdentityResolver, - ignite::Reference<ignite::binary::BinaryIdentityResolver>(ignite::binary::BinaryType<T>::*)()); - - /** - * This type is used to get hash code for binary types which have not - * GetHashCode nor GetIdentityResolver methods defined. - */ - template<typename T> - struct HashCodeGetterDefault - { - static int32_t Get(const T&, const ignite::binary::BinaryObject& obj) - { - ignite::binary::BinaryArrayIdentityResolver arrayResolver; - - return arrayResolver.GetHashCode(obj); - } - }; - - /** - * This type is used to get hash code for binary types which have not - * GetIdentityResolver method defined but have GetHashCode. - */ - template<typename T> - struct HashCodeGetterHashCode - { - static int32_t Get(const T& obj, const ignite::binary::BinaryObject&) - { - ignite::binary::BinaryType<T> bt; - - return bt.GetHashCode(obj); - } - }; - - /** - * This type is used to get hash code for binary types which have - * GetIdentityResolver method defined. - */ - template<typename T> - struct HashCodeGetterResolver - { - static int32_t Get(const T&, const ignite::binary::BinaryObject& obj) - { - ignite::binary::BinaryType<T> bt; - ignite::Reference<ignite::binary::BinaryIdentityResolver> resolver = bt.GetIdentityResolver(); - - return resolver.Get()->GetHashCode(obj); - } - }; - - /** - * Get hash code for the specified object. - * Determines the best method to use based on user-defined methods. - * - * @param obj Object reference. - * @param binObj Binary representation reference. - * @return Hash code for the object. - */ - template<typename T> - int32_t GetHashCode(const T& obj, const ignite::binary::BinaryObject& binObj) - { - using namespace common; - - typedef typename Conditional< - // Checking if the BinaryType<T>::GetIdentityResolver declared - IsDeclaredBinaryTypeGetIdentityResolver<T>::value, - - // True case. Using user-provided resolver. - HashCodeGetterResolver<T>, - - // False case. Adding condition. - typename Conditional< - // Checking if the BinaryType<T>::GetHashCode declared - IsDeclaredBinaryTypeGetHashCode<T>::value, - - // True case - using BinaryType<T>::GetHashCode(). - HashCodeGetterHashCode<T>, - - // False case. Using default getter. - HashCodeGetterDefault<T> - >::type - >::type HashCodeGetter; - - return HashCodeGetter::Get(obj, binObj); - } - } - } -} - -#endif //_IGNITE_IMPL_BINARY_BINARY_TYPE_IMP http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h index 50b2375..5670193 100644 --- a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h +++ b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h @@ -31,7 +31,6 @@ #include "ignite/impl/binary/binary_type_manager.h" #include "ignite/impl/binary/binary_utils.h" #include "ignite/impl/binary/binary_schema.h" -#include "ignite/impl/binary/binary_type_impl.h" #include "ignite/impl/binary/binary_type_manager.h" #include "ignite/binary/binary_consts.h" #include "ignite/binary/binary_type.h" @@ -721,7 +720,9 @@ namespace ignite // at this point that underlying memory contains valid binary object. ignite::binary::BinaryObject binObj(*stream->GetMemory(), pos, &idRslvr, metaMgr); - stream->WriteInt32(hashPos, impl::binary::GetHashCode<T>(obj, binObj)); + int32_t hash = BinaryUtils::GetDataHashCode(binObj.impl.GetData(), binObj.impl.GetLength()); + + stream->WriteInt32(hashPos, hash); } } http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/binary/project/vs/binary.vcxproj ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/project/vs/binary.vcxproj b/modules/platforms/cpp/binary/project/vs/binary.vcxproj index 5a01465..21f1248 100644 --- a/modules/platforms/cpp/binary/project/vs/binary.vcxproj +++ b/modules/platforms/cpp/binary/project/vs/binary.vcxproj @@ -181,8 +181,6 @@ <ClInclude Include="..\..\include\ignite\binary\binary_consts.h" /> <ClInclude Include="..\..\include\ignite\binary\binary_containers.h" /> <ClInclude Include="..\..\include\ignite\binary\binary_object.h" /> - <ClInclude Include="..\..\include\ignite\binary\binary_identity_resolver.h" /> - <ClInclude Include="..\..\include\ignite\binary\binary_array_identity_resolver.h" /> <ClInclude Include="..\..\include\ignite\binary\binary_raw_reader.h" /> <ClInclude Include="..\..\include\ignite\binary\binary_raw_writer.h" /> <ClInclude Include="..\..\include\ignite\binary\binary_reader.h" /> @@ -196,7 +194,6 @@ <ClInclude Include="..\..\include\ignite\impl\binary\binary_reader_impl.h" /> <ClInclude Include="..\..\include\ignite\impl\binary\binary_schema.h" /> <ClInclude Include="..\..\include\ignite\impl\binary\binary_type_handler.h" /> - <ClInclude Include="..\..\include\ignite\impl\binary\binary_type_impl.h" /> <ClInclude Include="..\..\include\ignite\impl\binary\binary_type_manager.h" /> <ClInclude Include="..\..\include\ignite\impl\binary\binary_type_snapshot.h" /> <ClInclude Include="..\..\include\ignite\impl\binary\binary_type_updater.h" /> @@ -209,7 +206,6 @@ <ClInclude Include="..\..\include\ignite\impl\interop\interop_stream_position_guard.h" /> </ItemGroup> <ItemGroup> - <ClCompile Include="..\..\src\binary\binary_array_identity_resolver.cpp" /> <ClCompile Include="..\..\src\binary\binary_containers.cpp" /> <ClCompile Include="..\..\src\binary\binary_raw_reader.cpp" /> <ClCompile Include="..\..\src\binary\binary_raw_writer.cpp" /> http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/binary/project/vs/binary.vcxproj.filters ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/project/vs/binary.vcxproj.filters b/modules/platforms/cpp/binary/project/vs/binary.vcxproj.filters index 05a21aa..27e4ad8 100644 --- a/modules/platforms/cpp/binary/project/vs/binary.vcxproj.filters +++ b/modules/platforms/cpp/binary/project/vs/binary.vcxproj.filters @@ -97,15 +97,6 @@ <ClInclude Include="..\..\include\ignite\impl\binary\binary_object_impl.h"> <Filter>Code\impl\binary</Filter> </ClInclude> - <ClInclude Include="..\..\include\ignite\binary\binary_array_identity_resolver.h"> - <Filter>Code\binary</Filter> - </ClInclude> - <ClInclude Include="..\..\include\ignite\binary\binary_identity_resolver.h"> - <Filter>Code\binary</Filter> - </ClInclude> - <ClInclude Include="..\..\include\ignite\impl\binary\binary_type_impl.h"> - <Filter>Code\impl\binary</Filter> - </ClInclude> <ClInclude Include="..\..\include\ignite\impl\binary\binary_field_meta.h"> <Filter>Code\impl\binary</Filter> </ClInclude> @@ -165,9 +156,6 @@ <ClCompile Include="..\..\src\impl\binary\binary_object_impl.cpp"> <Filter>Code\impl\binary</Filter> </ClCompile> - <ClCompile Include="..\..\src\binary\binary_array_identity_resolver.cpp"> - <Filter>Code\binary</Filter> - </ClCompile> <ClCompile Include="..\..\src\impl\binary\binary_field_meta.cpp"> <Filter>Code\impl\binary</Filter> </ClCompile> http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/binary/src/binary/binary_array_identity_resolver.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/src/binary/binary_array_identity_resolver.cpp b/modules/platforms/cpp/binary/src/binary/binary_array_identity_resolver.cpp deleted file mode 100644 index 6338842..0000000 --- a/modules/platforms/cpp/binary/src/binary/binary_array_identity_resolver.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <ignite/binary/binary_object.h> -#include <ignite/impl/binary/binary_utils.h> - -#include <ignite/binary/binary_array_identity_resolver.h> - -namespace ignite -{ - namespace binary - { - BinaryArrayIdentityResolver::BinaryArrayIdentityResolver() - { - // No-op. - } - - BinaryArrayIdentityResolver::~BinaryArrayIdentityResolver() - { - // No-op. - } - - int32_t BinaryArrayIdentityResolver::GetHashCode(const BinaryObject& obj) - { - return impl::binary::BinaryUtils::GetDataHashCode(obj.impl.GetData(), obj.impl.GetLength()); - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/core-test/include/ignite/binary_test_defs.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/include/ignite/binary_test_defs.h b/modules/platforms/cpp/core-test/include/ignite/binary_test_defs.h index 196c6d3..07e8a14 100644 --- a/modules/platforms/cpp/core-test/include/ignite/binary_test_defs.h +++ b/modules/platforms/cpp/core-test/include/ignite/binary_test_defs.h @@ -156,11 +156,6 @@ namespace ignite return GetBinaryStringHashCode(name); } - int32_t GetHashCode(const gt::BinaryInner& obj) - { - return obj.GetValue(); - } - bool IsNull(const gt::BinaryInner& obj) { return obj.GetValue() == 0; @@ -200,11 +195,6 @@ namespace ignite return GetBinaryStringHashCode(name); } - int32_t GetHashCode(const gt::BinaryInner& obj) - { - return obj.GetValue(); - } - bool IsNull(const gt::BinaryInner& obj) { return obj.GetValue() == 0; @@ -246,11 +236,6 @@ namespace ignite return GetBinaryStringHashCode(name); } - int32_t GetHashCode(const gt::BinaryOuter& obj) - { - return obj.GetValue() + obj.GetInner().GetValue(); - } - bool IsNull(const gt::BinaryOuter& obj) { return obj.GetValue() == 0 && obj.GetInner().GetValue(); @@ -294,11 +279,6 @@ namespace ignite return GetBinaryStringHashCode(name); } - int32_t GetHashCode(const gt::BinaryFields& obj) - { - return obj.val1 + obj.val2 + obj.rawVal1 + obj.rawVal2; - } - bool IsNull(const gt::BinaryFields& obj) { return false; @@ -352,11 +332,6 @@ namespace ignite return GetBinaryStringHashCode(name); } - int32_t GetHashCode(const gt::PureRaw& obj) - { - return GetBinaryStringHashCode(obj.val1.c_str()) ^ obj.val2; - } - bool IsNull(const gt::PureRaw& obj) { return false; http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/core-test/include/ignite/complex_type.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/include/ignite/complex_type.h b/modules/platforms/cpp/core-test/include/ignite/complex_type.h index cb4a8a1..1a97c7b 100644 --- a/modules/platforms/cpp/core-test/include/ignite/complex_type.h +++ b/modules/platforms/cpp/core-test/include/ignite/complex_type.h @@ -77,7 +77,6 @@ namespace ignite IGNITE_BINARY_GET_TYPE_ID_AS_HASH(InnerObject) IGNITE_BINARY_GET_TYPE_NAME_AS_IS(InnerObject) IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_GET_HASH_CODE_ZERO(InnerObject) IGNITE_BINARY_IS_NULL_FALSE(InnerObject) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(InnerObject) @@ -106,7 +105,6 @@ namespace ignite IGNITE_BINARY_GET_TYPE_ID_AS_HASH(ComplexType) IGNITE_BINARY_GET_TYPE_NAME_AS_IS(ComplexType) IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_GET_HASH_CODE_ZERO(ComplexType) IGNITE_BINARY_IS_NULL_FALSE(ComplexType) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(ComplexType) http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/core-test/include/ignite/test_type.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/include/ignite/test_type.h b/modules/platforms/cpp/core-test/include/ignite/test_type.h index d1dd967..d66c668 100644 --- a/modules/platforms/cpp/core-test/include/ignite/test_type.h +++ b/modules/platforms/cpp/core-test/include/ignite/test_type.h @@ -107,7 +107,6 @@ namespace ignite IGNITE_BINARY_GET_TYPE_ID_AS_HASH(TestType) IGNITE_BINARY_GET_TYPE_NAME_AS_IS(TestType) IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_GET_HASH_CODE_ZERO(TestType) IGNITE_BINARY_IS_NULL_FALSE(TestType) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(TestType) http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/core-test/src/binary_identity_resolver_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/binary_identity_resolver_test.cpp b/modules/platforms/cpp/core-test/src/binary_identity_resolver_test.cpp index 55b77bd..b6831c3 100644 --- a/modules/platforms/cpp/core-test/src/binary_identity_resolver_test.cpp +++ b/modules/platforms/cpp/core-test/src/binary_identity_resolver_test.cpp @@ -30,7 +30,6 @@ #include "ignite/cache/query/query_sql_fields.h" #include "ignite/ignite.h" #include "ignite/ignition.h" -#include "ignite/binary/binary_array_identity_resolver.h" #include "ignite/test_utils.h" #include "ignite/complex_type.h" @@ -134,56 +133,6 @@ struct TestUserClassBase }; struct DefaultHashing : TestUserClassBase {}; -struct GetHashDefined : TestUserClassBase {}; -struct ResolverDefined : TestUserClassBase {}; -struct BothDefined : TestUserClassBase {}; - -struct ComplexType2 : ComplexType { }; - -struct CustomIdResolver : binary::BinaryIdentityResolver -{ - int32_t GetHashCode(const BinaryObject& obj) - { - int32_t field; - try - { - ResolverDefined res = obj.Deserialize<ResolverDefined>(); - - field = res.field; - } - catch (const IgniteError&) - { - BothDefined res = obj.Deserialize<BothDefined>(); - - field = res.field; - } - - return field * 42; - } -}; - -struct CustomFieldIdResolver : binary::BinaryIdentityResolver -{ - static int32_t lastHash; - - int32_t GetHashCode(const BinaryObject& obj) - { - int32_t hash = 0; - - if (obj.HasField("objField")) - { - BinaryObject inner = obj.GetField<BinaryObject>("objField"); - - hash = inner.GetField<int32_t>("f1"); - } - - lastHash = hash; - - return hash; - } -}; - -int32_t CustomFieldIdResolver::lastHash = 0; namespace ignite { @@ -213,99 +162,6 @@ namespace ignite } }; - template<> - struct BinaryType<GetHashDefined> - { - IGNITE_BINARY_GET_TYPE_ID_AS_HASH(GetHashDefined) - IGNITE_BINARY_GET_TYPE_NAME_AS_IS(GetHashDefined) - IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_IS_NULL_FALSE(GetHashDefined) - IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(GetHashDefined) - - int32_t GetHashCode(const GetHashDefined& obj) - { - return obj.field * 10; - } - - void Write(BinaryWriter& writer, const GetHashDefined& obj) - { - writer.WriteInt32("field", obj.field); - } - - GetHashDefined Read(BinaryReader& reader) - { - GetHashDefined val; - - val.field = reader.ReadInt32("field"); - - return val; - } - }; - - template<> - struct BinaryType<ResolverDefined> - { - IGNITE_BINARY_GET_TYPE_ID_AS_HASH(ResolverDefined) - IGNITE_BINARY_GET_TYPE_NAME_AS_IS(ResolverDefined) - IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_IS_NULL_FALSE(ResolverDefined) - IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(ResolverDefined) - - ignite::Reference<ignite::binary::BinaryIdentityResolver> GetIdentityResolver() - { - return ignite::MakeReferenceFromCopy(CustomIdResolver()); - } - - void Write(BinaryWriter& writer, const ResolverDefined& obj) - { - writer.WriteInt32("field", obj.field); - } - - ResolverDefined Read(BinaryReader& reader) - { - ResolverDefined val; - - val.field = reader.ReadInt32("field"); - - return val; - } - }; - - template<> - struct BinaryType<BothDefined> - { - IGNITE_BINARY_GET_TYPE_ID_AS_HASH(BothDefined) - IGNITE_BINARY_GET_TYPE_NAME_AS_IS(BothDefined) - IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_IS_NULL_FALSE(BothDefined) - IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(BothDefined) - - int32_t GetHashCode(const GetHashDefined& obj) - { - return obj.field * 10; - } - - ignite::Reference<ignite::binary::BinaryIdentityResolver> GetIdentityResolver() - { - return ignite::MakeReferenceFromCopy(CustomIdResolver()); - } - - void Write(BinaryWriter& writer, const BothDefined& obj) - { - writer.WriteInt32("field", obj.field); - } - - BothDefined Read(BinaryReader& reader) - { - BothDefined val; - - val.field = reader.ReadInt32("field"); - - return val; - } - }; - - /** * Binary type definition for CompositeKey. */ @@ -367,42 +223,6 @@ namespace ignite return val; } }; - - /** - * Binary type definition for ComplexType2. - */ - template<> - struct BinaryType<ComplexType2> - { - IGNITE_BINARY_GET_TYPE_ID_AS_HASH(ComplexType2) - IGNITE_BINARY_GET_TYPE_NAME_AS_IS(ComplexType2) - IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_IS_NULL_FALSE(ComplexType2) - IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(ComplexType2) - - ignite::Reference<ignite::binary::BinaryIdentityResolver> GetIdentityResolver() - { - return ignite::MakeReferenceFromCopy(CustomFieldIdResolver()); - } - - void Write(BinaryWriter& writer, ComplexType2 obj) - { - writer.WriteInt32("i32Field", obj.i32Field); - writer.WriteObject("objField", obj.objField); - writer.WriteString("strField", obj.strField); - } - - ComplexType2 Read(BinaryReader& reader) - { - ComplexType2 obj; - - obj.i32Field = reader.ReadInt32("i32Field"); - obj.objField = reader.ReadObject<InnerObject>("objField"); - obj.strField = reader.ReadString("strField"); - - return obj; - } - }; } } @@ -439,20 +259,6 @@ void FillMem(InteropMemory& mem, const T& value) stream.Synchronize(); } -template<typename R, typename T> -int32_t CalculateHashCode(const T& value) -{ - InteropUnpooledMemory mem(1024); - - FillMem<T>(mem, value); - - BinaryObject obj(mem, 0, 0, 0); - - R resolver; - - return resolver.GetHashCode(obj); -} - template<typename T> int32_t RetrieveHashCode(const T& value) { @@ -490,19 +296,6 @@ BOOST_AUTO_TEST_CASE(GetDataHashCode) BOOST_CHECK_EQUAL(BinaryUtils::GetDataHashCode(data9, sizeof(data9)), 0x000D9F41); } -BOOST_AUTO_TEST_CASE(ArrayIdentityResolver) -{ - using namespace binary; - - CompositeKey key1("Some test garbage, one-two-three...", - Timestamp(109917, 130347199), Guid(0xACC064DF54EE9670, 0x065CF938F56E5E3B)); - - CompositeKeySimple key2("!!!!!!!!!!!!!!!!", Timestamp(324140, 334685375), 89563963); - - BOOST_CHECK_EQUAL(CalculateHashCode<BinaryArrayIdentityResolver>(key1), 0xC298792B); - BOOST_CHECK_EQUAL(CalculateHashCode<BinaryArrayIdentityResolver>(key2), 0x53207175); -} - BOOST_AUTO_TEST_CASE(IdentityEquilityWithGuid) { Ignite grid = ignite_test::StartNode("cache-identity.xml"); @@ -557,51 +350,4 @@ BOOST_AUTO_TEST_CASE(TestDefaultHashing) BOOST_CHECK_EQUAL(RetrieveHashCode(val), 0x01F91B0E); } -BOOST_AUTO_TEST_CASE(TestGetHashDefined) -{ - GetHashDefined val; - val.field = 1337; - - BOOST_CHECK_EQUAL(RetrieveHashCode(val), val.field * 10); -} - -BOOST_AUTO_TEST_CASE(TestResolverDefined) -{ - ResolverDefined val; - val.field = 1337; - - BOOST_CHECK_EQUAL(RetrieveHashCode(val), val.field * 42); -} - -BOOST_AUTO_TEST_CASE(TestBothDefined) -{ - BothDefined val; - val.field = 1337; - - BOOST_CHECK_EQUAL(RetrieveHashCode(val), val.field * 42); -} - -BOOST_AUTO_TEST_CASE(ComplexTypeWithFieldsIdentityResolver) -{ - BOOST_CHECKPOINT("Node startup"); - Ignite node = ignite_test::StartNode("cache-identity.xml"); - - ComplexType2 key; - - key.strField = "ComplexType2"; - key.i32Field = 58943095; - key.objField.f1 = 812; - key.objField.f2 = "InnerType"; - - int32_t value = -12345890; - - BOOST_CHECKPOINT("Cache creation"); - Cache<ComplexType2, int32_t> cache = node.GetOrCreateCache<ComplexType2, int32_t>("cache3"); - - BOOST_CHECKPOINT("Value Put"); - cache.Put(key, value); - - BOOST_CHECK_EQUAL(key.objField.f1, CustomFieldIdResolver::lastHash); -} - BOOST_AUTO_TEST_SUITE_END() http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/core-test/src/cache_invoke_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/cache_invoke_test.cpp b/modules/platforms/cpp/core-test/src/cache_invoke_test.cpp index 4f1f30a..f094d1c 100644 --- a/modules/platforms/cpp/core-test/src/cache_invoke_test.cpp +++ b/modules/platforms/cpp/core-test/src/cache_invoke_test.cpp @@ -129,7 +129,6 @@ namespace ignite IGNITE_BINARY_GET_TYPE_ID_AS_HASH(CacheEntryModifier) IGNITE_BINARY_GET_TYPE_NAME_AS_IS(CacheEntryModifier) IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_GET_HASH_CODE_ZERO(CacheEntryModifier) IGNITE_BINARY_IS_NULL_FALSE(CacheEntryModifier) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(CacheEntryModifier) @@ -240,7 +239,6 @@ namespace ignite IGNITE_BINARY_GET_TYPE_ID_AS_HASH(Divisor) IGNITE_BINARY_GET_TYPE_NAME_AS_IS(Divisor) IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_GET_HASH_CODE_ZERO(Divisor) IGNITE_BINARY_IS_NULL_FALSE(Divisor) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(Divisor) @@ -361,7 +359,6 @@ namespace ignite IGNITE_BINARY_GET_TYPE_ID_AS_HASH(CharRemover) IGNITE_BINARY_GET_TYPE_NAME_AS_IS(CharRemover) IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_GET_HASH_CODE_ZERO(CharRemover) IGNITE_BINARY_IS_NULL_FALSE(CharRemover) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(CharRemover) http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/core-test/src/cache_query_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/cache_query_test.cpp b/modules/platforms/cpp/core-test/src/cache_query_test.cpp index bfd45d1..2c4d3b5 100644 --- a/modules/platforms/cpp/core-test/src/cache_query_test.cpp +++ b/modules/platforms/cpp/core-test/src/cache_query_test.cpp @@ -245,7 +245,6 @@ namespace ignite IGNITE_BINARY_GET_TYPE_ID_AS_HASH(QueryPerson) IGNITE_BINARY_GET_TYPE_NAME_AS_IS(QueryPerson) IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_GET_HASH_CODE_ZERO(QueryPerson) IGNITE_BINARY_IS_NULL_FALSE(QueryPerson) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(QueryPerson) @@ -275,7 +274,6 @@ namespace ignite IGNITE_BINARY_GET_TYPE_ID_AS_HASH(QueryRelation) IGNITE_BINARY_GET_TYPE_NAME_AS_IS(QueryRelation) IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_GET_HASH_CODE_ZERO(QueryRelation) IGNITE_BINARY_IS_NULL_FALSE(QueryRelation) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(QueryRelation) http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/core-test/src/cache_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/cache_test.cpp b/modules/platforms/cpp/core-test/src/cache_test.cpp index a9ee47e..d269f65 100644 --- a/modules/platforms/cpp/core-test/src/cache_test.cpp +++ b/modules/platforms/cpp/core-test/src/cache_test.cpp @@ -53,7 +53,6 @@ namespace ignite IGNITE_BINARY_GET_TYPE_ID_AS_HASH(Person) IGNITE_BINARY_GET_TYPE_NAME_AS_IS(Person) IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_GET_HASH_CODE_ZERO(Person) IGNITE_BINARY_IS_NULL_FALSE(Person) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(Person) http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/core-test/src/continuous_query_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/continuous_query_test.cpp b/modules/platforms/cpp/core-test/src/continuous_query_test.cpp index c52baaf..46ffc2f 100644 --- a/modules/platforms/cpp/core-test/src/continuous_query_test.cpp +++ b/modules/platforms/cpp/core-test/src/continuous_query_test.cpp @@ -265,7 +265,6 @@ namespace ignite IGNITE_BINARY_GET_TYPE_ID_AS_HASH(TestEntry) IGNITE_BINARY_GET_TYPE_NAME_AS_IS(TestEntry) IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_GET_HASH_CODE_ZERO(TestEntry) IGNITE_BINARY_IS_NULL_FALSE(TestEntry) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(TestEntry) @@ -298,11 +297,6 @@ namespace ignite } IGNITE_BINARY_GET_FIELD_ID_AS_HASH - int32_t GetHashCode(const RangeFilter<K,V>&) - { - return 0; - } - bool IsNull(const RangeFilter<K,V>&) { return false; http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/odbc-test/include/complex_type.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/include/complex_type.h b/modules/platforms/cpp/odbc-test/include/complex_type.h index a84b033..99b18ca 100644 --- a/modules/platforms/cpp/odbc-test/include/complex_type.h +++ b/modules/platforms/cpp/odbc-test/include/complex_type.h @@ -64,7 +64,6 @@ namespace ignite IGNITE_BINARY_GET_TYPE_ID_AS_HASH(TestObject) IGNITE_BINARY_GET_TYPE_NAME_AS_IS(TestObject) IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_GET_HASH_CODE_ZERO(TestObject) IGNITE_BINARY_IS_NULL_FALSE(TestObject) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(TestObject) @@ -93,7 +92,6 @@ namespace ignite IGNITE_BINARY_GET_TYPE_ID_AS_HASH(ComplexType) IGNITE_BINARY_GET_TYPE_NAME_AS_IS(ComplexType) IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_GET_HASH_CODE_ZERO(ComplexType) IGNITE_BINARY_IS_NULL_FALSE(ComplexType) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(ComplexType) http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/cpp/odbc-test/include/test_type.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/include/test_type.h b/modules/platforms/cpp/odbc-test/include/test_type.h index 51271b5..7728338 100644 --- a/modules/platforms/cpp/odbc-test/include/test_type.h +++ b/modules/platforms/cpp/odbc-test/include/test_type.h @@ -107,7 +107,6 @@ namespace ignite IGNITE_BINARY_GET_TYPE_ID_AS_HASH(TestType) IGNITE_BINARY_GET_TYPE_NAME_AS_IS(TestType) IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_GET_HASH_CODE_ZERO(TestType) IGNITE_BINARY_IS_NULL_FALSE(TestType) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(TestType) http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryEqualityComparerTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryEqualityComparerTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryEqualityComparerTest.cs index 7c6d769..4dc4d93 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryEqualityComparerTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryEqualityComparerTest.cs @@ -17,10 +17,7 @@ namespace Apache.Ignite.Core.Tests.Binary { - using System.Collections.Generic; - using System.Diagnostics.CodeAnalysis; using Apache.Ignite.Core.Binary; - using Apache.Ignite.Core.Common; using Apache.Ignite.Core.Impl.Binary; using Apache.Ignite.Core.Impl.Binary.IO; using NUnit.Framework; @@ -31,87 +28,46 @@ namespace Apache.Ignite.Core.Tests.Binary public class BinaryEqualityComparerTest { /// <summary> - /// Tests common public methods logic. + /// Tests simple equality. /// </summary> [Test] - [SuppressMessage("ReSharper", "ReturnValueOfPureMethodIsNotUsed")] - public void TestPublicMethods() + public void TestSimpleEquality() { - var cmps = new IEqualityComparer<IBinaryObject>[] - { - new BinaryArrayEqualityComparer() - //new BinaryFieldEqualityComparer() - }; - var obj = GetBinaryObject(1, "x", 0); - foreach (var cmp in cmps) - { - Assert.IsTrue(cmp.Equals(null, null)); - Assert.IsTrue(cmp.Equals(obj, obj)); - - Assert.IsFalse(cmp.Equals(obj, null)); - Assert.IsFalse(cmp.Equals(null, obj)); + Assert.IsTrue(BinaryArrayEqualityComparer.Equals(null, null)); + Assert.IsTrue(BinaryArrayEqualityComparer.Equals(obj, obj)); - Assert.AreEqual(0, cmp.GetHashCode(null)); - Assert.AreNotEqual(0, cmp.GetHashCode(obj)); - } - } - - /// <summary> - /// Tests the custom comparer. - /// </summary> - [Test] - public void TestCustomComparer() - { - var ex = Assert.Throws<IgniteException>(() => Ignition.Start( - new IgniteConfiguration(TestUtils.GetTestConfiguration()) - { - BinaryConfiguration = new BinaryConfiguration - { - TypeConfigurations = new[] - { - new BinaryTypeConfiguration(typeof(Foo)) - { - EqualityComparer = new MyComparer() - } - } - } - })); + Assert.IsFalse(BinaryArrayEqualityComparer.Equals(obj, null)); + Assert.IsFalse(BinaryArrayEqualityComparer.Equals(null, obj)); - Assert.IsNotNull(ex.InnerException); - Assert.AreEqual("Unsupported IEqualityComparer<IBinaryObject> implementation: " + - "Apache.Ignite.Core.Tests.Binary.BinaryEqualityComparerTest+MyComparer. " + - "Only predefined implementations are supported.", ex.InnerException.Message); + Assert.AreEqual(0, BinaryArrayEqualityComparer.GetHashCode(null)); + Assert.AreNotEqual(0, BinaryArrayEqualityComparer.GetHashCode(obj)); } /// <summary> - /// Tests the array comparer. + /// Tests hash code on a stream. /// </summary> [Test] - public void TestArrayComparer() + public void TestStreamHashCode() { - var cmp = (IBinaryEqualityComparer) new BinaryArrayEqualityComparer(); - var ms = new BinaryHeapStream(10); - Assert.AreEqual(1, cmp.GetHashCode(ms, 0, 0, null, 0, null, null)); + Assert.AreEqual(1, BinaryArrayEqualityComparer.GetHashCode(ms, 0, 0)); ms.WriteByte(1); - Assert.AreEqual(31 + 1, cmp.GetHashCode(ms, 0, 1, null, 0, null, null)); + Assert.AreEqual(31 + 1, BinaryArrayEqualityComparer.GetHashCode(ms, 0, 1)); ms.WriteByte(3); - Assert.AreEqual((31 + 1) * 31 + 3, cmp.GetHashCode(ms, 0, 2, null, 0, null, null)); + Assert.AreEqual((31 + 1) * 31 + 3, BinaryArrayEqualityComparer.GetHashCode(ms, 0, 2)); } /// <summary> - /// Tests public methods of array comparer. + /// Tests binary objects comparisons. /// </summary> [Test] - public void TestArrayComparerPublic() + public void TestBinaryObjects() { - var cmp = new BinaryArrayEqualityComparer(); - var obj1 = GetBinaryObject(1, "foo", 11); var obj2 = GetBinaryObject(1, "bar", 11); var obj3 = GetBinaryObject(2, "foo", 11); @@ -120,30 +76,30 @@ namespace Apache.Ignite.Core.Tests.Binary var obj6 = GetBinaryObject(1, "foo", 12); // Equals. - Assert.IsTrue(cmp.Equals(obj1, obj1)); - Assert.IsTrue(cmp.Equals(obj1, obj5)); - Assert.IsFalse(cmp.Equals(obj1, obj2)); - Assert.IsFalse(cmp.Equals(obj1, obj3)); - Assert.IsFalse(cmp.Equals(obj1, obj4)); - Assert.IsFalse(cmp.Equals(obj1, obj6)); - - Assert.IsTrue(cmp.Equals(obj2, obj2)); - Assert.IsFalse(cmp.Equals(obj2, obj5)); - Assert.IsFalse(cmp.Equals(obj2, obj3)); - Assert.IsFalse(cmp.Equals(obj2, obj4)); - Assert.IsFalse(cmp.Equals(obj2, obj6)); - - Assert.IsTrue(cmp.Equals(obj3, obj3)); - Assert.IsFalse(cmp.Equals(obj3, obj5)); - Assert.IsFalse(cmp.Equals(obj3, obj4)); - Assert.IsFalse(cmp.Equals(obj3, obj6)); - - Assert.IsTrue(cmp.Equals(obj4, obj4)); - Assert.IsFalse(cmp.Equals(obj4, obj5)); - Assert.IsFalse(cmp.Equals(obj4, obj6)); - - Assert.IsTrue(cmp.Equals(obj5, obj5)); - Assert.IsFalse(cmp.Equals(obj5, obj6)); + Assert.IsTrue(BinaryArrayEqualityComparer.Equals(obj1, obj1)); + Assert.IsTrue(BinaryArrayEqualityComparer.Equals(obj1, obj5)); + Assert.IsFalse(BinaryArrayEqualityComparer.Equals(obj1, obj2)); + Assert.IsFalse(BinaryArrayEqualityComparer.Equals(obj1, obj3)); + Assert.IsFalse(BinaryArrayEqualityComparer.Equals(obj1, obj4)); + Assert.IsFalse(BinaryArrayEqualityComparer.Equals(obj1, obj6)); + + Assert.IsTrue(BinaryArrayEqualityComparer.Equals(obj2, obj2)); + Assert.IsFalse(BinaryArrayEqualityComparer.Equals(obj2, obj5)); + Assert.IsFalse(BinaryArrayEqualityComparer.Equals(obj2, obj3)); + Assert.IsFalse(BinaryArrayEqualityComparer.Equals(obj2, obj4)); + Assert.IsFalse(BinaryArrayEqualityComparer.Equals(obj2, obj6)); + + Assert.IsTrue(BinaryArrayEqualityComparer.Equals(obj3, obj3)); + Assert.IsFalse(BinaryArrayEqualityComparer.Equals(obj3, obj5)); + Assert.IsFalse(BinaryArrayEqualityComparer.Equals(obj3, obj4)); + Assert.IsFalse(BinaryArrayEqualityComparer.Equals(obj3, obj6)); + + Assert.IsTrue(BinaryArrayEqualityComparer.Equals(obj4, obj4)); + Assert.IsFalse(BinaryArrayEqualityComparer.Equals(obj4, obj5)); + Assert.IsFalse(BinaryArrayEqualityComparer.Equals(obj4, obj6)); + + Assert.IsTrue(BinaryArrayEqualityComparer.Equals(obj5, obj5)); + Assert.IsFalse(BinaryArrayEqualityComparer.Equals(obj5, obj6)); // BinaryObject.GetHashCode. Assert.AreEqual(1934949494, obj1.GetHashCode()); @@ -151,75 +107,21 @@ namespace Apache.Ignite.Core.Tests.Binary Assert.AreEqual(1424415317, obj3.GetHashCode()); Assert.AreEqual(1771330338, obj4.GetHashCode()); Assert.AreEqual(obj1.GetHashCode(), obj5.GetHashCode()); - Assert.AreEqual(1934979285, cmp.GetHashCode(obj6)); + Assert.AreEqual(1934979285, BinaryArrayEqualityComparer.GetHashCode(obj6)); // Comparer.GetHashCode. - Assert.AreEqual(2001751043, cmp.GetHashCode(GetBinaryObject(0, null, 0))); - Assert.AreEqual(194296580, cmp.GetHashCode(GetBinaryObject(1, null, 0))); - Assert.AreEqual(1934949494, cmp.GetHashCode(obj1)); - Assert.AreEqual(-2013102781, cmp.GetHashCode(obj2)); - Assert.AreEqual(1424415317, cmp.GetHashCode(obj3)); - Assert.AreEqual(1771330338, cmp.GetHashCode(obj4)); - Assert.AreEqual(cmp.GetHashCode(obj1), cmp.GetHashCode(obj5)); - Assert.AreEqual(1934979285, cmp.GetHashCode(obj6)); + Assert.AreEqual(2001751043, BinaryArrayEqualityComparer.GetHashCode(GetBinaryObject(0, null, 0))); + Assert.AreEqual(194296580, BinaryArrayEqualityComparer.GetHashCode(GetBinaryObject(1, null, 0))); + Assert.AreEqual(1934949494, BinaryArrayEqualityComparer.GetHashCode(obj1)); + Assert.AreEqual(-2013102781, BinaryArrayEqualityComparer.GetHashCode(obj2)); + Assert.AreEqual(1424415317, BinaryArrayEqualityComparer.GetHashCode(obj3)); + Assert.AreEqual(1771330338, BinaryArrayEqualityComparer.GetHashCode(obj4)); + Assert.AreEqual(BinaryArrayEqualityComparer.GetHashCode(obj1), BinaryArrayEqualityComparer.GetHashCode(obj5)); + Assert.AreEqual(1934979285, BinaryArrayEqualityComparer.GetHashCode(obj6)); // GetHashCode consistency. foreach (var obj in new[] {obj1, obj2, obj3, obj4, obj5, obj6}) - Assert.AreEqual(obj.GetHashCode(), cmp.GetHashCode(obj)); - } - - /// <summary> - /// Tests the field comparer. - /// </summary> - [Test] - public void TestFieldComparer() - { - var marsh = new Marshaller(new BinaryConfiguration - { - TypeConfigurations = new[] - { - new BinaryTypeConfiguration(typeof(Foo)) - { - EqualityComparer = new BinaryFieldEqualityComparer("Name", "Id") - } - } - }); - - var val = new Foo {Id = 58, Name = "John"}; - var binObj = marsh.Unmarshal<IBinaryObject>(marsh.Marshal(val), BinaryMode.ForceBinary); - var expHash = val.Name.GetHashCode() * 31 + val.Id.GetHashCode(); - Assert.AreEqual(expHash, binObj.GetHashCode()); - - val = new Foo {Id = 95}; - binObj = marsh.Unmarshal<IBinaryObject>(marsh.Marshal(val), BinaryMode.ForceBinary); - expHash = val.Id.GetHashCode(); - Assert.AreEqual(expHash, binObj.GetHashCode()); - } - - /// <summary> - /// Tests the field comparer validation. - /// </summary> - [Test] - public void TestFieldComparerValidation() - { - var ex = Assert.Throws<IgniteException>(() => Ignition.Start( - new IgniteConfiguration(TestUtils.GetTestConfiguration()) - { - BinaryConfiguration = new BinaryConfiguration - { - TypeConfigurations = new[] - { - new BinaryTypeConfiguration(typeof(Foo)) - { - EqualityComparer = new BinaryFieldEqualityComparer() - } - } - } - })); - - Assert.IsNotNull(ex.InnerException); - Assert.AreEqual("BinaryFieldEqualityComparer.FieldNames can not be null or empty.", - ex.InnerException.Message); + Assert.AreEqual(obj.GetHashCode(), BinaryArrayEqualityComparer.GetHashCode(obj)); } /// <summary> @@ -227,16 +129,7 @@ namespace Apache.Ignite.Core.Tests.Binary /// </summary> private static IBinaryObject GetBinaryObject(int id, string name, int raw) { - var marsh = new Marshaller(new BinaryConfiguration - { - TypeConfigurations = new[] - { - new BinaryTypeConfiguration(typeof(Foo)) - { - EqualityComparer = new BinaryArrayEqualityComparer() - } - } - }); + var marsh = new Marshaller(new BinaryConfiguration(typeof(Foo))); var bytes = marsh.Marshal(new Foo {Id = id, Name = name, Raw = raw}); @@ -265,18 +158,5 @@ namespace Apache.Ignite.Core.Tests.Binary Raw = reader.GetRawReader().ReadInt(); } } - - private class MyComparer : IEqualityComparer<IBinaryObject> - { - public bool Equals(IBinaryObject x, IBinaryObject y) - { - return true; - } - - public int GetHashCode(IBinaryObject obj) - { - return 0; - } - } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheDmlQueriesTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheDmlQueriesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheDmlQueriesTest.cs index a6a295b..d687894 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheDmlQueriesTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheDmlQueriesTest.cs @@ -23,7 +23,6 @@ namespace Apache.Ignite.Core.Tests.Cache.Query using Apache.Ignite.Core.Cache.Configuration; using Apache.Ignite.Core.Cache.Query; using Apache.Ignite.Core.Common; - using Apache.Ignite.Core.Impl.Binary; using NUnit.Framework; /// <summary> @@ -39,17 +38,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query { var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration()) { - BinaryConfiguration = new BinaryConfiguration(typeof(Foo)) - { - TypeConfigurations = - { - new BinaryTypeConfiguration(typeof(Key)), - new BinaryTypeConfiguration(typeof(Key2)) - { - EqualityComparer = new BinaryFieldEqualityComparer("Hi", "Lo") - } - } - } + BinaryConfiguration = new BinaryConfiguration(typeof(Foo), typeof(Key), typeof(Key2)) }; Ignition.Start(cfg); http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs index 7e44a7a..532f6d5 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs @@ -45,7 +45,6 @@ namespace Apache.Ignite.Core.Tests using Apache.Ignite.Core.Discovery.Tcp; using Apache.Ignite.Core.Discovery.Tcp.Multicast; using Apache.Ignite.Core.Events; - using Apache.Ignite.Core.Impl.Binary; using Apache.Ignite.Core.Impl.Common; using Apache.Ignite.Core.Lifecycle; using Apache.Ignite.Core.Log; @@ -76,7 +75,6 @@ namespace Apache.Ignite.Core.Tests </types> <typeConfigurations> <binaryTypeConfiguration affinityKeyFieldName='affKeyFieldName' isEnum='true' keepDeserialized='True' typeName='typeName'> - <equalityComparer type='BinaryArrayEqualityComparer' /> <idMapper type='Apache.Ignite.Core.Tests.Binary.IdMapper, Apache.Ignite.Core.Tests' /> <nameMapper type='Apache.Ignite.Core.Tests.IgniteConfigurationSerializerTest+NameMapper, Apache.Ignite.Core.Tests' /> <serializer type='Apache.Ignite.Core.Tests.IgniteConfigurationSerializerTest+TestSerializer, Apache.Ignite.Core.Tests' /> @@ -234,7 +232,6 @@ namespace Apache.Ignite.Core.Tests Assert.AreEqual("affKeyFieldName", binType.AffinityKeyFieldName); Assert.IsTrue(binType.IsEnum); Assert.AreEqual(true, binType.KeepDeserialized); - Assert.IsInstanceOf<BinaryArrayEqualityComparer>(binType.EqualityComparer); Assert.IsInstanceOf<IdMapper>(binType.IdMapper); Assert.IsInstanceOf<NameMapper>(binType.NameMapper); Assert.IsInstanceOf<TestSerializer>(binType.Serializer); @@ -585,8 +582,7 @@ namespace Apache.Ignite.Core.Tests TypeName = "typeName", IdMapper = new IdMapper(), NameMapper = new NameMapper(), - Serializer = new TestSerializer(), - EqualityComparer = new BinaryArrayEqualityComparer() + Serializer = new TestSerializer() }, new BinaryTypeConfiguration { @@ -594,8 +590,7 @@ namespace Apache.Ignite.Core.Tests KeepDeserialized = false, AffinityKeyFieldName = "affKeyFieldName", TypeName = "typeName2", - Serializer = new BinaryReflectiveSerializer(), - EqualityComparer = new BinaryFieldEqualityComparer() + Serializer = new BinaryReflectiveSerializer() } }, Types = new[] {typeof (string).FullName}, http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationTest.cs index ee36e5d..8358f69 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationTest.cs @@ -34,7 +34,6 @@ namespace Apache.Ignite.Core.Tests using Apache.Ignite.Core.Discovery.Tcp.Static; using Apache.Ignite.Core.Events; using Apache.Ignite.Core.Impl; - using Apache.Ignite.Core.Impl.Binary; using Apache.Ignite.Core.Tests.Plugin; using Apache.Ignite.Core.Transactions; using NUnit.Framework; @@ -183,9 +182,6 @@ namespace Apache.Ignite.Core.Tests Assert.AreEqual("affKey", typ.AffinityKeyFieldName); Assert.AreEqual(false, typ.KeepDeserialized); - CollectionAssert.AreEqual(new[] {"fld1", "fld2"}, - ((BinaryFieldEqualityComparer)typ.EqualityComparer).FieldNames); - Assert.IsNotNull(resCfg.PluginConfigurations); Assert.AreEqual(cfg.PluginConfigurations, resCfg.PluginConfigurations); } @@ -523,8 +519,7 @@ namespace Apache.Ignite.Core.Tests TypeName = "myType", IsEnum = true, AffinityKeyFieldName = "affKey", - KeepDeserialized = false, - EqualityComparer = new BinaryFieldEqualityComparer("fld1", "fld2") + KeepDeserialized = false } } }, http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj index c999d84..1a758ce 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj @@ -91,9 +91,7 @@ <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> - <Compile Include="Binary\BinaryArrayEqualityComparer.cs" /> <Compile Include="Common\ExceptionFactory.cs" /> - <Compile Include="Impl\Binary\BinaryFieldEqualityComparer.cs" /> <Compile Include="Binary\BinaryReflectiveSerializer.cs" /> <Compile Include="Common\JavaException.cs" /> <Compile Include="DataStructures\Configuration\Package-Info.cs" /> @@ -101,10 +99,9 @@ <Compile Include="Discovery\Tcp\Multicast\Package-Info.cs" /> <Compile Include="Discovery\Tcp\Package-Info.cs" /> <Compile Include="Discovery\Tcp\Static\Package-Info.cs" /> - <Compile Include="Impl\Binary\BinaryEqualityComparerSerializer.cs" /> + <Compile Include="Impl\Binary\BinaryArrayEqualityComparer.cs" /> <Compile Include="Impl\Binary\BinaryProcessor.cs" /> <Compile Include="Impl\Binary\BinaryReflectiveSerializerInternal.cs" /> - <Compile Include="Impl\Binary\IBinaryEqualityComparer.cs" /> <Compile Include="Impl\Binary\IBinarySerializerInternal.cs" /> <Compile Include="Binary\Package-Info.cs" /> <Compile Include="Cache\Affinity\AffinityKey.cs" /> http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryArrayEqualityComparer.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryArrayEqualityComparer.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryArrayEqualityComparer.cs deleted file mode 100644 index 7f8048a..0000000 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryArrayEqualityComparer.cs +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -namespace Apache.Ignite.Core.Binary -{ - using System; - using System.Collections.Generic; - using System.Diagnostics; - using System.Diagnostics.CodeAnalysis; - using Apache.Ignite.Core.Impl.Binary; - using Apache.Ignite.Core.Impl.Binary.IO; - - /// <summary> - /// Compares binary object equality using underlying byte array. - /// </summary> - public sealed class BinaryArrayEqualityComparer : IEqualityComparer<IBinaryObject>, IBinaryEqualityComparer, - IBinaryStreamProcessor<KeyValuePair<int,int>, int> - { - /// <summary> - /// Singleton instance. - /// </summary> - [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", - Justification = "Type is immutable.")] - public static readonly BinaryArrayEqualityComparer Instance = new BinaryArrayEqualityComparer(); - - /// <summary> - /// Determines whether the specified objects are equal. - /// </summary> - /// <param name="x">The first object to compare.</param> - /// <param name="y">The second object to compare.</param> - /// <returns> - /// true if the specified objects are equal; otherwise, false. - /// </returns> - public bool Equals(IBinaryObject x, IBinaryObject y) - { - if (x == null) - return y == null; - - if (y == null) - return false; - - if (ReferenceEquals(x, y)) - return true; - - var binx = GetBinaryObject(x); - var biny = GetBinaryObject(y); - - var lenx = GetDataLength(binx); - var leny = GetDataLength(biny); - - if (lenx != leny) - return false; - - var startx = GetDataStart(binx); - var starty = GetDataStart(biny); - - var arrx = binx.Data; - var arry = biny.Data; - - for (var i = 0; i < lenx; i++) - { - if (arrx[i + startx] != arry[i + starty]) - return false; - } - - return true; - } - - /// <summary> - /// Returns a hash code for this instance. - /// </summary> - /// <param name="obj">The object.</param> - /// <returns> - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. - /// </returns> - public int GetHashCode(IBinaryObject obj) - { - if (obj == null) - return 0; - - var binObj = GetBinaryObject(obj); - - var arg = new KeyValuePair<int, int>(GetDataStart(binObj), GetDataLength(binObj)); - - using (var stream = new BinaryHeapStream(binObj.Data)) - { - return stream.Apply(this, arg); - } - } - - /** <inheritdoc /> */ - int IBinaryEqualityComparer.GetHashCode(IBinaryStream stream, int startPos, int length, - BinaryObjectSchemaHolder schema, int schemaId, Marshaller marshaller, IBinaryTypeDescriptor desc) - { - Debug.Assert(stream != null); - Debug.Assert(startPos >= 0); - Debug.Assert(length >= 0); - - var arg = new KeyValuePair<int, int>(startPos, length); - - return stream.Apply(this, arg); - } - - /** <inheritdoc /> */ - unsafe int IBinaryStreamProcessor<KeyValuePair<int, int>, int>.Invoke(byte* data, KeyValuePair<int, int> arg) - { - var hash = 1; - var ptr = data + arg.Key; - - for (var i = 0; i < arg.Value; i++) - hash = 31 * hash + *(ptr + i); - - return hash; - } - - /// <summary> - /// Casts to <see cref="BinaryObject"/> or throws an error. - /// </summary> - private static BinaryObject GetBinaryObject(IBinaryObject obj) - { - var binObj = obj as BinaryObject; - - if (binObj != null) - return binObj; - - throw new NotSupportedException(string.Format("{0} of type {1} is not supported.", - typeof(IBinaryObject), obj.GetType())); - } - - /// <summary> - /// Gets the non-raw data length. - /// </summary> - private static int GetDataLength(BinaryObject binObj) - { - return binObj.Header.FooterStartOffset - BinaryObjectHeader.Size; - } - - /// <summary> - /// Gets the data starting position. - /// </summary> - private static int GetDataStart(BinaryObject binObj) - { - return binObj.Offset + BinaryObjectHeader.Size; - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryTypeConfiguration.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryTypeConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryTypeConfiguration.cs index 722197c..d342fa5 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryTypeConfiguration.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/BinaryTypeConfiguration.cs @@ -70,7 +70,6 @@ namespace Apache.Ignite.Core.Binary TypeName = cfg.TypeName; KeepDeserialized = cfg.KeepDeserialized; IsEnum = cfg.IsEnum; - EqualityComparer = cfg.EqualityComparer; } /// <summary> @@ -115,18 +114,6 @@ namespace Apache.Ignite.Core.Binary public bool IsEnum { get; set; } /// <summary> - /// Gets or sets the equality comparer to compute hash codes and compare objects - /// in <see cref="IBinaryObject"/> form. - /// This comparer is important only for types that are used as cache keys. - /// <para /> - /// Null means legacy behavior: hash code is computed by calling <see cref="object.GetHashCode"/>, equality is - /// computed by comparing bytes in serialized (binary) form. - /// <para /> - /// Only predefined implementations are supported: <see cref="BinaryArrayEqualityComparer"/>. - /// </summary> - public IEqualityComparer<IBinaryObject> EqualityComparer { get; set; } - - /// <summary> /// Returns a string that represents the current object. /// </summary> /// <returns> http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs index dc1a88c..a3f5daf 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs @@ -271,30 +271,6 @@ namespace Apache.Ignite.Core { writer.WriteBoolean(false); } - - // Send only descriptors with non-null EqualityComparer to preserve old behavior where - // remote nodes can have no BinaryConfiguration. - - if (BinaryConfiguration.TypeConfigurations != null && - BinaryConfiguration.TypeConfigurations.Any(x => x.EqualityComparer != null)) - { - // Create a new marshaller to reuse type name resolver mechanism. - var types = new Marshaller(BinaryConfiguration).GetUserTypeDescriptors() - .Where(x => x.EqualityComparer != null).ToList(); - - writer.WriteInt(types.Count); - - foreach (var type in types) - { - writer.WriteString(BinaryUtils.SimpleTypeName(type.TypeName)); - writer.WriteBoolean(type.IsEnum); - BinaryEqualityComparerSerializer.Write(writer, type.EqualityComparer); - } - } - else - { - writer.WriteInt(0); - } } else { @@ -428,25 +404,6 @@ namespace Apache.Ignite.Core if (r.ReadBoolean()) BinaryConfiguration.CompactFooter = r.ReadBoolean(); - - var typeCount = r.ReadInt(); - - if (typeCount > 0) - { - var types = new List<BinaryTypeConfiguration>(typeCount); - - for (var i = 0; i < typeCount; i++) - { - types.Add(new BinaryTypeConfiguration - { - TypeName = r.ReadString(), - IsEnum = r.ReadBoolean(), - EqualityComparer = BinaryEqualityComparerSerializer.Read(r) - }); - } - - BinaryConfiguration.TypeConfigurations = types; - } } // User attributes http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd index 649129a..f041a8f 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd +++ b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd @@ -144,20 +144,6 @@ </xs:attribute> </xs:complexType> </xs:element> - <xs:element name="equalityComparer" minOccurs="0"> - <xs:annotation> - <xs:documentation> - Equality comparer to compute hash codes and compare objects in IBinaryObject form. - </xs:documentation> - </xs:annotation> - <xs:complexType> - <xs:attribute name="type" type="xs:string" use="required"> - <xs:annotation> - <xs:documentation>Assembly-qualified type name.</xs:documentation> - </xs:annotation> - </xs:attribute> - </xs:complexType> - </xs:element> </xs:all> <xs:attribute name="typeName" type="xs:string"> <xs:annotation> http://git-wip-us.apache.org/repos/asf/ignite/blob/c2d8bd9a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryArrayEqualityComparer.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryArrayEqualityComparer.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryArrayEqualityComparer.cs new file mode 100644 index 0000000..8ba409b --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryArrayEqualityComparer.cs @@ -0,0 +1,159 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Impl.Binary +{ + using System; + using System.Collections.Generic; + using System.Diagnostics; + using Apache.Ignite.Core.Binary; + using Apache.Ignite.Core.Impl.Binary.IO; + + /// <summary> + /// Compares binary object equality using underlying byte array. + /// </summary> + internal static class BinaryArrayEqualityComparer + { + /** */ + private static readonly HashStreamProcessor HashCodeProcessor = new HashStreamProcessor(); + + /// <summary> + /// Determines whether the specified objects are equal. + /// </summary> + /// <param name="x">The first object to compare.</param> + /// <param name="y">The second object to compare.</param> + /// <returns> + /// true if the specified objects are equal; otherwise, false. + /// </returns> + public static bool Equals(IBinaryObject x, IBinaryObject y) + { + if (x == null) + return y == null; + + if (y == null) + return false; + + if (ReferenceEquals(x, y)) + return true; + + var binx = GetBinaryObject(x); + var biny = GetBinaryObject(y); + + var lenx = GetDataLength(binx); + var leny = GetDataLength(biny); + + if (lenx != leny) + return false; + + var startx = GetDataStart(binx); + var starty = GetDataStart(biny); + + var arrx = binx.Data; + var arry = biny.Data; + + for (var i = 0; i < lenx; i++) + { + if (arrx[i + startx] != arry[i + starty]) + return false; + } + + return true; + } + + /// <summary> + /// Returns a hash code for this instance. + /// </summary> + /// <param name="obj">The object.</param> + /// <returns> + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// </returns> + public static int GetHashCode(IBinaryObject obj) + { + if (obj == null) + return 0; + + var binObj = GetBinaryObject(obj); + + var arg = new KeyValuePair<int, int>(GetDataStart(binObj), GetDataLength(binObj)); + + using (var stream = new BinaryHeapStream(binObj.Data)) + { + return stream.Apply(HashCodeProcessor, arg); + } + } + + /** <inheritdoc /> */ + public static int GetHashCode(IBinaryStream stream, int startPos, int length) + { + Debug.Assert(stream != null); + Debug.Assert(startPos >= 0); + Debug.Assert(length >= 0); + + var arg = new KeyValuePair<int, int>(startPos, length); + + return stream.Apply(HashCodeProcessor, arg); + } + + /// <summary> + /// Casts to <see cref="BinaryObject"/> or throws an error. + /// </summary> + private static BinaryObject GetBinaryObject(IBinaryObject obj) + { + var binObj = obj as BinaryObject; + + if (binObj != null) + return binObj; + + throw new NotSupportedException(string.Format("{0} of type {1} is not supported.", + typeof(IBinaryObject), obj.GetType())); + } + + /// <summary> + /// Gets the non-raw data length. + /// </summary> + private static int GetDataLength(BinaryObject binObj) + { + return binObj.Header.FooterStartOffset - BinaryObjectHeader.Size; + } + + /// <summary> + /// Gets the data starting position. + /// </summary> + private static int GetDataStart(BinaryObject binObj) + { + return binObj.Offset + BinaryObjectHeader.Size; + } + + /// <summary> + /// Hash code calculating stream processor. + /// </summary> + private class HashStreamProcessor : IBinaryStreamProcessor<KeyValuePair<int, int>, int> + { + /** <inheritdoc /> */ + public unsafe int Invoke(byte* data, KeyValuePair<int, int> arg) + { + var hash = 1; + var ptr = data + arg.Key; + + for (var i = 0; i < arg.Value; i++) + hash = 31 * hash + *(ptr + i); + + return hash; + } + } + } +}
