summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcpp/allTests.py1
-rw-r--r--cpp/src/Ice/HashUtil.h7
-rw-r--r--cpp/src/Ice/Makefile.mak1
-rw-r--r--cpp/src/Ice/OpaqueEndpointI.cpp3
-rw-r--r--cpp/src/Ice/Reference.cpp12
-rw-r--r--cpp/src/Ice/TcpEndpointI.cpp7
-rw-r--r--cpp/src/Ice/UdpEndpointI.cpp7
-rw-r--r--cpp/src/Ice/winrt/StreamEndpointI.cpp7
-rw-r--r--cpp/src/IceSSL/EndpointI.cpp7
-rw-r--r--cpp/src/slice2cs/Gen.cpp74
-rw-r--r--cpp/src/slice2java/Gen.cpp118
-rw-r--r--cpp/test/Ice/Makefile1
-rw-r--r--cpp/test/Ice/Makefile.mak3
-rw-r--r--cpp/test/Ice/hash/.depend3
-rw-r--r--cpp/test/Ice/hash/.depend.mak3
-rw-r--r--cpp/test/Ice/hash/.gitignore6
-rw-r--r--cpp/test/Ice/hash/Client.cpp139
-rw-r--r--cpp/test/Ice/hash/Makefile33
-rw-r--r--cpp/test/Ice/hash/Makefile.mak49
-rw-r--r--cpp/test/Ice/hash/Test.ice20
-rwxr-xr-xcpp/test/Ice/hash/run.py25
-rw-r--r--cpp/test/WinRT/TestSuite/MainPage.xaml.cpp3
-rw-r--r--cpp/test/WinRT/TestSuite/TestSuite.vcxproj3
-rw-r--r--cpp/test/WinRT/TestSuite/TestSuite.vcxproj.filters3
-rwxr-xr-xcs/allTests.py1
-rw-r--r--cs/config/Make.rules.cs1
-rw-r--r--cs/config/Make.rules.mak.cs1
-rw-r--r--cs/src/Ice/Arrays.cs13
-rw-r--r--cs/src/Ice/CollectionBase.cs6
-rw-r--r--cs/src/Ice/Collections.cs20
-rw-r--r--cs/src/Ice/DictionaryBase.cs8
-rw-r--r--cs/src/Ice/EndpointI.cs5
-rw-r--r--cs/src/Ice/Object.cs15
-rw-r--r--cs/src/Ice/OpaqueEndpointI.cs11
-rw-r--r--cs/src/Ice/Proxy.cs15
-rw-r--r--cs/src/Ice/ProxyIdentityKey.cs10
-rw-r--r--cs/src/Ice/Reference.cs33
-rw-r--r--cs/src/Ice/TcpConnector.cs11
-rw-r--r--cs/src/Ice/TcpEndpointI.cs17
-rw-r--r--cs/src/Ice/Timer.cs42
-rw-r--r--cs/src/Ice/UdpConnector.cs13
-rw-r--r--cs/src/Ice/UdpEndpointI.cs21
-rw-r--r--cs/src/Ice/Util.cs89
-rw-r--r--cs/src/IceSSL/ConnectorI.cs11
-rw-r--r--cs/src/IceSSL/EndpointI.cs17
-rw-r--r--cs/test/Ice/Makefile1
-rw-r--r--cs/test/Ice/Makefile.mak1
-rw-r--r--cs/test/Ice/hash/Client.cs550
-rw-r--r--cs/test/Ice/hash/Makefile29
-rw-r--r--cs/test/Ice/hash/Makefile.mak29
-rw-r--r--cs/test/Ice/hash/Test.ice97
-rwxr-xr-xcs/test/Ice/hash/client.exe.config6
-rw-r--r--cs/test/Ice/hash/generated/.gitignore1
-rwxr-xr-xcs/test/Ice/hash/run.py30
-rwxr-xr-xjava/allTests.py1
-rw-r--r--java/build.xml3
-rw-r--r--java/src/Freeze/SharedDbEnv.java4
-rw-r--r--java/src/Ice/LocalObject.java2
-rw-r--r--java/src/Ice/LocalObjectImpl.java6
-rw-r--r--java/src/Ice/Object.java5
-rw-r--r--java/src/Ice/ObjectImpl.java9
-rw-r--r--java/src/Ice/ObjectPrx.java5
-rw-r--r--java/src/Ice/ObjectPrxHelperBase.java9
-rw-r--r--java/src/Ice/ProxyIdentityFacetKey.java6
-rw-r--r--java/src/Ice/ProxyIdentityKey.java5
-rw-r--r--java/src/IceInternal/HashUtil.java120
-rw-r--r--java/src/IceInternal/OpaqueEndpointI.java12
-rw-r--r--java/src/IceInternal/Reference.java23
-rw-r--r--java/src/IceInternal/RoutableReference.java4
-rw-r--r--java/src/IceInternal/TcpConnector.java13
-rw-r--r--java/src/IceInternal/TcpEndpointI.java17
-rw-r--r--java/src/IceInternal/UdpConnector.java15
-rw-r--r--java/src/IceInternal/UdpEndpointI.java21
-rw-r--r--java/src/IceSSL/ConnectorI.java13
-rw-r--r--java/src/IceSSL/EndpointI.java17
-rw-r--r--java/test/Ice/hash/Client.java429
-rw-r--r--java/test/Ice/hash/Test.ice71
-rwxr-xr-xjava/test/Ice/hash/run.py28
78 files changed, 2025 insertions, 452 deletions
diff --git a/cpp/allTests.py b/cpp/allTests.py
index c0432217228..f124bf519bd 100755
--- a/cpp/allTests.py
+++ b/cpp/allTests.py
@@ -66,6 +66,7 @@ tests = [
("Ice/defaultServant", ["core"]),
("Ice/defaultValue", ["core"]),
("Ice/invoke", ["core", "novc6"]),
+ ("Ice/hash", ["once"]),
("IceSSL/configuration", ["once", "novalgrind"]), # valgrind doesn't work well with openssl
("IceBox/configuration", ["core", "noipv6", "novc6", "nomingw"]),
("Freeze/dbmap", ["once", "novc6", "nomingw"]),
diff --git a/cpp/src/Ice/HashUtil.h b/cpp/src/Ice/HashUtil.h
index 7b6c7f6a27b..d23ee90ff0c 100644
--- a/cpp/src/Ice/HashUtil.h
+++ b/cpp/src/Ice/HashUtil.h
@@ -15,13 +15,13 @@ namespace IceInternal
inline void
hashAdd(Ice::Int& hashCode, Ice::Int value)
{
- hashCode = hashCode * 5 + value;
+ hashCode = ((hashCode << 5) + hashCode) ^ (2654435761u * value);
}
inline void
hashAdd(Ice::Int& hashCode, bool value)
{
- hashCode = hashCode * 5 + static_cast<Ice::Int>(value);
+ hashCode = ((hashCode << 5) + hashCode) ^ (value ? 1 : 0);
}
inline void
@@ -29,7 +29,7 @@ hashAdd(Ice::Int& hashCode, const std::string& value)
{
for(std::string::const_iterator p = value.begin(); p != value.end(); ++p)
{
- hashCode = 5 * hashCode + *p;
+ hashCode = ((hashCode << 5) + hashCode) ^ *p;
}
}
@@ -52,5 +52,4 @@ hashAdd(Ice::Int& hashCode, const std::map<K, V>& map)
}
}
-
}
diff --git a/cpp/src/Ice/Makefile.mak b/cpp/src/Ice/Makefile.mak
index 522da39075e..b5378cba7ef 100644
--- a/cpp/src/Ice/Makefile.mak
+++ b/cpp/src/Ice/Makefile.mak
@@ -124,7 +124,6 @@ CPPFLAGS = $(CPPFLAGS) -DCOMPSUFFIX=\"$(COMPSUFFIX)\"
SLICE2CPPFLAGS = --ice --include-dir Ice --dll-export ICE_API $(SLICE2CPPFLAGS)
LINKWITH = $(BASELIBS) $(BZIP2_LIBS) $(ICE_OS_LIBS) ws2_32.lib Iphlpapi.lib
-
PDBFLAGS = /pdb:$(DLLNAME:.dll=.pdb)
LD_DLLFLAGS = $(LD_DLLFLAGS) /entry:"ice_DLL_Main"
RES_FILE = Ice.res
diff --git a/cpp/src/Ice/OpaqueEndpointI.cpp b/cpp/src/Ice/OpaqueEndpointI.cpp
index a3ed87efd85..80e3146a327 100644
--- a/cpp/src/Ice/OpaqueEndpointI.cpp
+++ b/cpp/src/Ice/OpaqueEndpointI.cpp
@@ -433,7 +433,8 @@ IceInternal::OpaqueEndpointI::operator<(const LocalObject& r) const
Ice::Int
IceInternal::OpaqueEndpointI::hashInit() const
{
- Ice::Int h = _type;
+ Ice::Int h = 5381;
+ hashAdd(h, _type);
hashAdd(h, _rawEncoding.major);
hashAdd(h, _rawEncoding.minor);
hashAdd(h, _rawBytes);
diff --git a/cpp/src/Ice/Reference.cpp b/cpp/src/Ice/Reference.cpp
index 3ec8385c214..0b8a6eaff7b 100644
--- a/cpp/src/Ice/Reference.cpp
+++ b/cpp/src/Ice/Reference.cpp
@@ -483,12 +483,20 @@ IceInternal::Reference::Reference(const Reference& r) :
int
IceInternal::Reference::hashInit() const
{
- Int h = static_cast<Int>(_mode);
+ Int h = 5381;
+ hashAdd(h, static_cast<Int>(_mode));
+ hashAdd(h, _secure);
hashAdd(h, _identity.name);
hashAdd(h, _identity.category);
hashAdd(h, _context->getValue());
hashAdd(h, _facet);
- hashAdd(h, _secure);
+ hashAdd(h, _overrideCompress);
+ if(_overrideCompress)
+ {
+ hashAdd(h, _compress);
+ }
+ hashAdd(h, _encoding.major);
+ hashAdd(h, _encoding.minor);
return h;
}
diff --git a/cpp/src/Ice/TcpEndpointI.cpp b/cpp/src/Ice/TcpEndpointI.cpp
index e38885976fb..9c64b22057b 100644
--- a/cpp/src/Ice/TcpEndpointI.cpp
+++ b/cpp/src/Ice/TcpEndpointI.cpp
@@ -547,10 +547,15 @@ IceInternal::TcpEndpointI::operator<(const LocalObject& r) const
Ice::Int
IceInternal::TcpEndpointI::hashInit() const
{
- Ice::Int h = 0;
+ Ice::Int h = 5381;
+ hashAdd(h, TCPEndpointType);
hashAdd(h, _host);
hashAdd(h, _port);
hashAdd(h, _timeout);
+ hashAdd(h, _protocol.major);
+ hashAdd(h, _protocol.minor);
+ hashAdd(h, _encoding.major);
+ hashAdd(h, _encoding.minor);
hashAdd(h, _connectionId);
hashAdd(h, _compress);
return h;
diff --git a/cpp/src/Ice/UdpEndpointI.cpp b/cpp/src/Ice/UdpEndpointI.cpp
index f8dacf01d7a..db5f1a495b7 100644
--- a/cpp/src/Ice/UdpEndpointI.cpp
+++ b/cpp/src/Ice/UdpEndpointI.cpp
@@ -632,12 +632,17 @@ IceInternal::UdpEndpointI::operator<(const LocalObject& r) const
Ice::Int
IceInternal::UdpEndpointI::hashInit() const
{
- Ice::Int h = 0;
+ Ice::Int h = 5381;
+ hashAdd(h, UDPEndpointType);
hashAdd(h, _host);
hashAdd(h, _port);
hashAdd(h, _mcastInterface);
hashAdd(h, _mcastTtl);
hashAdd(h, _connect);
+ hashAdd(h, _protocol.major);
+ hashAdd(h, _protocol.minor);
+ hashAdd(h, _encoding.major);
+ hashAdd(h, _encoding.minor);
hashAdd(h, _connectionId);
hashAdd(h, _compress);
return h;
diff --git a/cpp/src/Ice/winrt/StreamEndpointI.cpp b/cpp/src/Ice/winrt/StreamEndpointI.cpp
index 1f1c030f84e..d048945f0a0 100644
--- a/cpp/src/Ice/winrt/StreamEndpointI.cpp
+++ b/cpp/src/Ice/winrt/StreamEndpointI.cpp
@@ -587,10 +587,15 @@ IceInternal::StreamEndpointI::operator<(const LocalObject& r) const
Ice::Int
IceInternal::StreamEndpointI::hashInit() const
{
- Ice::Int h = 0;
+ Ice::Int h = 5381;
+ hashAdd(h, _type);
hashAdd(h, _host);
hashAdd(h, _port);
hashAdd(h, _timeout);
+ hashAdd(h, _protocol.major);
+ hashAdd(h, _protocol.minor);
+ hashAdd(h, _encoding.major);
+ hashAdd(h, _encoding.minor);
hashAdd(h, _connectionId);
hashAdd(h, _compress);
return h;
diff --git a/cpp/src/IceSSL/EndpointI.cpp b/cpp/src/IceSSL/EndpointI.cpp
index a9eb8e707d8..0b33e896741 100644
--- a/cpp/src/IceSSL/EndpointI.cpp
+++ b/cpp/src/IceSSL/EndpointI.cpp
@@ -544,10 +544,15 @@ IceSSL::EndpointI::operator<(const Ice::LocalObject& r) const
Ice::Int
IceSSL::EndpointI::hashInit() const
{
- Int h = 0;
+ Int h = 5381;
+ IceInternal::hashAdd(h, EndpointType);
IceInternal::hashAdd(h, _host);
IceInternal::hashAdd(h, _port);
IceInternal::hashAdd(h, _timeout);
+ IceInternal::hashAdd(h, _protocol.major);
+ IceInternal::hashAdd(h, _protocol.minor);
+ IceInternal::hashAdd(h, _encoding.major);
+ IceInternal::hashAdd(h, _encoding.minor);
IceInternal::hashAdd(h, _connectionId);
IceInternal::hashAdd(h, _compress);
return h;
diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp
index f636b758a77..f76877a2065 100644
--- a/cpp/src/slice2cs/Gen.cpp
+++ b/cpp/src/slice2cs/Gen.cpp
@@ -2844,8 +2844,9 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
}
else
{
- _out << nl << "int h__ = 0;";
+ _out << nl << "int h__ = 5381;";
}
+ _out << nl << "IceInternal.HashUtil.hashAdd(ref h__, \"" << p->scoped() << "\");";
writeMemberHashCode(dataMembers, DotNet::Exception);
_out << nl << "return h__;";
_out << eb;
@@ -3252,7 +3253,8 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p)
emitGeneratedCodeAttribute();
_out << nl << "public override int GetHashCode()";
_out << sb;
- _out << nl << "int h__ = 0;";
+ _out << nl << "int h__ = 5381;";
+ _out << nl << "IceInternal.HashUtil.hashAdd(ref h__, \"" << p->scoped() << "\");";
writeMemberHashCode(dataMembers, isClass ? DotNet::ICloneable : 0);
_out << nl << "return h__;";
_out << eb;
@@ -3678,73 +3680,7 @@ Slice::Gen::TypesVisitor::writeMemberHashCode(const DataMemberList& dataMembers,
{
for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
- string memberName = fixId((*q)->name(), baseTypes);
- TypePtr memberType = (*q)->type();
- bool isValue = isValueType(memberType);
- if(!isValue)
- {
- _out << nl << "if(" << memberName << " != null)";
- _out << sb;
- }
- SequencePtr seq = SequencePtr::dynamicCast(memberType);
- if(seq)
- {
- string meta;
- bool isSerializable = seq->findMetaData("clr:serializable", meta);
- bool isGeneric = seq->findMetaData("clr:generic:", meta);
- bool isArray = !isSerializable && !isGeneric && !seq->hasMetaData("clr:collection");
- if(isArray)
- {
- //
- // GetHashCode() for native arrays does not have value semantics.
- //
- _out << nl << "h__ = 5 * h__ + IceUtilInternal.Arrays.GetHashCode(" << memberName << ");";
- }
- else if(isGeneric)
- {
- //
- // GetHashCode() for generic types does not have value semantics.
- //
- _out << nl << "h__ = 5 * h__ + IceUtilInternal.Collections.SequenceGetHashCode(" << memberName << ");";
- }
- else
- {
- //
- // GetHashCode() for CollectionBase has value semantics.
- //
- _out << nl << "h__ = 5 * h__ + " << memberName << ".GetHashCode();";
- }
- }
- else
- {
- DictionaryPtr dict = DictionaryPtr::dynamicCast(memberType);
- if(dict)
- {
- if(dict->hasMetaData("clr:collection"))
- {
- //
- // GetHashCode() for DictionaryBase has value semantics.
- //
- _out << nl << "h__ = 5 * h__ + " << memberName << ".GetHashCode();";
- }
- else
- {
- //
- // GetHashCode() for generic types does not have value semantics.
- //
- _out << nl << "h__ = 5 * h__ + IceUtilInternal.Collections.DictionaryGetHashCode(" << memberName
- << ");";
- }
- }
- else
- {
- _out << nl << "h__ = 5 * h__ + " << memberName << ".GetHashCode();";
- }
- }
- if(!isValue)
- {
- _out << eb;
- }
+ _out << nl << "IceInternal.HashUtil.hashAdd(ref h__, " << fixId((*q)->name(), baseTypes) << ");";
}
}
diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp
index 3f0c23c2aca..1a9b678b6aa 100644
--- a/cpp/src/slice2java/Gen.cpp
+++ b/cpp/src/slice2java/Gen.cpp
@@ -465,110 +465,6 @@ Slice::JavaVisitor::writeDelegateThrowsClause(const string& package, const Excep
}
void
-Slice::JavaVisitor::writeHashCode(Output& out, const TypePtr& type, const string& name, int& iter,
- const StringList& metaData)
-{
- BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
- if(builtin)
- {
- switch(builtin->kind())
- {
- case Builtin::KindByte:
- case Builtin::KindShort:
- case Builtin::KindLong:
- {
- out << nl << "__h = 5 * __h + (int)" << name << ';';
- break;
- }
- case Builtin::KindBool:
- {
- out << nl << "__h = 5 * __h + (" << name << " ? 1 : 0);";
- break;
- }
- case Builtin::KindInt:
- {
- out << nl << "__h = 5 * __h + " << name << ';';
- break;
- }
- case Builtin::KindFloat:
- {
- out << nl << "__h = 5 * __h + java.lang.Float.floatToIntBits(" << name << ");";
- break;
- }
- case Builtin::KindDouble:
- {
- out << nl << "__h = 5 * __h + (int)java.lang.Double.doubleToLongBits(" << name << ");";
- break;
- }
- case Builtin::KindString:
- {
- out << nl << "if(" << name << " != null)";
- out << sb;
- out << nl << "__h = 5 * __h + " << name << ".hashCode();";
- out << eb;
- break;
- }
- case Builtin::KindObject:
- case Builtin::KindObjectProxy:
- case Builtin::KindLocalObject:
- {
- out << nl << "if(" << name << " != null)";
- out << sb;
- out << nl << "__h = 5 * __h + " << name << ".hashCode();";
- out << eb;
- break;
- }
- }
- return;
- }
-
- ProxyPtr prx = ProxyPtr::dynamicCast(type);
- ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
- DictionaryPtr dict = DictionaryPtr::dynamicCast(type);
- if(prx || cl || dict)
- {
- out << nl << "if(" << name << " != null)";
- out << sb;
- out << nl << "__h = 5 * __h + " << name << ".hashCode();";
- out << eb;
- return;
- }
-
- SequencePtr seq = SequencePtr::dynamicCast(type);
- if(seq)
- {
- bool customType = hasTypeMetaData(seq, metaData);
-
- out << nl << "if(" << name << " != null)";
- out << sb;
- if(customType)
- {
- out << nl << "__h = 5 * __h + " << name << ".hashCode();";
- }
- else
- {
- out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < " << name << ".length; __i" << iter
- << "++)";
- out << sb;
- ostringstream elem;
- elem << name << "[__i" << iter << ']';
- iter++;
- writeHashCode(out, seq->type(), elem.str(), iter);
- out << eb;
- }
- out << eb;
- return;
- }
-
- ConstructedPtr constructed = ConstructedPtr::dynamicCast(type);
- assert(constructed);
- out << nl << "if(" << name << " != null)";
- out << sb;
- out << nl << "__h = 5 * __h + " << name << ".hashCode();";
- out << eb;
-}
-
-void
Slice::JavaVisitor::writeMarshalDataMember(Output& out, const string& package, const DataMemberPtr& member, int& iter)
{
if(!member->optional())
@@ -2528,14 +2424,6 @@ Slice::Gen::TieVisitor::visitClassDefStart(const ClassDefPtr& p)
if(p->isLocal())
{
- out << sp << nl << "/**";
- out << nl << " * @deprecated This method is deprecated, use hashCode instead.";
- out << nl << " **/";
- out << nl << "public int" << nl << "ice_hash()";
- out << sb;
- out << nl << "return hashCode();";
- out << eb;
-
out << sp << nl << "public java.lang.Object" << nl << "clone()";
out.inc();
out << nl << "throws java.lang.CloneNotSupportedException";
@@ -3772,13 +3660,13 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p)
out << sp << nl << "public int" << nl << "hashCode()";
out << sb;
- out << nl << "int __h = 0;";
+ out << nl << "int __h = 5381;";
+ out << nl << "__h = IceInternal.HashUtil.hashAdd(__h, \"" << p->scoped() << "\");";
iter = 0;
for(d = members.begin(); d != members.end(); ++d)
{
string memberName = fixKwd((*d)->name());
- StringList metaData = (*d)->getMetaData();
- writeHashCode(out, (*d)->type(), memberName, iter, metaData);
+ out << nl << "__h = IceInternal.HashUtil.hashAdd(__h, " << memberName << ");";
}
out << nl << "return __h;";
out << eb;
diff --git a/cpp/test/Ice/Makefile b/cpp/test/Ice/Makefile
index c9f3b3390ec..15092758312 100644
--- a/cpp/test/Ice/Makefile
+++ b/cpp/test/Ice/Makefile
@@ -24,6 +24,7 @@ SUBDIRS = proxy \
adapterDeactivation \
slicing \
gc \
+ hash \
checksum \
stream \
dispatcher \
diff --git a/cpp/test/Ice/Makefile.mak b/cpp/test/Ice/Makefile.mak
index 12a0b8186de..eaa8112b30a 100644
--- a/cpp/test/Ice/Makefile.mak
+++ b/cpp/test/Ice/Makefile.mak
@@ -20,6 +20,7 @@ SUBDIRS = proxy \
objects \
location \
adapterDeactivation \
+ hash \
ami \
invoke \
dispatcher \
@@ -28,7 +29,7 @@ SUBDIRS = proxy \
retry \
timeout \
udp \
- stream \
+ stream
!if "$(WINRT)" != "yes"
SUBDIRS = $(SUBDIRS) \
diff --git a/cpp/test/Ice/hash/.depend b/cpp/test/Ice/hash/.depend
new file mode 100644
index 00000000000..d48f87cfd5c
--- /dev/null
+++ b/cpp/test/Ice/hash/.depend
@@ -0,0 +1,3 @@
+Client$(OBJEXT): Client.cpp $(includedir)/Ice/Ice.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Initialize.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/IceUtil/ScopedArray.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/MutexProtocol.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/EndpointF.h $(includedir)/Ice/EndpointTypes.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsync.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/Cond.h $(includedir)/IceUtil/Timer.h $(includedir)/IceUtil/Thread.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/InstanceF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/LoggerF.h $(includedir)/Ice/StatsF.h $(includedir)/Ice/Dispatcher.h $(includedir)/Ice/StringConverter.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/BuiltinSequences.h $(includedir)/Ice/Stream.h $(includedir)/IceUtil/Unicode.h $(includedir)/Ice/LocalException.h $(includedir)/Ice/Properties.h $(includedir)/Ice/Outgoing.h $(includedir)/Ice/Incoming.h $(includedir)/Ice/ServantLocatorF.h $(includedir)/Ice/ServantManagerF.h $(includedir)/Ice/Direct.h $(includedir)/Ice/Logger.h $(includedir)/Ice/LoggerUtil.h $(includedir)/Ice/Stats.h $(includedir)/Ice/Communicator.h $(includedir)/Ice/RouterF.h $(includedir)/Ice/LocatorF.h $(includedir)/Ice/PluginF.h $(includedir)/Ice/ImplicitContextF.h $(includedir)/Ice/CommunicatorAsync.h $(includedir)/Ice/ObjectFactory.h $(includedir)/Ice/ObjectAdapter.h $(includedir)/Ice/FacetMap.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/ServantLocator.h $(includedir)/Ice/IncomingAsync.h $(includedir)/Ice/Process.h $(includedir)/Ice/Application.h $(includedir)/Ice/Connection.h $(includedir)/Ice/ConnectionAsync.h $(includedir)/Ice/Functional.h $(includedir)/IceUtil/Functional.h $(includedir)/Ice/ImplicitContext.h $(includedir)/Ice/Locator.h $(includedir)/Ice/FactoryTableInit.h $(includedir)/Ice/FactoryTable.h $(includedir)/Ice/UserExceptionFactory.h $(includedir)/Ice/ProcessF.h $(includedir)/Ice/Router.h $(includedir)/Ice/DispatchInterceptor.h $(includedir)/Ice/IconvStringConverter.h Test.h ../../include/TestCommon.h $(includedir)/IceUtil/IceUtil.h $(includedir)/IceUtil/AbstractMutex.h $(includedir)/IceUtil/Cache.h $(includedir)/IceUtil/CountDownLatch.h $(includedir)/IceUtil/CtrlCHandler.h $(includedir)/IceUtil/MutexPtrLock.h $(includedir)/IceUtil/RecMutex.h $(includedir)/IceUtil/UUID.h
+Test$(OBJEXT): Test.cpp Test.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/MutexProtocol.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/EndpointF.h $(includedir)/IceUtil/ScopedArray.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/EndpointTypes.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsync.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/Cond.h $(includedir)/IceUtil/Timer.h $(includedir)/IceUtil/Thread.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/InstanceF.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/Outgoing.h $(includedir)/Ice/Incoming.h $(includedir)/Ice/ServantLocatorF.h $(includedir)/Ice/ServantManagerF.h $(includedir)/Ice/Direct.h $(includedir)/Ice/FactoryTableInit.h $(includedir)/Ice/FactoryTable.h $(includedir)/Ice/UserExceptionFactory.h $(includedir)/Ice/LocalException.h $(includedir)/Ice/BuiltinSequences.h $(includedir)/Ice/Stream.h $(includedir)/Ice/ObjectFactory.h $(includedir)/IceUtil/Iterator.h
+Test.h Test.cpp: Test.ice $(SLICE2CPP) $(SLICEPARSERLIB)
diff --git a/cpp/test/Ice/hash/.depend.mak b/cpp/test/Ice/hash/.depend.mak
new file mode 100644
index 00000000000..ebd394b6929
--- /dev/null
+++ b/cpp/test/Ice/hash/.depend.mak
@@ -0,0 +1,3 @@
+Client$(OBJEXT): Client.cpp "$(includedir)/Ice/Ice.h" "$(includedir)/IceUtil/Config.h" "$(includedir)/Ice/Initialize.h" "$(includedir)/Ice/CommunicatorF.h" "$(includedir)/Ice/LocalObjectF.h" "$(includedir)/IceUtil/Shared.h" "$(includedir)/Ice/Handle.h" "$(includedir)/IceUtil/Handle.h" "$(includedir)/IceUtil/Exception.h" "$(includedir)/Ice/Config.h" "$(includedir)/Ice/ProxyF.h" "$(includedir)/Ice/ProxyHandle.h" "$(includedir)/Ice/ObjectF.h" "$(includedir)/Ice/Exception.h" "$(includedir)/Ice/LocalObject.h" "$(includedir)/IceUtil/ScopedArray.h" "$(includedir)/Ice/UndefSysMacros.h" "$(includedir)/Ice/PropertiesF.h" "$(includedir)/Ice/Proxy.h" "$(includedir)/IceUtil/Mutex.h" "$(includedir)/IceUtil/Lock.h" "$(includedir)/IceUtil/ThreadException.h" "$(includedir)/IceUtil/Time.h" "$(includedir)/IceUtil/MutexProtocol.h" "$(includedir)/Ice/ProxyFactoryF.h" "$(includedir)/Ice/ConnectionIF.h" "$(includedir)/Ice/RequestHandlerF.h" "$(includedir)/Ice/EndpointIF.h" "$(includedir)/Ice/EndpointF.h" "$(includedir)/Ice/EndpointTypes.h" "$(includedir)/Ice/ObjectAdapterF.h" "$(includedir)/Ice/ReferenceF.h" "$(includedir)/Ice/OutgoingAsync.h" "$(includedir)/IceUtil/Monitor.h" "$(includedir)/IceUtil/Cond.h" "$(includedir)/IceUtil/Timer.h" "$(includedir)/IceUtil/Thread.h" "$(includedir)/Ice/OutgoingAsyncF.h" "$(includedir)/Ice/InstanceF.h" "$(includedir)/Ice/Current.h" "$(includedir)/Ice/ConnectionF.h" "$(includedir)/Ice/Identity.h" "$(includedir)/Ice/BasicStream.h" "$(includedir)/Ice/ObjectFactoryF.h" "$(includedir)/Ice/Buffer.h" "$(includedir)/Ice/Protocol.h" "$(includedir)/Ice/StreamF.h" "$(includedir)/Ice/Object.h" "$(includedir)/Ice/GCShared.h" "$(includedir)/Ice/GCCountMap.h" "$(includedir)/Ice/IncomingAsyncF.h" "$(includedir)/Ice/LoggerF.h" "$(includedir)/Ice/StatsF.h" "$(includedir)/Ice/Dispatcher.h" "$(includedir)/Ice/StringConverter.h" "$(includedir)/Ice/Plugin.h" "$(includedir)/Ice/BuiltinSequences.h" "$(includedir)/Ice/Stream.h" "$(includedir)/IceUtil/Unicode.h" "$(includedir)/Ice/LocalException.h" "$(includedir)/Ice/Properties.h" "$(includedir)/Ice/Outgoing.h" "$(includedir)/Ice/Incoming.h" "$(includedir)/Ice/ServantLocatorF.h" "$(includedir)/Ice/ServantManagerF.h" "$(includedir)/Ice/Direct.h" "$(includedir)/Ice/Logger.h" "$(includedir)/Ice/LoggerUtil.h" "$(includedir)/Ice/Stats.h" "$(includedir)/Ice/Communicator.h" "$(includedir)/Ice/RouterF.h" "$(includedir)/Ice/LocatorF.h" "$(includedir)/Ice/PluginF.h" "$(includedir)/Ice/ImplicitContextF.h" "$(includedir)/Ice/CommunicatorAsync.h" "$(includedir)/Ice/ObjectFactory.h" "$(includedir)/Ice/ObjectAdapter.h" "$(includedir)/Ice/FacetMap.h" "$(includedir)/Ice/Endpoint.h" "$(includedir)/Ice/ServantLocator.h" "$(includedir)/Ice/IncomingAsync.h" "$(includedir)/Ice/Process.h" "$(includedir)/Ice/Application.h" "$(includedir)/Ice/Connection.h" "$(includedir)/Ice/ConnectionAsync.h" "$(includedir)/Ice/Functional.h" "$(includedir)/IceUtil/Functional.h" "$(includedir)/Ice/ImplicitContext.h" "$(includedir)/Ice/Locator.h" "$(includedir)/Ice/FactoryTableInit.h" "$(includedir)/Ice/FactoryTable.h" "$(includedir)/Ice/UserExceptionFactory.h" "$(includedir)/Ice/ProcessF.h" "$(includedir)/Ice/Router.h" "$(includedir)/Ice/DispatchInterceptor.h" "$(includedir)/Ice/IconvStringConverter.h" Test.h ../../include/TestCommon.h "$(includedir)/IceUtil/IceUtil.h" "$(includedir)/IceUtil/AbstractMutex.h" "$(includedir)/IceUtil/Cache.h" "$(includedir)/IceUtil/CountDownLatch.h" "$(includedir)/IceUtil/CtrlCHandler.h" "$(includedir)/IceUtil/MutexPtrLock.h" "$(includedir)/IceUtil/RecMutex.h" "$(includedir)/IceUtil/UUID.h"
+Test$(OBJEXT): Test.cpp Test.h "$(includedir)/Ice/LocalObjectF.h" "$(includedir)/IceUtil/Shared.h" "$(includedir)/IceUtil/Config.h" "$(includedir)/Ice/Handle.h" "$(includedir)/IceUtil/Handle.h" "$(includedir)/IceUtil/Exception.h" "$(includedir)/Ice/Config.h" "$(includedir)/Ice/ProxyF.h" "$(includedir)/Ice/ProxyHandle.h" "$(includedir)/Ice/ObjectF.h" "$(includedir)/Ice/Exception.h" "$(includedir)/Ice/LocalObject.h" "$(includedir)/Ice/Proxy.h" "$(includedir)/IceUtil/Mutex.h" "$(includedir)/IceUtil/Lock.h" "$(includedir)/IceUtil/ThreadException.h" "$(includedir)/IceUtil/Time.h" "$(includedir)/IceUtil/MutexProtocol.h" "$(includedir)/Ice/ProxyFactoryF.h" "$(includedir)/Ice/ConnectionIF.h" "$(includedir)/Ice/RequestHandlerF.h" "$(includedir)/Ice/EndpointIF.h" "$(includedir)/Ice/EndpointF.h" "$(includedir)/IceUtil/ScopedArray.h" "$(includedir)/Ice/UndefSysMacros.h" "$(includedir)/Ice/EndpointTypes.h" "$(includedir)/Ice/ObjectAdapterF.h" "$(includedir)/Ice/ReferenceF.h" "$(includedir)/Ice/OutgoingAsync.h" "$(includedir)/IceUtil/Monitor.h" "$(includedir)/IceUtil/Cond.h" "$(includedir)/IceUtil/Timer.h" "$(includedir)/IceUtil/Thread.h" "$(includedir)/Ice/OutgoingAsyncF.h" "$(includedir)/Ice/InstanceF.h" "$(includedir)/Ice/CommunicatorF.h" "$(includedir)/Ice/Current.h" "$(includedir)/Ice/ConnectionF.h" "$(includedir)/Ice/Identity.h" "$(includedir)/Ice/BasicStream.h" "$(includedir)/Ice/ObjectFactoryF.h" "$(includedir)/Ice/Buffer.h" "$(includedir)/Ice/Protocol.h" "$(includedir)/Ice/StreamF.h" "$(includedir)/Ice/Object.h" "$(includedir)/Ice/GCShared.h" "$(includedir)/Ice/GCCountMap.h" "$(includedir)/Ice/IncomingAsyncF.h" "$(includedir)/Ice/Outgoing.h" "$(includedir)/Ice/Incoming.h" "$(includedir)/Ice/ServantLocatorF.h" "$(includedir)/Ice/ServantManagerF.h" "$(includedir)/Ice/Direct.h" "$(includedir)/Ice/FactoryTableInit.h" "$(includedir)/Ice/FactoryTable.h" "$(includedir)/Ice/UserExceptionFactory.h" "$(includedir)/Ice/LocalException.h" "$(includedir)/Ice/BuiltinSequences.h" "$(includedir)/Ice/Stream.h" "$(includedir)/Ice/ObjectFactory.h" "$(includedir)/IceUtil/Iterator.h"
+Test.h Test.cpp: Test.ice "$(SLICE2CPP)" "$(SLICEPARSERLIB)"
diff --git a/cpp/test/Ice/hash/.gitignore b/cpp/test/Ice/hash/.gitignore
new file mode 100644
index 00000000000..d780341c0e4
--- /dev/null
+++ b/cpp/test/Ice/hash/.gitignore
@@ -0,0 +1,6 @@
+// Generated by makegitignore.py
+
+// IMPORTANT: Do not edit this file -- any edits made here will be lost!
+client
+Test.h
+Test.cpp
diff --git a/cpp/test/Ice/hash/Client.cpp b/cpp/test/Ice/hash/Client.cpp
new file mode 100644
index 00000000000..833ce35dc9d
--- /dev/null
+++ b/cpp/test/Ice/hash/Client.cpp
@@ -0,0 +1,139 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#include <Ice/Ice.h>
+#include <IceUtil/Random.h>
+#include <Test.h>
+#include <TestCommon.h>
+
+using namespace std;
+using namespace Test;
+
+DEFINE_TEST("client")
+
+int main(int argc, char** argv)
+{
+ cout << "testing proxy & endpoint hash algorithm collisions... " << flush;
+ map<Ice::Int, Ice::ObjectPrx> seenProxy;
+ map<Ice::Int, Ice::EndpointPtr> seenEndpoint;
+ unsigned int proxyCollisions = 0;
+ unsigned int endpointCollisions = 0;
+ unsigned int i = 0;
+ unsigned int maxCollisions = 10;
+ unsigned int maxIterations = 10000;
+
+ Ice::InitializationData id;
+ id.properties = Ice::createProperties(argc, argv);
+#ifndef ICE_OS_WINRT
+ //
+ // In Ice for WinRT IceSSL is part of Ice core.
+ //
+ id.properties->setProperty("Ice.Plugin.IceSSL", "IceSSL:createIceSSL");
+#endif
+ Ice::CommunicatorPtr communicator = Ice::initialize(id);
+ for(i = 0; proxyCollisions < maxCollisions &&
+ endpointCollisions < maxCollisions &&
+ i < maxIterations; ++i)
+ {
+ ostringstream os;
+ os << i << ":tcp -p " << IceUtilInternal::random(65536) << " -t 10" << IceUtilInternal::random(1000000)
+ << ":udp -p " << IceUtilInternal::random(65536) << " -h " << IceUtilInternal::random(100);
+
+ Ice::ObjectPrx obj = communicator->stringToProxy(os.str());
+ Ice::EndpointSeq endpoints = obj->ice_getEndpoints();
+ if(!seenProxy.insert(make_pair(obj->ice_getHash(), obj)).second)
+ {
+ ++proxyCollisions;
+ }
+ test(obj->ice_getHash() == obj->ice_getHash());
+
+ for(Ice::EndpointSeq::const_iterator j = endpoints.begin(); j != endpoints.end(); ++j)
+ {
+ Ice::EndpointPtr endpoint = (*j);
+ if(!seenEndpoint.insert(make_pair(endpoint->ice_getHash(), endpoint)).second)
+ {
+ if(endpoint == seenEndpoint[endpoint->ice_getHash()])
+ {
+ continue; // Same object
+ }
+ ++endpointCollisions;
+ }
+ test(endpoint->ice_getHash() == endpoint->ice_getHash());
+ }
+ }
+ test(proxyCollisions < maxCollisions);
+ test(endpointCollisions < maxCollisions);
+
+ //
+ // Check the same proxy produce the same hash, even when we recreate the proxy.
+ //
+ Ice::ObjectPrx prx1 = communicator->stringToProxy("Glacier2/router:tcp -p 10010");
+ Ice::ObjectPrx prx2 = communicator->stringToProxy("Glacier2/router:ssl -p 10011");
+ Ice::ObjectPrx prx3 = communicator->stringToProxy("Glacier2/router:udp -p 10012");
+ Ice::ObjectPrx prx4 = communicator->stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010");
+ Ice::ObjectPrx prx5 = communicator->stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011");
+ Ice::ObjectPrx prx6 = communicator->stringToProxy("Glacier2/router:udp -h zeroc.com -p 10012");
+ Ice::ObjectPrx prx7 = communicator->stringToProxy("Glacier2/router:tcp -p 10010 -t 10000");
+ Ice::ObjectPrx prx8 = communicator->stringToProxy("Glacier2/router:ssl -p 10011 -t 10000");
+ Ice::ObjectPrx prx9 = communicator->stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010 -t 10000");
+ Ice::ObjectPrx prx10 = communicator->stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011 -t 10000");
+
+ map<string, int> proxyMap;
+ proxyMap["prx1"] = prx1->ice_getHash();
+ proxyMap["prx2"] = prx2->ice_getHash();
+ proxyMap["prx3"] = prx3->ice_getHash();
+ proxyMap["prx4"] = prx4->ice_getHash();
+ proxyMap["prx5"] = prx5->ice_getHash();
+ proxyMap["prx6"] = prx6->ice_getHash();
+ proxyMap["prx7"] = prx7->ice_getHash();
+ proxyMap["prx8"] = prx8->ice_getHash();
+ proxyMap["prx9"] = prx9->ice_getHash();
+ proxyMap["prx10"] = prx10->ice_getHash();
+
+ test( communicator->stringToProxy("Glacier2/router:tcp -p 10010")->ice_getHash() == proxyMap["prx1"]);
+ test( communicator->stringToProxy("Glacier2/router:ssl -p 10011")->ice_getHash() == proxyMap["prx2"]);
+ test( communicator->stringToProxy("Glacier2/router:udp -p 10012")->ice_getHash() == proxyMap["prx3"]);
+ test( communicator->stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010")->ice_getHash() == proxyMap["prx4"]);
+ test( communicator->stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011")->ice_getHash() == proxyMap["prx5"]);
+ test( communicator->stringToProxy("Glacier2/router:udp -h zeroc.com -p 10012")->ice_getHash() == proxyMap["prx6"]);
+ test( communicator->stringToProxy("Glacier2/router:tcp -p 10010 -t 10000")->ice_getHash() == proxyMap["prx7"]);
+ test( communicator->stringToProxy("Glacier2/router:ssl -p 10011 -t 10000")->ice_getHash() == proxyMap["prx8"]);
+ test( communicator->stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010 -t 10000")->ice_getHash() == proxyMap["prx9"]);
+ test( communicator->stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011 -t 10000")->ice_getHash() == proxyMap["prx10"]);
+
+ cerr << "ok" << endl;
+
+ cout << "testing objects hash algorithm collisions... " << flush;
+ unsigned int objectCollisions = 0;
+ map<Ice::Int, Ice::ObjectPtr> seenObject;
+ for(i = 0; objectCollisions < maxCollisions && i < maxIterations; ++i)
+ {
+ Ice::ObjectPtr obj = new Point;
+ if(!seenObject.insert(make_pair(obj->ice_getHash(), obj)).second)
+ {
+ ++objectCollisions;
+ }
+ test(obj->ice_getHash() == obj->ice_getHash());
+ }
+ test(objectCollisions < maxCollisions);
+
+ cerr << "ok" << endl;
+ if(communicator)
+ {
+ try
+ {
+ communicator->destroy();
+ }
+ catch(const Ice::LocalException& ex)
+ {
+ cerr << ex << endl;
+ }
+ }
+ return EXIT_SUCCESS;
+}
diff --git a/cpp/test/Ice/hash/Makefile b/cpp/test/Ice/hash/Makefile
new file mode 100644
index 00000000000..250beb61bf6
--- /dev/null
+++ b/cpp/test/Ice/hash/Makefile
@@ -0,0 +1,33 @@
+# **********************************************************************
+#
+# Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
+#
+# This copy of Ice is licensed to you under the terms described in the
+# ICE_LICENSE file included in this distribution.
+#
+# **********************************************************************
+
+top_srcdir = ../../..
+
+CLIENT = client
+
+TARGETS = $(CLIENT)
+
+COBJS = Client.o
+
+OBJS = Test.o
+
+SRCS = $(COBJS:.o=.cpp) \
+ $(OBJS:.o=.cpp)
+
+SLICE_SRCS = Test.ice
+
+include $(top_srcdir)/config/Make.rules
+
+CPPFLAGS := -I. -I../../include $(CPPFLAGS)
+
+$(CLIENT): $(OBJS) $(COBJS)
+ rm -f $@
+ $(CXX) $(LDFLAGS) -o $@ $(COBJS) $(OBJS) $(LIBS)
+
+include .depend
diff --git a/cpp/test/Ice/hash/Makefile.mak b/cpp/test/Ice/hash/Makefile.mak
new file mode 100644
index 00000000000..b231eda718d
--- /dev/null
+++ b/cpp/test/Ice/hash/Makefile.mak
@@ -0,0 +1,49 @@
+# **********************************************************************
+#
+# Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
+#
+# This copy of Ice is licensed to you under the terms described in the
+# ICE_LICENSE file included in this distribution.
+#
+# **********************************************************************
+
+top_srcdir = ..\..\..
+
+!if "$(WINRT)" != "yes"
+NAME_PREFIX =
+EXT = .exe
+!else
+NAME_PREFIX = Ice_hash_
+EXT = .dll
+!endif
+
+CLIENT = $(NAME_PREFIX)client
+
+TARGETS = $(CLIENT)$(EXT)
+
+COBJS = Test.obj \
+ Client.obj
+
+SRCS = $(COBJS:.obj=.cpp)
+
+!include $(top_srcdir)/config/Make.rules.mak
+
+CPPFLAGS = -I. -I../../include $(CPPFLAGS) -DWIN32_LEAN_AND_MEAN
+
+
+!if "$(WINRT)" != "yes"
+LD_TESTFLAGS = $(LD_EXEFLAGS) $(SETARGV)
+!else
+LD_TESTFLAGS = $(LD_DLLFLAGS) /export:dllMain
+!endif
+
+!if "$(GENERATE_PDB)" == "yes"
+CPDBFLAGS = /pdb:$(CLIENT).pdb
+!endif
+
+$(CLIENT)$(EXT): $(COBJS)
+ $(LINK) $(LD_TESTFLAGS) $(CPDBFLAGS) $(SETARGV) $(COBJS) $(PREOUT)$@ $(PRELIBS)$(LIBS)
+ @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) && \
+ $(MT) -nologo -manifest $@.manifest -outputresource:$@;#1 && del /q $@.manifest
+
+!include .depend.mak
diff --git a/cpp/test/Ice/hash/Test.ice b/cpp/test/Ice/hash/Test.ice
new file mode 100644
index 00000000000..0bc77e005b6
--- /dev/null
+++ b/cpp/test/Ice/hash/Test.ice
@@ -0,0 +1,20 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#pragma once
+
+module Test
+{
+
+class Point
+{
+};
+
+};
+
diff --git a/cpp/test/Ice/hash/run.py b/cpp/test/Ice/hash/run.py
new file mode 100755
index 00000000000..3c4472ca289
--- /dev/null
+++ b/cpp/test/Ice/hash/run.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+# **********************************************************************
+#
+# Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
+#
+# This copy of Ice is licensed to you under the terms described in the
+# ICE_LICENSE file included in this distribution.
+#
+# **********************************************************************
+
+import os, sys
+
+path = [ ".", "..", "../..", "../../..", "../../../.." ]
+head = os.path.dirname(sys.argv[0])
+if len(head) > 0:
+ path = [os.path.join(head, p) for p in path]
+path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ]
+if len(path) == 0:
+ raise "can't find toplevel directory!"
+sys.path.append(os.path.join(path[0]))
+from scripts import *
+
+client = os.path.join(os.getcwd(), "client")
+TestUtil.simpleTest(client)
+
diff --git a/cpp/test/WinRT/TestSuite/MainPage.xaml.cpp b/cpp/test/WinRT/TestSuite/MainPage.xaml.cpp
index a572f49a96f..1b36c721576 100644
--- a/cpp/test/WinRT/TestSuite/MainPage.xaml.cpp
+++ b/cpp/test/WinRT/TestSuite/MainPage.xaml.cpp
@@ -300,7 +300,8 @@ static const TestCase allTest[] =
{"Ice\\retry", "Ice_retry_", "client.dll", "server.dll", 0, 0 },
{"Ice\\stream", "Ice_stream_", "client.dll", 0, 0, 0},
{"Ice\\timeout", "Ice_timeout_", "client.dll", "server.dll", 0, 0 },
- {"Ice\\udp", "Ice_udp_", "client.dll", "server.dll", 0, 0 }
+ {"Ice\\udp", "Ice_udp_", "client.dll", "server.dll", 0, 0 },
+ {"Ice\\hash", "Ice_hash_", "client.dll", 0, 0, 0}
};
class TestRunner : public IceUtil::Thread
diff --git a/cpp/test/WinRT/TestSuite/TestSuite.vcxproj b/cpp/test/WinRT/TestSuite/TestSuite.vcxproj
index 3e6321b9bc0..ee8bd766392 100644
--- a/cpp/test/WinRT/TestSuite/TestSuite.vcxproj
+++ b/cpp/test/WinRT/TestSuite/TestSuite.vcxproj
@@ -227,6 +227,9 @@
<None Include="..\..\Ice\facets\Ice_facets_server.dll">
<DeploymentContent>true</DeploymentContent>
</None>
+ <None Include="..\..\Ice\hash\Ice_hash_client.dll">
+ <DeploymentContent>true</DeploymentContent>
+ </None>
<None Include="..\..\Ice\hold\Ice_hold_client.dll">
<DeploymentContent>true</DeploymentContent>
</None>
diff --git a/cpp/test/WinRT/TestSuite/TestSuite.vcxproj.filters b/cpp/test/WinRT/TestSuite/TestSuite.vcxproj.filters
index a265ba6d68e..05791395699 100644
--- a/cpp/test/WinRT/TestSuite/TestSuite.vcxproj.filters
+++ b/cpp/test/WinRT/TestSuite/TestSuite.vcxproj.filters
@@ -196,6 +196,9 @@
<Filter>Tests</Filter>
</None>
<None Include="key.pfx" />
+ <None Include="..\..\Ice\hash\Ice_hash_client.dll">
+ <Filter>Tests</Filter>
+ </None>
</ItemGroup>
<ItemGroup>
<Page Include="MainPage.xaml" />
diff --git a/cs/allTests.py b/cs/allTests.py
index c2284249681..1a2e6093e62 100755
--- a/cs/allTests.py
+++ b/cs/allTests.py
@@ -59,6 +59,7 @@ tests = [
("Ice/defaultValue", ["core"]),
("Ice/threadPoolPriority", ["core", "nomono", "nosilverlight"]),
("Ice/invoke", ["core"]),
+ ("Ice/hash", ["once"]),
("IceBox/configuration", ["core", "noipv6", "nosilverlight"]),
("Glacier2/router", ["service", "nosilverlight"]),
("Glacier2/sessionHelper", ["service", "nosilverlight"]),
diff --git a/cs/config/Make.rules.cs b/cs/config/Make.rules.cs
index f09c2e66e85..13b64033ee9 100644
--- a/cs/config/Make.rules.cs
+++ b/cs/config/Make.rules.cs
@@ -133,6 +133,7 @@ endif
MCS = gmcs
MCSFLAGS = -warnaserror -d:MAKEFILE_BUILD
+
ifeq ($(DEBUG),yes)
MCSFLAGS := $(MCSFLAGS) -debug -define:DEBUG
endif
diff --git a/cs/config/Make.rules.mak.cs b/cs/config/Make.rules.mak.cs
index 34c51e33cb5..043b9f1dd11 100644
--- a/cs/config/Make.rules.mak.cs
+++ b/cs/config/Make.rules.mak.cs
@@ -120,6 +120,7 @@ generate_policies = yes
MCS = csc -nologo
MCSFLAGS = -warnaserror -d:MAKEFILE_BUILD
+
!if "$(DEBUG)" == "yes"
!if "$(OPTIMIZE)" == "yes"
MCSFLAGS = $(MCSFLAGS) -debug:pdbonly
diff --git a/cs/src/Ice/Arrays.cs b/cs/src/Ice/Arrays.cs
index f737531878e..a87e5419ef1 100644
--- a/cs/src/Ice/Arrays.cs
+++ b/cs/src/Ice/Arrays.cs
@@ -90,11 +90,15 @@ namespace IceUtilInternal
public static int GetHashCode(object[] arr)
{
- int h = 0;
+ int h = 5381;
for(int i = 0; i < arr.Length; i++)
{
- h = 5 * h + arr[i].GetHashCode();
+ object o = arr[i];
+ if(o != null)
+ {
+ IceInternal.HashUtil.hashAdd(ref h, o);
+ }
}
return h;
@@ -106,7 +110,10 @@ namespace IceUtilInternal
foreach(object o in arr)
{
- h = 5 * h + o.GetHashCode();
+ if(o != null)
+ {
+ IceInternal.HashUtil.hashAdd(ref h, o);
+ }
}
return h;
diff --git a/cs/src/Ice/CollectionBase.cs b/cs/src/Ice/CollectionBase.cs
index 78db0a998db..f338c88d1d0 100644
--- a/cs/src/Ice/CollectionBase.cs
+++ b/cs/src/Ice/CollectionBase.cs
@@ -304,13 +304,13 @@ namespace Ice
public override int GetHashCode()
{
- int hash = 0;
+ int h = 5381;
for(int i = 0; i < Count; ++i)
{
T v__ = list_[i];
- hash = 5 * hash + v__.GetHashCode();
+ IceInternal.HashUtil.hashAdd(ref h, v__);
}
- return hash;
+ return h;
}
public override bool Equals(object other)
diff --git a/cs/src/Ice/Collections.cs b/cs/src/Ice/Collections.cs
index 577e35fdaa9..66a71835c17 100644
--- a/cs/src/Ice/Collections.cs
+++ b/cs/src/Ice/Collections.cs
@@ -94,17 +94,12 @@ namespace IceUtilInternal
public static int SequenceGetHashCode(IEnumerable seq)
{
- int h = 0;
-
+ int h = 5381;
IEnumerator e = seq.GetEnumerator();
while(e.MoveNext())
{
- if(e.Current != null)
- {
- h = 5 * h + e.Current.GetHashCode();
- }
+ IceInternal.HashUtil.hashAdd(ref h, e.Current);
}
-
return h;
}
@@ -152,18 +147,13 @@ namespace IceUtilInternal
public static int DictionaryGetHashCode(IDictionary d)
{
- int h = 0;
-
+ int h = 5381;
IDictionaryEnumerator e = d.GetEnumerator();
while(e.MoveNext())
{
- h = 5 * h + e.Key.GetHashCode();
- if(e.Value != null)
- {
- h = 5 * h + e.Key.GetHashCode();
- }
+ IceInternal.HashUtil.hashAdd(ref h, e.Key);
+ IceInternal.HashUtil.hashAdd(ref h, e.Value);
}
-
return h;
}
}
diff --git a/cs/src/Ice/DictionaryBase.cs b/cs/src/Ice/DictionaryBase.cs
index 96b6f5bb82d..5d215b81224 100644
--- a/cs/src/Ice/DictionaryBase.cs
+++ b/cs/src/Ice/DictionaryBase.cs
@@ -137,13 +137,13 @@ namespace Ice
public override int GetHashCode()
{
- int hash = 0;
+ int h = 5381;
foreach(KeyValuePair<KT, VT> kvp in dict_)
{
- hash = 5 * hash + kvp.Key.GetHashCode();
- hash = 5 * hash + kvp.Value.GetHashCode();
+ IceInternal.HashUtil.hashAdd(ref h, kvp.Key);
+ IceInternal.HashUtil.hashAdd(ref h, kvp.Value);
}
- return hash;
+ return h;
}
public class CEnumerator : System.Collections.IDictionaryEnumerator
diff --git a/cs/src/Ice/EndpointI.cs b/cs/src/Ice/EndpointI.cs
index 9c36ac01254..bcf61e11af5 100644
--- a/cs/src/Ice/EndpointI.cs
+++ b/cs/src/Ice/EndpointI.cs
@@ -53,7 +53,10 @@ namespace IceInternal
public override int GetHashCode()
{
- return 5 * protocol_.GetHashCode() + encoding_.GetHashCode();
+ int h = 5381;
+ IceInternal.HashUtil.hashAdd(ref h, protocol_);
+ IceInternal.HashUtil.hashAdd(ref h, encoding_);
+ return h;
}
public virtual int CompareTo(EndpointI p)
diff --git a/cs/src/Ice/Object.cs b/cs/src/Ice/Object.cs
index 2095447350f..dcd6dcc53df 100644
--- a/cs/src/Ice/Object.cs
+++ b/cs/src/Ice/Object.cs
@@ -65,12 +65,6 @@ namespace Ice
public interface Object : System.ICloneable
{
/// <summary>
- /// This method is deprecated. Use GetHashCode instead.
- /// </summary>
- [Obsolete("This method is deprecated. Use GetHashCode instead.")]
- int ice_hash();
-
- /// <summary>
/// Tests whether this object supports a specific Slice interface.
/// </summary>
///
@@ -182,15 +176,6 @@ namespace Ice
}
/// <summary>
- /// This method is deprecated. Use GetHashCode instead.
- /// </summary>
- [Obsolete("This method is deprecated. Use GetHashCode instead.")]
- public virtual int ice_hash()
- {
- return GetHashCode();
- }
-
- /// <summary>
/// Returns a copy of the object. The cloned object contains field-for-field copies
/// of the state.
/// </summary>
diff --git a/cs/src/Ice/OpaqueEndpointI.cs b/cs/src/Ice/OpaqueEndpointI.cs
index 15bb3ff4243..68c3be9b1bc 100644
--- a/cs/src/Ice/OpaqueEndpointI.cs
+++ b/cs/src/Ice/OpaqueEndpointI.cs
@@ -417,12 +417,11 @@ namespace IceInternal
private void calcHashValue()
{
- _hashCode = _type;
- _hashCode = 5 * _hashCode + _rawEncoding.GetHashCode();
- for(int i = 0; i < _rawBytes.Length; i++)
- {
- _hashCode = 5 * _hashCode + _rawBytes[i];
- }
+ int h = 5381;
+ IceInternal.HashUtil.hashAdd(ref h, _type);
+ IceInternal.HashUtil.hashAdd(ref h, _rawEncoding);
+ IceInternal.HashUtil.hashAdd(ref h, _rawBytes);
+ _hashCode = h;
}
private short _type;
diff --git a/cs/src/Ice/Proxy.cs b/cs/src/Ice/Proxy.cs
index 309db3ac3b5..2e74a47e9c2 100644
--- a/cs/src/Ice/Proxy.cs
+++ b/cs/src/Ice/Proxy.cs
@@ -84,12 +84,6 @@ namespace Ice
public interface ObjectPrx
{
/// <summary>
- /// This method is deprecated. Use GetHashCode instead.
- /// </summary>
- [Obsolete("This method is deprecated. Use GetHashCode instead.")]
- int ice_getHash();
-
- /// <summary>
/// Returns the communicator that created this proxy.
/// </summary>
/// <returns>The communicator that created this proxy.</returns>
@@ -756,15 +750,6 @@ namespace Ice
}
/// <summary>
- /// This method is deprecated. Use GetHashCode instead.
- /// </summary>
- [Obsolete("This method is deprecated. Use GetHashCode instead.")]
- public int ice_getHash()
- {
- return _reference.GetHashCode();
- }
-
- /// <summary>
/// Returns the communicator that created this proxy.
/// </summary>
/// <returns>The communicator that created this proxy.</returns>
diff --git a/cs/src/Ice/ProxyIdentityKey.cs b/cs/src/Ice/ProxyIdentityKey.cs
index 546b795ddd4..85a516079c7 100644
--- a/cs/src/Ice/ProxyIdentityKey.cs
+++ b/cs/src/Ice/ProxyIdentityKey.cs
@@ -7,6 +7,7 @@
//
// **********************************************************************
+using System;
using System.Globalization;
namespace Ice
@@ -25,7 +26,9 @@ namespace Ice
/// <returns>The hash value for the proxy based on the identity.</returns>
public int GetHashCode(object obj)
{
- return ((Ice.ObjectPrx)obj).ice_getIdentity().GetHashCode();
+ int h = 5381;
+ IceInternal.HashUtil.hashAdd(ref h, ((Ice.ObjectPrx)obj).ice_getIdentity());
+ return h;
}
/// Compares two proxies for equality.
@@ -84,7 +87,10 @@ namespace Ice
Ice.ObjectPrx o = (Ice.ObjectPrx)obj;
Ice.Identity identity = o.ice_getIdentity();
string facet = o.ice_getFacet();
- return 5 * identity.GetHashCode() + facet.GetHashCode();
+ int h = 5381;
+ IceInternal.HashUtil.hashAdd(ref h, identity);
+ IceInternal.HashUtil.hashAdd(ref h, facet);
+ return h;
}
/// Compares two proxies for equality.
diff --git a/cs/src/Ice/Reference.cs b/cs/src/Ice/Reference.cs
index e8030c750e0..da94201b3ea 100644
--- a/cs/src/Ice/Reference.cs
+++ b/cs/src/Ice/Reference.cs
@@ -197,25 +197,21 @@ namespace IceInternal
{
return hashValue_;
}
-
- int h = (int)mode_;
-
- h = 5 * h + identity_.GetHashCode();
-
- foreach(KeyValuePair<string, string> p in context_)
+ int h = 5381;
+ IceInternal.HashUtil.hashAdd(ref h, mode_);
+ IceInternal.HashUtil.hashAdd(ref h, secure_);
+ IceInternal.HashUtil.hashAdd(ref h, identity_);
+ IceInternal.HashUtil.hashAdd(ref h, context_);
+ IceInternal.HashUtil.hashAdd(ref h, facet_);
+ IceInternal.HashUtil.hashAdd(ref h, overrideCompress_);
+ if(overrideCompress_)
{
- h = 5 * h + p.Key.GetHashCode();
- h = 5 * h + p.Value.GetHashCode();
+ IceInternal.HashUtil.hashAdd(ref h, compress_);
}
-
- h = 5 * h + facet_.GetHashCode();
-
- h = 5 * h + (secure_ ? 1 : 0);
-
+ IceInternal.HashUtil.hashAdd(ref h, encoding_);
hashValue_ = h;
hashInitialized_ = true;
-
- return h;
+ return hashValue_;
}
}
@@ -1043,10 +1039,9 @@ namespace IceInternal
{
if(!hashInitialized_)
{
- base.GetHashCode(); // Initializes hashValue_.
-
- // Add hash of adapter ID to base hash.
- hashValue_ = 5 * hashValue_ + _adapterId.GetHashCode();
+ int h = base.GetHashCode(); // Initializes hashValue_.
+ IceInternal.HashUtil.hashAdd(ref h, _adapterId);
+ hashValue_ = h;
}
return hashValue_;
}
diff --git a/cs/src/Ice/TcpConnector.cs b/cs/src/Ice/TcpConnector.cs
index 64d2c0b27bb..5f322293d20 100644
--- a/cs/src/Ice/TcpConnector.cs
+++ b/cs/src/Ice/TcpConnector.cs
@@ -79,11 +79,12 @@ namespace IceInternal
_encoding = encoding;
_connectionId = connectionId;
- _hashCode = _addr.GetHashCode();
- _hashCode = 5 * _hashCode + _timeout;
- _hashCode = 5 * _hashCode + _protocol.GetHashCode();
- _hashCode = 5 * _hashCode + _encoding.GetHashCode();
- _hashCode = 5 * _hashCode + _connectionId.GetHashCode();
+ _hashCode = 5381;
+ IceInternal.HashUtil.hashAdd(ref _hashCode, _addr);
+ IceInternal.HashUtil.hashAdd(ref _hashCode, _timeout);
+ IceInternal.HashUtil.hashAdd(ref _hashCode, _protocol);
+ IceInternal.HashUtil.hashAdd(ref _hashCode, _encoding);
+ IceInternal.HashUtil.hashAdd(ref _hashCode, _connectionId);
}
public override bool Equals(object obj)
diff --git a/cs/src/Ice/TcpEndpointI.cs b/cs/src/Ice/TcpEndpointI.cs
index 6d6564437ca..4500d1e903a 100644
--- a/cs/src/Ice/TcpEndpointI.cs
+++ b/cs/src/Ice/TcpEndpointI.cs
@@ -564,13 +564,16 @@ namespace IceInternal
private void calcHashValue()
{
- _hashCode = _host.GetHashCode();
- _hashCode = 5 * _hashCode + _port;
- _hashCode = 5 * _hashCode + _timeout;
- _hashCode = 5 * _hashCode + protocol_.GetHashCode();
- _hashCode = 5 * _hashCode + encoding_.GetHashCode();
- _hashCode = 5 * _hashCode + _connectionId.GetHashCode();
- _hashCode = 5 * _hashCode + (_compress ? 1 : 0);
+ int h = 5381;
+ IceInternal.HashUtil.hashAdd(ref h, Ice.TCPEndpointType.value);
+ IceInternal.HashUtil.hashAdd(ref h, _host);
+ IceInternal.HashUtil.hashAdd(ref h, _port);
+ IceInternal.HashUtil.hashAdd(ref h, _timeout);
+ IceInternal.HashUtil.hashAdd(ref h, protocol_);
+ IceInternal.HashUtil.hashAdd(ref h, encoding_);
+ IceInternal.HashUtil.hashAdd(ref h, _connectionId);
+ IceInternal.HashUtil.hashAdd(ref h, _compress);
+ _hashCode = h;
}
private Instance _instance;
diff --git a/cs/src/Ice/Timer.cs b/cs/src/Ice/Timer.cs
index 23f1335640e..1e6c34b0948 100644
--- a/cs/src/Ice/Timer.cs
+++ b/cs/src/Ice/Timer.cs
@@ -361,31 +361,23 @@ namespace IceInternal
return 0;
}
- public override bool Equals(object o)
- {
- Token t = null;
-
- try
- {
- t = (Token)o;
- }
- catch(InvalidCastException)
- {
- return false;
- }
-
- if(this == t)
- {
- return true;
- }
-
- return CompareTo(t) == 0;
- }
-
- public override int GetHashCode()
- {
- return id ^ (int)scheduledTime;
- }
+ public override bool Equals(object o)
+ {
+ if(object.ReferenceEquals(this, o))
+ {
+ return true;
+ }
+ Token t = o as Token;
+ return t == null ? false : CompareTo(t) == 0;
+ }
+
+ public override int GetHashCode()
+ {
+ int h = 5381;
+ IceInternal.HashUtil.hashAdd(ref h, id);
+ IceInternal.HashUtil.hashAdd(ref h, scheduledTime);
+ return h;
+ }
public long scheduledTime;
public int id; // Since we can't compare references, we need to use another id.
diff --git a/cs/src/Ice/UdpConnector.cs b/cs/src/Ice/UdpConnector.cs
index 970e45c3675..2523d4cb373 100644
--- a/cs/src/Ice/UdpConnector.cs
+++ b/cs/src/Ice/UdpConnector.cs
@@ -44,12 +44,13 @@ namespace IceInternal
_encoding = encoding;
_connectionId = connectionId;
- _hashCode = _addr.GetHashCode();
- _hashCode = 5 * _hashCode + _mcastInterface.GetHashCode();
- _hashCode = 5 * _hashCode + _protocol.GetHashCode();
- _hashCode = 5 * _hashCode + _encoding.GetHashCode();
- _hashCode = 5 * _hashCode + _mcastTtl.GetHashCode();
- _hashCode = 5 * _hashCode + _connectionId.GetHashCode();
+ _hashCode = 5381;
+ IceInternal.HashUtil.hashAdd(ref _hashCode, _addr);
+ IceInternal.HashUtil.hashAdd(ref _hashCode, _mcastInterface);
+ IceInternal.HashUtil.hashAdd(ref _hashCode, _protocol);
+ IceInternal.HashUtil.hashAdd(ref _hashCode, _encoding);
+ IceInternal.HashUtil.hashAdd(ref _hashCode, _mcastTtl);
+ IceInternal.HashUtil.hashAdd(ref _hashCode, _connectionId);
}
public override bool Equals(object obj)
diff --git a/cs/src/Ice/UdpEndpointI.cs b/cs/src/Ice/UdpEndpointI.cs
index 911660e9afe..39e641f02a4 100644
--- a/cs/src/Ice/UdpEndpointI.cs
+++ b/cs/src/Ice/UdpEndpointI.cs
@@ -623,15 +623,18 @@ namespace IceInternal
private void calcHashValue()
{
- _hashCode = _host.GetHashCode();
- _hashCode = 5 * _hashCode + _port;
- _hashCode = 5 * _hashCode + _mcastInterface.GetHashCode();
- _hashCode = 5 * _hashCode + _mcastTtl.GetHashCode();
- _hashCode = 5 * _hashCode + (_connect? 1 : 0);
- _hashCode = 5 * _hashCode + protocol_.GetHashCode();
- _hashCode = 5 * _hashCode + encoding_.GetHashCode();
- _hashCode = 5 * _hashCode + _connectionId.GetHashCode();
- _hashCode = 5 * _hashCode + (_compress? 1 : 0);
+ int h = 5381;
+ IceInternal.HashUtil.hashAdd(ref h, Ice.UDPEndpointType.value);
+ IceInternal.HashUtil.hashAdd(ref h, _host);
+ IceInternal.HashUtil.hashAdd(ref h, _port);
+ IceInternal.HashUtil.hashAdd(ref h, _mcastInterface);
+ IceInternal.HashUtil.hashAdd(ref h, _mcastTtl);
+ IceInternal.HashUtil.hashAdd(ref h, _connect);
+ IceInternal.HashUtil.hashAdd(ref h, protocol_);
+ IceInternal.HashUtil.hashAdd(ref h, encoding_);
+ IceInternal.HashUtil.hashAdd(ref h, _connectionId);
+ IceInternal.HashUtil.hashAdd(ref h, _compress);
+ _hashCode = h;
}
private Instance instance_;
diff --git a/cs/src/Ice/Util.cs b/cs/src/Ice/Util.cs
index 9257113fd2b..a1e9efc82ed 100644
--- a/cs/src/Ice/Util.cs
+++ b/cs/src/Ice/Util.cs
@@ -9,6 +9,7 @@
using System;
using System.Threading;
+using System.Collections;
using System.Text;
using System.Globalization;
@@ -600,6 +601,84 @@ namespace Ice
namespace IceInternal
{
+ public sealed class HashUtil
+ {
+ public static void hashAdd(ref int hashCode, bool value)
+ {
+ hashCode = unchecked(((hashCode << 5) + hashCode) ^ value.GetHashCode());
+ }
+
+ public static void hashAdd(ref int hashCode, short value)
+ {
+ hashCode = unchecked(((hashCode << 5) + hashCode) ^ (int)(2654435761 * value));
+ }
+
+ public static void hashAdd(ref int hashCode, byte value)
+ {
+ hashCode = unchecked(((hashCode << 5) + hashCode) ^ (int)(2654435761 * value));
+ }
+
+ public static void hashAdd(ref int hashCode, int value)
+ {
+ hashCode = unchecked(((hashCode << 5) + hashCode) ^ (int)(2654435761 * value));
+ }
+
+ public static void hashAdd(ref int hashCode, long value)
+ {
+ hashCode = unchecked(((hashCode << 5) + hashCode) ^ value.GetHashCode());
+ }
+
+ public static void hashAdd(ref int hashCode, float value)
+ {
+ hashCode = unchecked(((hashCode << 5) + hashCode) ^ value.GetHashCode());
+ }
+
+ public static void hashAdd(ref int hashCode, double value)
+ {
+ hashCode = unchecked(((hashCode << 5) + hashCode) ^ value.GetHashCode());
+ }
+
+ public static void hashAdd(ref int hashCode, object value)
+ {
+ if(value != null)
+ {
+ hashCode = unchecked(((hashCode << 5) + hashCode) ^ value.GetHashCode());
+ }
+ }
+
+ public static void hashAdd(ref int hashCode, object[] arr)
+ {
+ if(arr != null)
+ {
+ hashCode = unchecked(((hashCode << 5) + hashCode) ^ IceUtilInternal.Arrays.GetHashCode(arr));
+ }
+ }
+
+ public static void hashAdd(ref int hashCode, Array arr)
+ {
+ if(arr != null)
+ {
+ hashCode = unchecked(((hashCode << 5) + hashCode) ^ IceUtilInternal.Arrays.GetHashCode(arr));
+ }
+ }
+
+ public static void hashAdd(ref int hashCode, IEnumerable s)
+ {
+ if(s != null)
+ {
+ hashCode = unchecked(((hashCode << 5) + hashCode) ^ IceUtilInternal.Collections.SequenceGetHashCode(s));
+ }
+ }
+
+ public static void hashAdd(ref int hashCode, IDictionary d)
+ {
+ if(d != null)
+ {
+ hashCode = unchecked(((hashCode << 5) + hashCode) ^ IceUtilInternal.Collections.DictionaryGetHashCode(d));
+ }
+ }
+ }
+
public sealed class Util
{
public static Instance getInstance(Ice.Communicator communicator)
@@ -646,10 +725,10 @@ namespace IceInternal
}
return ThreadPriority.Normal;
}
-#endif
- }
-}
-
+#endif
+ }
+}
+
#if SILVERLIGHT
namespace System
{
@@ -658,4 +737,4 @@ namespace System
Object Clone();
}
}
-#endif
+#endif
diff --git a/cs/src/IceSSL/ConnectorI.cs b/cs/src/IceSSL/ConnectorI.cs
index 6b49fd08ef1..3d543c2d67c 100644
--- a/cs/src/IceSSL/ConnectorI.cs
+++ b/cs/src/IceSSL/ConnectorI.cs
@@ -88,11 +88,12 @@ namespace IceSSL
_encoding = encoding;
_connectionId = connectionId;
- _hashCode = _addr.GetHashCode();
- _hashCode = 5 * _hashCode + _timeout;
- _hashCode = 5 * _hashCode + _protocol.GetHashCode();
- _hashCode = 5 * _hashCode + _encoding.GetHashCode();
- _hashCode = 5 * _hashCode + _connectionId.GetHashCode();
+ _hashCode = 5381;
+ IceInternal.HashUtil.hashAdd(ref _hashCode, _addr);
+ IceInternal.HashUtil.hashAdd(ref _hashCode, _timeout);
+ IceInternal.HashUtil.hashAdd(ref _hashCode, _protocol);
+ IceInternal.HashUtil.hashAdd(ref _hashCode, _encoding);
+ IceInternal.HashUtil.hashAdd(ref _hashCode, _connectionId);
}
public override bool Equals(object obj)
diff --git a/cs/src/IceSSL/EndpointI.cs b/cs/src/IceSSL/EndpointI.cs
index d995d3c3a3a..87fb1f38978 100644
--- a/cs/src/IceSSL/EndpointI.cs
+++ b/cs/src/IceSSL/EndpointI.cs
@@ -551,13 +551,16 @@ namespace IceSSL
private void calcHashValue()
{
- _hashCode = _host.GetHashCode();
- _hashCode = 5 * _hashCode + _port;
- _hashCode = 5 * _hashCode + _timeout;
- _hashCode = 5 * _hashCode + protocol_.GetHashCode();
- _hashCode = 5 * _hashCode + encoding_.GetHashCode();
- _hashCode = 5 * _hashCode + _connectionId.GetHashCode();
- _hashCode = 5 * _hashCode + (_compress ? 1 : 0);
+ int h = 5381;
+ IceInternal.HashUtil.hashAdd(ref h, EndpointType.value);
+ IceInternal.HashUtil.hashAdd(ref h, _host);
+ IceInternal.HashUtil.hashAdd(ref h, _port);
+ IceInternal.HashUtil.hashAdd(ref h, _timeout);
+ IceInternal.HashUtil.hashAdd(ref h, protocol_);
+ IceInternal.HashUtil.hashAdd(ref h, encoding_);
+ IceInternal.HashUtil.hashAdd(ref h, _connectionId);
+ IceInternal.HashUtil.hashAdd(ref h, _compress);
+ _hashCode = h;
}
private Instance _instance;
diff --git a/cs/test/Ice/Makefile b/cs/test/Ice/Makefile
index 5717097f88d..0fc71beeb86 100644
--- a/cs/test/Ice/Makefile
+++ b/cs/test/Ice/Makefile
@@ -19,6 +19,7 @@ SUBDIRS = application \
info \
inheritance \
invoke \
+ hash \
hold \
location \
objects \
diff --git a/cs/test/Ice/Makefile.mak b/cs/test/Ice/Makefile.mak
index 39f88d81e5c..7d731d91ef2 100644
--- a/cs/test/Ice/Makefile.mak
+++ b/cs/test/Ice/Makefile.mak
@@ -20,6 +20,7 @@ SUBDIRS = application \
inheritance \
invoke \
hold \
+ hash \
location \
objects \
binding \
diff --git a/cs/test/Ice/hash/Client.cs b/cs/test/Ice/hash/Client.cs
new file mode 100644
index 00000000000..9101a9a86ed
--- /dev/null
+++ b/cs/test/Ice/hash/Client.cs
@@ -0,0 +1,550 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+using System;
+using System.Diagnostics;
+using System.Reflection;
+using System.Collections.Generic;
+
+[assembly: CLSCompliant(true)]
+
+[assembly: AssemblyTitle("IceTest")]
+[assembly: AssemblyDescription("Ice test")]
+[assembly: AssemblyCompany("ZeroC, Inc.")]
+
+public class Client
+{
+ private static void test(bool b)
+ {
+ if(!b)
+ {
+ throw new System.Exception();
+ }
+ }
+
+ public static int Main(string[] args)
+ {
+ int status = 0;
+ Ice.Communicator communicator = null;
+
+#if !COMPACT
+ Debug.Listeners.Add(new ConsoleTraceListener());
+#endif
+
+ try
+ {
+ System.Console.Error.Write("testing proxy & endpoint hash algorithm collisions... ");
+ System.Console.Error.Flush();
+ Dictionary<int, Ice.ObjectPrx> seenProxy = new Dictionary<int, Ice.ObjectPrx>();
+ Dictionary<int, Ice.Endpoint> seenEndpoint = new Dictionary<int, Ice.Endpoint>();
+ int proxyCollisions = 0;
+ int endpointCollisions = 0;
+ int i = 0;
+ int maxCollisions = 10;
+ int maxIterations = 10000;
+
+ Ice.InitializationData initData = new Ice.InitializationData();
+ initData.properties = Ice.Util.createProperties(ref args);
+ //initData.properties.setProperty("Ice.Plugin.IceSSL", "IceSSL:IceSSL.PluginFactory");
+ communicator = Ice.Util.initialize(ref args, initData);
+ {
+ System.Random rand = new System.Random();
+ for(i = 0; proxyCollisions < maxCollisions &&
+ endpointCollisions < maxCollisions &&
+ i < maxIterations; ++i)
+ {
+ System.IO.StringWriter sw = new System.IO.StringWriter();
+ sw.Write(i);
+ sw.Write(":tcp -p ");
+ sw.Write(rand.Next(65536));
+ sw.Write(" -t 10");
+ sw.Write(rand.Next(1000000));
+ sw.Write(":udp -p ");
+ sw.Write(rand.Next(65536));
+ sw.Write(" -h ");
+ sw.Write(rand.Next(100));
+
+ Ice.ObjectPrx obj = communicator.stringToProxy(sw.ToString());
+ List<Ice.Endpoint> endpoints = new List<Ice.Endpoint>(obj.ice_getEndpoints());
+
+
+ if(seenProxy.ContainsKey(obj.GetHashCode()))
+ {
+ if(obj.Equals(seenProxy[obj.GetHashCode()]))
+ {
+ continue;
+ }
+ ++proxyCollisions;
+ }
+ else
+ {
+ seenProxy[obj.GetHashCode()] = obj;
+ }
+
+ foreach(Ice.Endpoint endpoint in endpoints)
+ {
+ if(seenEndpoint.ContainsKey(endpoint.GetHashCode()))
+ {
+ if(endpoint.Equals(seenEndpoint[endpoint.GetHashCode()]))
+ {
+ continue;
+ }
+ ++endpointCollisions;
+ }
+ else
+ {
+ seenEndpoint[endpoint.GetHashCode()] = endpoint;
+ }
+ //
+ // Check the same endpoint produce always the same hash
+ //
+ test(endpoint.GetHashCode() == endpoint.GetHashCode());
+ }
+ //
+ // Check the same proxy produce always the same hash
+ //
+ test(obj.GetHashCode() == obj.GetHashCode());
+ }
+ test(proxyCollisions < maxCollisions);
+ test(endpointCollisions < maxCollisions);
+ {
+ Ice.ProxyIdentityKey comparer = new Ice.ProxyIdentityKey();
+ proxyCollisions = 0;
+ seenProxy = new Dictionary<int, Ice.ObjectPrx>();
+ for(i = 0; proxyCollisions < maxCollisions && i < maxIterations; ++i)
+ {
+ System.IO.StringWriter sw = new System.IO.StringWriter();
+ sw.Write(i);
+ sw.Write(":tcp -p ");
+ sw.Write(rand.Next(65536));
+ sw.Write(" -t 10");
+ sw.Write(rand.Next(1000000));
+ sw.Write(":udp -p ");
+ sw.Write(rand.Next(65536));
+ sw.Write(" -h ");
+ sw.Write(rand.Next(100));
+
+ Ice.ObjectPrx obj = communicator.stringToProxy(sw.ToString());
+
+ if(seenProxy.ContainsKey(comparer.GetHashCode(obj)))
+ {
+ ++proxyCollisions;
+ }
+ else
+ {
+ seenProxy[comparer.GetHashCode(obj)] = obj;
+ }
+ //
+ // Check the same proxy produce always the same hash
+ //
+ test(comparer.GetHashCode(obj) == comparer.GetHashCode(obj));
+ }
+ test(proxyCollisions < maxCollisions);
+ }
+ }
+
+ {
+ System.Random rand = new System.Random();
+ Ice.ProxyIdentityFacetKey comparer = new Ice.ProxyIdentityFacetKey();
+ proxyCollisions = 0;
+ seenProxy = new Dictionary<int, Ice.ObjectPrx>();
+ for(i = 0; proxyCollisions < maxCollisions && i < maxIterations; ++i)
+ {
+ System.IO.StringWriter sw = new System.IO.StringWriter();
+ sw.Write(i);
+ sw.Write(" -f demo:tcp -p ");
+ sw.Write(rand.Next(65536));
+ sw.Write(" -t 10");
+ sw.Write(rand.Next(1000000));
+ sw.Write(":udp -p ");
+ sw.Write(rand.Next(65536));
+ sw.Write(" -h ");
+ sw.Write(rand.Next(100));
+
+ Ice.ObjectPrx obj = communicator.stringToProxy(sw.ToString());
+
+ if(seenProxy.ContainsKey(comparer.GetHashCode(obj)))
+ {
+ ++proxyCollisions;
+ }
+ else
+ {
+ seenProxy[comparer.GetHashCode(obj)] = obj;
+ }
+ //
+ // Check the same proxy produce always the same hash
+ //
+ test(comparer.GetHashCode(obj) == comparer.GetHashCode(obj));
+ }
+ test(proxyCollisions < maxCollisions);
+ }
+
+ Ice.ProxyIdentityFacetKey iComparer = new Ice.ProxyIdentityFacetKey();
+ Ice.ProxyIdentityFacetKey ifComparer = new Ice.ProxyIdentityFacetKey();
+
+ Ice.ObjectPrx prx1 = communicator.stringToProxy("Glacier2/router:tcp -p 10010");
+ //Ice.ObjectPrx prx2 = communicator.stringToProxy("Glacier2/router:ssl -p 10011");
+ Ice.ObjectPrx prx3 = communicator.stringToProxy("Glacier2/router:udp -p 10012");
+ Ice.ObjectPrx prx4 = communicator.stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010");
+ //Ice.ObjectPrx prx5 = communicator.stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011");
+ Ice.ObjectPrx prx6 = communicator.stringToProxy("Glacier2/router:udp -h zeroc.com -p 10012");
+ Ice.ObjectPrx prx7 = communicator.stringToProxy("Glacier2/router:tcp -p 10010 -t 10000");
+ //Ice.ObjectPrx prx8 = communicator.stringToProxy("Glacier2/router:ssl -p 10011 -t 10000");
+ Ice.ObjectPrx prx9 = communicator.stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010 -t 10000");
+ //Ice.ObjectPrx prx10 = communicator.stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011 -t 10000");
+
+ Dictionary<string, int> proxyMap = new Dictionary<string, int>();
+ proxyMap["prx1"] = prx1.GetHashCode();
+ //proxyMap["prx2"] = prx2.GetHashCode();
+ proxyMap["prx3"] = prx3.GetHashCode();
+ proxyMap["prx4"] = prx4.GetHashCode();
+ //proxyMap["prx5"] = prx5.GetHashCode();
+ proxyMap["prx6"] = prx6.GetHashCode();
+ proxyMap["prx7"] = prx7.GetHashCode();
+ //proxyMap["prx8"] = prx8.GetHashCode();
+ proxyMap["prx9"] = prx9.GetHashCode();
+ //proxyMap["prx10"] = prx10.GetHashCode();
+
+ test(communicator.stringToProxy("Glacier2/router:tcp -p 10010").GetHashCode() == proxyMap["prx1"]);
+ //test(communicator.stringToProxy("Glacier2/router:ssl -p 10011").GetHashCode() == proxyMap["prx2"]);
+ test(communicator.stringToProxy("Glacier2/router:udp -p 10012").GetHashCode() == proxyMap["prx3"]);
+ test(communicator.stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010").GetHashCode() == proxyMap["prx4"]);
+ //test(communicator.stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011").GetHashCode() == proxyMap["prx5"]);
+ test(communicator.stringToProxy("Glacier2/router:udp -h zeroc.com -p 10012").GetHashCode() == proxyMap["prx6"]);
+ test(communicator.stringToProxy("Glacier2/router:tcp -p 10010 -t 10000").GetHashCode() == proxyMap["prx7"]);
+ //test(communicator.stringToProxy("Glacier2/router:ssl -p 10011 -t 10000").GetHashCode() == proxyMap["prx8"]);
+ test(communicator.stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010 -t 10000").GetHashCode() == proxyMap["prx9"]);
+ //test(communicator.stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011 -t 10000").GetHashCode() == proxyMap["prx10"]);
+
+ test(iComparer.GetHashCode(prx1) == iComparer.GetHashCode(prx1));
+ test(ifComparer.GetHashCode(prx1) == ifComparer.GetHashCode(prx1));
+
+ test(iComparer.GetHashCode(prx3) == iComparer.GetHashCode(prx3));
+ test(ifComparer.GetHashCode(prx3) == ifComparer.GetHashCode(prx3));
+
+ test(iComparer.GetHashCode(prx4) == iComparer.GetHashCode(prx4));
+ test(ifComparer.GetHashCode(prx4) == ifComparer.GetHashCode(prx4));
+
+ test(iComparer.GetHashCode(prx6) == iComparer.GetHashCode(prx6));
+ test(ifComparer.GetHashCode(prx6) == ifComparer.GetHashCode(prx6));
+
+ test(iComparer.GetHashCode(prx7) == iComparer.GetHashCode(prx7));
+ test(ifComparer.GetHashCode(prx7) == ifComparer.GetHashCode(prx7));
+
+ test(iComparer.GetHashCode(prx9) == iComparer.GetHashCode(prx9));
+ test(ifComparer.GetHashCode(prx9) == ifComparer.GetHashCode(prx9));
+
+ System.Console.Error.WriteLine("ok");
+
+ System.Console.Error.Write("testing exceptions hash algorithm collisions... ");
+
+ {
+ Dictionary<int,Test.OtherException> seenException = new Dictionary<int, Test.OtherException>();
+ System.Random rand = new System.Random();
+
+ int exceptionCollisions = 0;
+ for(i = 0; i < maxIterations &&
+ exceptionCollisions < maxCollisions; ++i)
+ {
+ Test.OtherException ex = new Test.OtherException(rand.Next(100), rand.Next(100), 0, false);
+ if(seenException.ContainsKey(ex.GetHashCode()))
+ {
+ if(ex.Equals(seenException[ex.GetHashCode()]))
+ {
+ continue; // same object
+ }
+ exceptionCollisions++;
+ }
+ else
+ {
+ seenException[ex.GetHashCode()] = ex;
+ }
+ //
+ // Check the same exception produce always the same hash
+ //
+ test(ex.GetHashCode() == ex.GetHashCode());
+ }
+ test(exceptionCollisions < maxCollisions);
+ }
+
+ //
+ // Same as above but with numbers in high ranges
+ //
+ {
+ Dictionary<int,Test.OtherException> seenException = new Dictionary<int, Test.OtherException>();
+ System.Random rand = new System.Random();
+
+ int exceptionCollisions = 0;
+ for(i = 0; i < maxIterations &&
+ exceptionCollisions < maxCollisions; ++i)
+ {
+ Test.OtherException ex = new Test.OtherException(rand.Next(100) * 2^30, rand.Next(100) * 2^30, rand.Next(100) * 2^30, false);
+ if(seenException.ContainsKey(ex.GetHashCode()))
+ {
+ if(ex.Equals(seenException[ex.GetHashCode()]))
+ {
+ continue; // same object
+ }
+ exceptionCollisions++;
+ }
+ else
+ {
+ seenException[ex.GetHashCode()] = ex;
+ }
+ //
+ // Check the same exception produce always the same hash
+ //
+ test(ex.GetHashCode() == ex.GetHashCode());
+ }
+ test(exceptionCollisions < maxCollisions);
+ }
+
+ {
+ Dictionary<int,Test.BaseException> seenException = new Dictionary<int, Test.BaseException>();
+ System.Random rand = new System.Random();
+
+ int exceptionCollisions = 0;
+ for(i = 0; i < maxIterations &&
+ exceptionCollisions < maxCollisions; ++i)
+ {
+ int v = rand.Next(1000);
+ Test.BaseException ex = new Test.InvalidPointException(v);
+ if(seenException.ContainsKey(ex.GetHashCode()))
+ {
+ if(ex.Equals(seenException[ex.GetHashCode()]))
+ {
+ continue; // same object
+ }
+ exceptionCollisions++;
+ }
+ else
+ {
+ seenException[ex.GetHashCode()] = ex;
+ }
+
+ //
+ // Check the same exception produce always the same hash
+ //
+ test(ex.GetHashCode() == ex.GetHashCode());
+
+ ex = new Test.InvalidLengthException(v);
+ if(seenException.ContainsKey(ex.GetHashCode()))
+ {
+ if(ex.Equals(seenException[ex.GetHashCode()]))
+ {
+ continue; // same object
+ }
+ exceptionCollisions++;
+ }
+ else
+ {
+ seenException[ex.GetHashCode()] = ex;
+ }
+
+ //
+ // Check the same exception produce always the same hash
+ //
+ test(ex.GetHashCode() == ex.GetHashCode());
+ }
+ test(exceptionCollisions < maxCollisions);
+ }
+ System.Console.Error.WriteLine("ok");
+
+ System.Console.Error.Write("testing struct hash algorithm collisions... ");
+ {
+ Dictionary<int,Test.PointF> seenPointF = new Dictionary<int, Test.PointF>();
+ System.Random rand = new System.Random();
+ int structCollisions = 0;
+ for(i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
+ {
+ Test.PointF pf = new Test.PointF((float)rand.NextDouble(), (float)rand.NextDouble(),
+ (float)rand.NextDouble());
+ if(seenPointF.ContainsKey(pf.GetHashCode()))
+ {
+ if(pf.Equals(seenPointF[pf.GetHashCode()]))
+ {
+ continue; // same object
+ }
+ structCollisions++;
+ }
+ else
+ {
+ seenPointF[pf.GetHashCode()] = pf;
+ }
+ //
+ // Check the same struct produce always the same hash
+ //
+ test(pf.GetHashCode() == pf.GetHashCode());
+ }
+ test(structCollisions < maxCollisions);
+
+ Dictionary<int,Test.PointD> seenPointD = new Dictionary<int, Test.PointD>();
+ structCollisions = 0;
+ for(i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
+ {
+ Test.PointD pd = new Test.PointD(rand.NextDouble(), rand.NextDouble(),
+ rand.NextDouble());
+ if(seenPointD.ContainsKey(pd.GetHashCode()))
+ {
+ if(pd.Equals(seenPointD[pd.GetHashCode()]))
+ {
+ continue; // same object
+ }
+ structCollisions++;
+ }
+ else
+ {
+ seenPointD[pd.GetHashCode()] = pd;
+ }
+ //
+ // Check the same struct produce always the same hash
+ //
+ test(pd.GetHashCode() == pd.GetHashCode());
+ }
+ test(structCollisions < maxCollisions);
+
+ Dictionary<int,Test.Polyline> seenPolyline = new Dictionary<int, Test.Polyline>();
+ structCollisions = 0;
+ for(i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
+ {
+ Test.Polyline polyline = new Test.Polyline();
+ List<Test.Point> vertices = new List<Test.Point>();
+ for(int j = 0; j < 100; ++j)
+ {
+ vertices.Add(new Test.Point(rand.Next(100), rand.Next(100)));
+ }
+ polyline.vertices = vertices.ToArray();
+
+ if(seenPolyline.ContainsKey(polyline.GetHashCode()))
+ {
+ if(polyline.Equals(seenPolyline[polyline.GetHashCode()]))
+ {
+ continue; // same object
+ }
+ structCollisions++;
+ }
+ else
+ {
+ seenPolyline[polyline.GetHashCode()] = polyline;
+ }
+ //
+ // Check the same struct produce always the same hash
+ //
+ test(polyline.GetHashCode() == polyline.GetHashCode());
+ }
+ test(structCollisions < maxCollisions);
+
+ Dictionary<int,Test.ColorPalette> seenColorPalette = new Dictionary<int, Test.ColorPalette>();
+ structCollisions = 0;
+ for(i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
+ {
+ Test.ColorPalette colorPalette = new Test.ColorPalette();
+ colorPalette.colors = new Dictionary<int, Test.Color>();
+ for(int j = 0; j < 100; ++j)
+ {
+ colorPalette.colors[j] = new Test.Color(rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255));
+ }
+
+ if(seenColorPalette.ContainsKey(colorPalette.GetHashCode()))
+ {
+ if(colorPalette.Equals(seenColorPalette[colorPalette.GetHashCode()]))
+ {
+ continue; // same object
+ }
+ structCollisions++;
+ }
+ else
+ {
+ seenColorPalette[colorPalette.GetHashCode()] = colorPalette;
+ }
+ //
+ // Check the same struct produce always the same hash
+ //
+ test(colorPalette.GetHashCode() == colorPalette.GetHashCode());
+ }
+ test(structCollisions < maxCollisions);
+
+ Dictionary<int,Test.Color> seenColor = new Dictionary<int, Test.Color>();
+ structCollisions = 0;
+ for(i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
+ {
+ Test.Color c = new Test.Color(rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255));
+ if(seenColor.ContainsKey(c.GetHashCode()))
+ {
+ if(c.Equals(seenColor[c.GetHashCode()]))
+ {
+ continue; // same object
+ }
+ structCollisions++;
+ }
+ else
+ {
+ seenColor[c.GetHashCode()] = c;
+ }
+ //
+ // Check the same struct produce always the same hash
+ //
+ test(c.GetHashCode() == c.GetHashCode());
+ }
+ test(structCollisions < maxCollisions);
+
+ structCollisions = 0;
+ Dictionary<int,Test.Draw> seenDraw = new Dictionary<int, Test.Draw>();
+ structCollisions = 0;
+ for(i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
+ {
+ Test.Draw draw = new Test.Draw(
+ new Test.Color(rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255)),
+ new Test.Pen(rand.Next(10),
+ new Test.Color(rand.Next(255), rand.Next(255), rand.Next(255), rand.Next(255))),
+ false);
+
+ if(seenDraw.ContainsKey(draw.GetHashCode()))
+ {
+ if(draw.Equals(seenDraw[draw.GetHashCode()]))
+ {
+ continue; // same object
+ }
+ structCollisions++;
+ }
+ else
+ {
+ seenDraw[draw.GetHashCode()] = draw;
+ }
+ //
+ // Check the same struct produce always the same hash
+ //
+ test(draw.GetHashCode() == draw.GetHashCode());
+ }
+ test(structCollisions < maxCollisions);
+ }
+ System.Console.Error.WriteLine("ok");
+
+ if(communicator != null)
+ {
+ try
+ {
+ communicator.destroy();
+ }
+ catch(Ice.LocalException ex)
+ {
+ System.Console.Error.WriteLine(ex);
+ status = 1;
+ }
+ }
+ }
+ catch(Exception ex)
+ {
+ Console.WriteLine(ex.ToString());
+ status = 1;
+ }
+
+ return status;
+ }
+}
diff --git a/cs/test/Ice/hash/Makefile b/cs/test/Ice/hash/Makefile
new file mode 100644
index 00000000000..2b3b6fdd7c9
--- /dev/null
+++ b/cs/test/Ice/hash/Makefile
@@ -0,0 +1,29 @@
+# **********************************************************************
+#
+# Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
+#
+# This copy of Ice is licensed to you under the terms described in the
+# ICE_LICENSE file included in this distribution.
+#
+# **********************************************************************
+
+top_srcdir = ../../..
+
+TARGETS = client.exe
+
+C_SRCS = Client.cs
+
+SLICE_SRCS = $(SDIR)/Test.ice
+
+SDIR = .
+
+GDIR = generated
+
+include $(top_srcdir)/config/Make.rules.cs
+
+MCSFLAGS := $(MCSFLAGS) -target:exe
+
+SLICE2CSFLAGS := $(SLICE2CSFLAGS) -I. -I$(slicedir)
+
+client.exe: $(C_SRCS) $(GEN_SRCS)
+ $(MCS) $(MCSFLAGS) -out:$@ $(call ref,Ice) $(subst /,$(DSEP),$^)
diff --git a/cs/test/Ice/hash/Makefile.mak b/cs/test/Ice/hash/Makefile.mak
new file mode 100644
index 00000000000..c8bea7d4b5a
--- /dev/null
+++ b/cs/test/Ice/hash/Makefile.mak
@@ -0,0 +1,29 @@
+# **********************************************************************
+#
+# Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
+#
+# This copy of Ice is licensed to you under the terms described in the
+# ICE_LICENSE file included in this distribution.
+#
+# **********************************************************************
+
+top_srcdir = ..\..\..
+
+TARGETS = client.exe
+
+C_SRCS = Client.cs
+
+GEN_SRCS = $(GDIR)\Test.cs
+
+SDIR = .
+
+GDIR = generated
+
+!include $(top_srcdir)\config\Make.rules.mak.cs
+
+MCSFLAGS = $(MCSFLAGS) -target:exe
+
+SLICE2CSFLAGS = $(SLICE2CSFLAGS) -I. -I"$(slicedir)"
+
+client.exe: $(C_SRCS) $(GEN_SRCS)
+ $(MCS) $(MCSFLAGS) -out:$@ -r:"$(refdir)\Ice.dll" $(C_SRCS) $(GEN_SRCS)
diff --git a/cs/test/Ice/hash/Test.ice b/cs/test/Ice/hash/Test.ice
new file mode 100644
index 00000000000..08c138478cc
--- /dev/null
+++ b/cs/test/Ice/hash/Test.ice
@@ -0,0 +1,97 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#pragma once
+
+module Test
+{
+
+
+exception BaseException
+{
+};
+
+exception InvalidPointException extends BaseException
+{
+ int index;
+};
+
+exception InvalidLengthException extends BaseException
+{
+ int length;
+};
+
+exception OtherException
+{
+ int x;
+ int y;
+ int z;
+ bool b;
+};
+
+
+struct PointF
+{
+ float x;
+ float y;
+ float z;
+};
+
+struct PointD
+{
+ double x;
+ double y;
+ double z;
+};
+
+struct Point
+{
+ int x;
+ int y;
+};
+sequence<Point> Points;
+
+struct Polyline
+{
+ Points vertices;
+};
+
+struct Color
+{
+ int r;
+ int g;
+ int b;
+ int a;
+};
+
+
+dictionary<int, Color> StringColorMap;
+
+struct ColorPalette
+{
+ StringColorMap colors;
+};
+
+
+
+class Pen
+{
+ int thickness;
+ Test::Color color;
+};
+
+struct Draw
+{
+ Test::Color backgroundColor;
+ Test::Pen pen;
+ bool shared;
+};
+
+};
+
diff --git a/cs/test/Ice/hash/client.exe.config b/cs/test/Ice/hash/client.exe.config
new file mode 100755
index 00000000000..cf795ac3756
--- /dev/null
+++ b/cs/test/Ice/hash/client.exe.config
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<configuration>
+ <runtime>
+ <developmentMode developerInstallation="true"/>
+ </runtime>
+</configuration>
diff --git a/cs/test/Ice/hash/generated/.gitignore b/cs/test/Ice/hash/generated/.gitignore
new file mode 100644
index 00000000000..39af5887579
--- /dev/null
+++ b/cs/test/Ice/hash/generated/.gitignore
@@ -0,0 +1 @@
+# Dummy file, so that git retains this otherwise empty directory.
diff --git a/cs/test/Ice/hash/run.py b/cs/test/Ice/hash/run.py
new file mode 100755
index 00000000000..267b40578d3
--- /dev/null
+++ b/cs/test/Ice/hash/run.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+# **********************************************************************
+#
+# Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
+#
+# This copy of Ice is licensed to you under the terms described in the
+# ICE_LICENSE file included in this distribution.
+#
+# **********************************************************************
+
+import os, sys, getopt
+
+path = [ ".", "..", "../..", "../../..", "../../../.." ]
+head = os.path.dirname(sys.argv[0])
+if len(head) > 0:
+ path = [os.path.join(head, p) for p in path]
+path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ]
+if len(path) == 0:
+ raise "can't find toplevel directory!"
+sys.path.append(os.path.join(path[0]))
+from scripts import *
+
+client = os.path.join(os.getcwd(), "client")
+
+print "starting client...",
+clientProc = TestUtil.startClient(client, "", startReader = False)
+print "ok"
+clientProc.startReader()
+clientProc.waitTestSuccess()
+
diff --git a/java/allTests.py b/java/allTests.py
index d69abc728fb..ce7ac3ac3c4 100755
--- a/java/allTests.py
+++ b/java/allTests.py
@@ -64,6 +64,7 @@ tests = [
("Ice/classLoader", ["core"]),
("Ice/invoke", ["core"]),
("Ice/properties", ["once"]),
+ ("Ice/hash", ["once"]),
("Ice/optional", ["once"]),
("IceBox/configuration", ["core", "noipv6"]),
("Freeze/dbmap", ["once"]),
diff --git a/java/build.xml b/java/build.xml
index 4164c47b28d..0c59f90231e 100644
--- a/java/build.xml
+++ b/java/build.xml
@@ -434,6 +434,9 @@
<fileset dir="test/Ice/faultTolerance">
<include name="Test.ice" />
</fileset>
+ <fileset dir="test/Ice/hash">
+ <include name="Test.ice" />
+ </fileset>
<fileset dir="test/Ice/hold">
<include name="Test.ice" />
</fileset>
diff --git a/java/src/Freeze/SharedDbEnv.java b/java/src/Freeze/SharedDbEnv.java
index ab7163c20b7..76bf51d78e1 100644
--- a/java/src/Freeze/SharedDbEnv.java
+++ b/java/src/Freeze/SharedDbEnv.java
@@ -545,7 +545,9 @@ public class SharedDbEnv implements com.sleepycat.db.ErrorHandler, Runnable
public int
hashCode()
{
- return envName.hashCode() ^ communicator.hashCode();
+ int h = 5381;
+ h = IceInternal.HashUtil.hashAdd(h, envName);
+ return IceInternal.HashUtil.hashAdd(h, communicator);
}
}
diff --git a/java/src/Ice/LocalObject.java b/java/src/Ice/LocalObject.java
index 03cbba57d9b..335198e6f01 100644
--- a/java/src/Ice/LocalObject.java
+++ b/java/src/Ice/LocalObject.java
@@ -17,6 +17,4 @@ public interface LocalObject
boolean equals(java.lang.Object rhs);
java.lang.Object clone() throws java.lang.CloneNotSupportedException;
-
- int ice_hash();
}
diff --git a/java/src/Ice/LocalObjectImpl.java b/java/src/Ice/LocalObjectImpl.java
index c2634d3e15e..da39eac7dab 100644
--- a/java/src/Ice/LocalObjectImpl.java
+++ b/java/src/Ice/LocalObjectImpl.java
@@ -19,10 +19,4 @@ public abstract class LocalObjectImpl implements LocalObject, java.lang.Cloneabl
{
return super.clone();
}
-
- public int
- ice_hash()
- {
- return hashCode();
- }
}
diff --git a/java/src/Ice/Object.java b/java/src/Ice/Object.java
index 70461f26b86..20184f6657f 100644
--- a/java/src/Ice/Object.java
+++ b/java/src/Ice/Object.java
@@ -22,11 +22,6 @@ public interface Object
**/
java.lang.Object clone() throws java.lang.CloneNotSupportedException;
- /**
- * @deprecated This method is deprecated, use hashCode instead.
- **/
- int ice_hash();
-
/**
* Tests whether this object supports a specific Slice interface.
*
diff --git a/java/src/Ice/ObjectImpl.java b/java/src/Ice/ObjectImpl.java
index 7ff5636cc0f..a1e0fb5c7a4 100644
--- a/java/src/Ice/ObjectImpl.java
+++ b/java/src/Ice/ObjectImpl.java
@@ -43,15 +43,6 @@ public abstract class ObjectImpl implements Object, java.lang.Cloneable, java.io
return o;
}
- /**
- * @deprecated
- **/
- public int
- ice_hash()
- {
- return hashCode();
- }
-
public final static String[] __ids =
{
"::Ice::Object"
diff --git a/java/src/Ice/ObjectPrx.java b/java/src/Ice/ObjectPrx.java
index 119482ba45e..17587de0a9e 100644
--- a/java/src/Ice/ObjectPrx.java
+++ b/java/src/Ice/ObjectPrx.java
@@ -15,11 +15,6 @@ package Ice;
public interface ObjectPrx
{
/**
- * @deprecated This method is deprecated, use hashCode instead.
- **/
- int ice_getHash();
-
- /**
* Returns the communicator that created this proxy.
*
* @return The communicator that created this proxy.
diff --git a/java/src/Ice/ObjectPrxHelperBase.java b/java/src/Ice/ObjectPrxHelperBase.java
index 9a1de69d685..fd6deac1100 100644
--- a/java/src/Ice/ObjectPrxHelperBase.java
+++ b/java/src/Ice/ObjectPrxHelperBase.java
@@ -26,15 +26,6 @@ public class ObjectPrxHelperBase implements ObjectPrx, java.io.Serializable
}
/**
- * @deprecated
- **/
- public final int
- ice_getHash()
- {
- return _reference.hashCode();
- }
-
- /**
* Returns the communicator that created this proxy.
*
* @return The communicator that created this proxy.
diff --git a/java/src/Ice/ProxyIdentityFacetKey.java b/java/src/Ice/ProxyIdentityFacetKey.java
index f23bf093952..a2b859e958d 100644
--- a/java/src/Ice/ProxyIdentityFacetKey.java
+++ b/java/src/Ice/ProxyIdentityFacetKey.java
@@ -17,6 +17,7 @@ package Ice;
* @see ProxyIdentityAndFacetCompare
* @see ProxyIdentityCompare
* @see ProxyIdentityKey
+ *
**/
public class ProxyIdentityFacetKey
{
@@ -35,8 +36,9 @@ public class ProxyIdentityFacetKey
//
_identity = proxy.ice_getIdentity();
_facet = proxy.ice_getFacet();
- int h = _identity.hashCode();
- h = 5 * h + _facet.hashCode();
+ int h = 5381;
+ h = IceInternal.HashUtil.hashAdd(h, _identity);
+ h = IceInternal.HashUtil.hashAdd(h, _facet);
_hashCode = h;
}
diff --git a/java/src/Ice/ProxyIdentityKey.java b/java/src/Ice/ProxyIdentityKey.java
index a008ad63869..6bfe9b640ab 100644
--- a/java/src/Ice/ProxyIdentityKey.java
+++ b/java/src/Ice/ProxyIdentityKey.java
@@ -17,6 +17,7 @@ package Ice;
* @see ProxyIdentityCompare
* @see ProxyIdentityAndFacetCompare
* @see ProxyIdentityFacetKey
+ *
**/
public class ProxyIdentityKey
{
@@ -34,7 +35,9 @@ public class ProxyIdentityKey
// Cache the identity and its hash code.
//
_identity = proxy.ice_getIdentity();
- _hashCode = _identity.hashCode();
+ int h = 5381;
+ h = IceInternal.HashUtil.hashAdd(h, _identity);
+ _hashCode = h;
}
/**
diff --git a/java/src/IceInternal/HashUtil.java b/java/src/IceInternal/HashUtil.java
new file mode 100644
index 00000000000..520254bbc64
--- /dev/null
+++ b/java/src/IceInternal/HashUtil.java
@@ -0,0 +1,120 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2012 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+package IceInternal;
+
+public final class HashUtil
+{
+ public static int
+ hashAdd(int hashCode, boolean value)
+ {
+ return ((hashCode << 5) + hashCode) ^ (value ? 0 : 1);
+ }
+
+ public static int
+ hashAdd(int hashCode, short value)
+ {
+ return ((hashCode << 5) + hashCode) ^ (int)(2654435761l * value);
+ }
+
+ public static int
+ hashAdd(int hashCode, byte value)
+ {
+ return ((hashCode << 5) + hashCode) ^ (int)(2654435761l * value);
+ }
+
+ public static int
+ hashAdd(int hashCode, int value)
+ {
+ return ((hashCode << 5) + hashCode) ^ (int)(2654435761l * value);
+ }
+
+ public static int
+ hashAdd(int hashCode, long value)
+ {
+ return ((hashCode << 5) + hashCode) ^ (int)(value ^ (value >>> 32));
+ }
+
+ public static int
+ hashAdd(int hashCode, float value)
+ {
+ return ((hashCode << 5) + hashCode) ^ Float.floatToIntBits(value);
+ }
+
+ public static int
+ hashAdd(int hashCode, double value)
+ {
+ long v = Double.doubleToLongBits(value);
+ return ((hashCode << 5) + hashCode) ^ (int)(v ^ (v >>> 32));
+ }
+
+ public static int
+ hashAdd(int hashCode, java.lang.Object value)
+ {
+ if(value != null)
+ {
+ hashCode = ((hashCode << 5) + hashCode) ^ value.hashCode();
+ }
+ return hashCode;
+ }
+
+ public static int
+ hashAdd(int hashCode, boolean[] arr)
+ {
+ return ((hashCode << 5) + hashCode) ^ java.util.Arrays.hashCode(arr);
+ }
+
+ public static int
+ hashAdd(int hashCode, byte[] arr)
+ {
+ return ((hashCode << 5) + hashCode) ^ java.util.Arrays.hashCode(arr);
+ }
+
+ public static int
+ hashAdd(int hashCode, char[] arr)
+ {
+ return ((hashCode << 5) + hashCode) ^ java.util.Arrays.hashCode(arr);
+ }
+
+ public static int
+ hashAdd(int hashCode, double[] arr)
+ {
+ return ((hashCode << 5) + hashCode) ^ java.util.Arrays.hashCode(arr);
+ }
+
+ public static int
+ hashAdd(int hashCode, float[] arr)
+ {
+ return ((hashCode << 5) + hashCode) ^ java.util.Arrays.hashCode(arr);
+ }
+
+ public static int
+ hashAdd(int hashCode, int[] arr)
+ {
+ return ((hashCode << 5) + hashCode) ^ java.util.Arrays.hashCode(arr);
+ }
+
+ public static int
+ hashAdd(int hashCode, long[] arr)
+ {
+ return ((hashCode << 5) + hashCode) ^ java.util.Arrays.hashCode(arr);
+ }
+
+ public static int
+ hashAdd(int hashCode, Object[] arr)
+ {
+ return ((hashCode << 5) + hashCode) ^ java.util.Arrays.hashCode(arr);
+ }
+
+ public static int
+ hashAdd(int hashCode, short[] arr)
+ {
+ return ((hashCode << 5) + hashCode) ^ java.util.Arrays.hashCode(arr);
+ }
+}
diff --git a/java/src/IceInternal/OpaqueEndpointI.java b/java/src/IceInternal/OpaqueEndpointI.java
index 3982b095415..f40763a418a 100644
--- a/java/src/IceInternal/OpaqueEndpointI.java
+++ b/java/src/IceInternal/OpaqueEndpointI.java
@@ -433,13 +433,11 @@ final class OpaqueEndpointI extends EndpointI
private void
calcHashValue()
{
- _hashCode = _type;
- _hashCode = 5 * _hashCode + _rawEncoding.major;
- _hashCode = 5 * _hashCode + _rawEncoding.minor;
- for(int i = 0; i < _rawBytes.length; i++)
- {
- _hashCode = 5 * _hashCode + _rawBytes[i];
- }
+ int h = 5381;
+ h = IceInternal.HashUtil.hashAdd(h, _type);
+ h = IceInternal.HashUtil.hashAdd(h, _rawEncoding);
+ h = IceInternal.HashUtil.hashAdd(h, _rawBytes);
+ _hashCode = h;
}
private short _type;
diff --git a/java/src/IceInternal/Reference.java b/java/src/IceInternal/Reference.java
index 8a1357d8401..2e6e1f4af1a 100644
--- a/java/src/IceInternal/Reference.java
+++ b/java/src/IceInternal/Reference.java
@@ -201,20 +201,23 @@ public abstract class Reference implements Cloneable
return _hashValue;
}
- int h = _mode;
-
- h = 5 * h + _identity.hashCode();
-
- h = 5 * h + _context.hashCode();
-
- h = 5 * h + _facet.hashCode();
-
- h = 5 * h + (_secure ? 1 : 0);
+ int h = 5381;
+ h = IceInternal.HashUtil.hashAdd(h, _mode);
+ h = IceInternal.HashUtil.hashAdd(h, _secure);
+ h = IceInternal.HashUtil.hashAdd(h, _identity);
+ h = IceInternal.HashUtil.hashAdd(h, _context);
+ h = IceInternal.HashUtil.hashAdd(h, _facet);
+ h = IceInternal.HashUtil.hashAdd(h, _overrideCompress);
+ if(_overrideCompress)
+ {
+ h = IceInternal.HashUtil.hashAdd(h, _compress);
+ }
+ h = IceInternal.HashUtil.hashAdd(h, _encoding);
_hashValue = h;
_hashInitialized = true;
- return h;
+ return _hashValue;
}
//
diff --git a/java/src/IceInternal/RoutableReference.java b/java/src/IceInternal/RoutableReference.java
index 2e70432de90..e1f9607a4a8 100644
--- a/java/src/IceInternal/RoutableReference.java
+++ b/java/src/IceInternal/RoutableReference.java
@@ -369,9 +369,7 @@ public class RoutableReference extends Reference
if(!_hashInitialized)
{
super.hashCode(); // Initializes _hashValue.
-
- // Add hash of adapter ID to base hash.
- _hashValue = 5 * _hashValue + _adapterId.hashCode();
+ _hashValue = IceInternal.HashUtil.hashAdd(_hashValue, _adapterId);
}
return _hashValue;
}
diff --git a/java/src/IceInternal/TcpConnector.java b/java/src/IceInternal/TcpConnector.java
index 7947a4152f8..71503101dc5 100644
--- a/java/src/IceInternal/TcpConnector.java
+++ b/java/src/IceInternal/TcpConnector.java
@@ -80,12 +80,13 @@ final class TcpConnector implements Connector
_encoding = encoding;
_connectionId = connectionId;
- _hashCode = _addr.getAddress().getHostAddress().hashCode();
- _hashCode = 5 * _hashCode + _addr.getPort();
- _hashCode = 5 * _hashCode + _timeout;
- _hashCode = 5 * _hashCode + _protocol.hashCode();
- _hashCode = 5 * _hashCode + _encoding.hashCode();
- _hashCode = 5 * _hashCode + _connectionId.hashCode();
+ _hashCode = 5381;
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _addr.getAddress().getHostAddress());
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _addr.getPort());
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _timeout);
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _protocol);
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _encoding);
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _connectionId);
}
public boolean
diff --git a/java/src/IceInternal/TcpEndpointI.java b/java/src/IceInternal/TcpEndpointI.java
index 0d2ab229193..18426c4494d 100644
--- a/java/src/IceInternal/TcpEndpointI.java
+++ b/java/src/IceInternal/TcpEndpointI.java
@@ -556,13 +556,16 @@ final class TcpEndpointI extends EndpointI
private void
calcHashValue()
{
- _hashCode = _host.hashCode();
- _hashCode = 5 * _hashCode + _port;
- _hashCode = 5 * _hashCode + _timeout;
- _hashCode = 5 * _hashCode + _protocol.hashCode();
- _hashCode = 5 * _hashCode + _encoding.hashCode();
- _hashCode = 5 * _hashCode + _connectionId.hashCode();
- _hashCode = 5 * _hashCode + (_compress ? 1 : 0);
+ int h = 5381;
+ h = IceInternal.HashUtil.hashAdd(h, Ice.TCPEndpointType.value);
+ h = IceInternal.HashUtil.hashAdd(h, _host);
+ h = IceInternal.HashUtil.hashAdd(h, _port);
+ h = IceInternal.HashUtil.hashAdd(h, _timeout);
+ h = IceInternal.HashUtil.hashAdd(h, _protocol);
+ h = IceInternal.HashUtil.hashAdd(h, _encoding);
+ h = IceInternal.HashUtil.hashAdd(h, _connectionId);
+ h = IceInternal.HashUtil.hashAdd(h, _compress);
+ _hashCode = h;
}
private Instance _instance;
diff --git a/java/src/IceInternal/UdpConnector.java b/java/src/IceInternal/UdpConnector.java
index 1d231ef6b31..152e838dd58 100644
--- a/java/src/IceInternal/UdpConnector.java
+++ b/java/src/IceInternal/UdpConnector.java
@@ -56,13 +56,14 @@ final class UdpConnector implements Connector
_encoding = encoding;
_connectionId = connectionId;
- _hashCode = _addr.getAddress().getHostAddress().hashCode();
- _hashCode = 5 * _hashCode + _addr.getPort();
- _hashCode = 5 * _hashCode + _mcastInterface.hashCode();
- _hashCode = 5 * _hashCode + _protocol.hashCode();
- _hashCode = 5 * _hashCode + _encoding.hashCode();
- _hashCode = 5 * _hashCode + _mcastTtl;
- _hashCode = 5 * _hashCode + _connectionId.hashCode();
+ _hashCode = 5381;
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _addr.getAddress().getHostAddress());
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _addr.getPort());
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _mcastInterface);
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _protocol);
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _encoding);
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _mcastTtl);
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _connectionId);
}
public boolean
diff --git a/java/src/IceInternal/UdpEndpointI.java b/java/src/IceInternal/UdpEndpointI.java
index d3a8c23f27f..8e78a33079c 100644
--- a/java/src/IceInternal/UdpEndpointI.java
+++ b/java/src/IceInternal/UdpEndpointI.java
@@ -583,15 +583,18 @@ final class UdpEndpointI extends EndpointI
private void
calcHashValue()
{
- _hashCode = _host.hashCode();
- _hashCode = 5 * _hashCode + _port;
- _hashCode = 5 * _hashCode + _mcastInterface.hashCode();
- _hashCode = 5 * _hashCode + _mcastTtl;
- _hashCode = 5 * _hashCode + (_connect ? 1 : 0);
- _hashCode = 5 * _hashCode + _protocol.hashCode();
- _hashCode = 5 * _hashCode + _encoding.hashCode();
- _hashCode = 5 * _hashCode + _connectionId.hashCode();
- _hashCode = 5 * _hashCode + (_compress ? 1 : 0);
+ int h = 5381;
+ h = IceInternal.HashUtil.hashAdd(h, Ice.UDPEndpointType.value);
+ h = IceInternal.HashUtil.hashAdd(h, _host);
+ h = IceInternal.HashUtil.hashAdd(h, _port);
+ h = IceInternal.HashUtil.hashAdd(h, _mcastInterface);
+ h = IceInternal.HashUtil.hashAdd(h, _mcastTtl);
+ h = IceInternal.HashUtil.hashAdd(h, _connect);
+ h = IceInternal.HashUtil.hashAdd(h, _protocol);
+ h = IceInternal.HashUtil.hashAdd(h, _encoding);
+ h = IceInternal.HashUtil.hashAdd(h, _connectionId);
+ h = IceInternal.HashUtil.hashAdd(h, _compress);
+ _hashCode = h;
}
private Instance _instance;
diff --git a/java/src/IceSSL/ConnectorI.java b/java/src/IceSSL/ConnectorI.java
index a2478eb3867..12db25b4f18 100644
--- a/java/src/IceSSL/ConnectorI.java
+++ b/java/src/IceSSL/ConnectorI.java
@@ -91,12 +91,13 @@ final class ConnectorI implements IceInternal.Connector
_encoding = encoding;
_connectionId = connectionId;
- _hashCode = _addr.getAddress().getHostAddress().hashCode();
- _hashCode = 5 * _hashCode + _addr.getPort();
- _hashCode = 5 * _hashCode + _timeout;
- _hashCode = 5 * _hashCode + _protocol.hashCode();
- _hashCode = 5 * _hashCode + _encoding.hashCode();
- _hashCode = 5 * _hashCode + _connectionId.hashCode();
+ _hashCode = 5381;
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _addr.getAddress().getHostAddress());
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _addr.getPort());
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _timeout);
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _protocol);
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _encoding);
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _connectionId);
}
public boolean
diff --git a/java/src/IceSSL/EndpointI.java b/java/src/IceSSL/EndpointI.java
index 8ccd13656fc..e768b26d40e 100644
--- a/java/src/IceSSL/EndpointI.java
+++ b/java/src/IceSSL/EndpointI.java
@@ -554,13 +554,16 @@ final class EndpointI extends IceInternal.EndpointI
private void
calcHashValue()
{
- _hashCode = _host.hashCode();
- _hashCode = 5 * _hashCode + _port;
- _hashCode = 5 * _hashCode + _timeout;
- _hashCode = 5 * _hashCode + _protocol.hashCode();
- _hashCode = 5 * _hashCode + _encoding.hashCode();
- _hashCode = 5 * _hashCode + _connectionId.hashCode();
- _hashCode = 5 * _hashCode + (_compress ? 1 : 0);
+ int h = 5381;
+ h = IceInternal.HashUtil.hashAdd(h, EndpointType.value);
+ h = IceInternal.HashUtil.hashAdd(h, _host);
+ h = IceInternal.HashUtil.hashAdd(h, _port);
+ h = IceInternal.HashUtil.hashAdd(h, _timeout);
+ h = IceInternal.HashUtil.hashAdd(h, _protocol);
+ h = IceInternal.HashUtil.hashAdd(h, _encoding);
+ h = IceInternal.HashUtil.hashAdd(h, _connectionId);
+ h = IceInternal.HashUtil.hashAdd(h, _compress);
+ _hashCode = h;
}
private Instance _instance;
diff --git a/java/test/Ice/hash/Client.java b/java/test/Ice/hash/Client.java
new file mode 100644
index 00000000000..07bc968b7e7
--- /dev/null
+++ b/java/test/Ice/hash/Client.java
@@ -0,0 +1,429 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+package test.Ice.hash;
+
+public class Client
+{
+ private static void
+ test(boolean b)
+ {
+ if(!b)
+ {
+ throw new RuntimeException();
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ int status = 0;
+ try
+ {
+ java.util.Map<Integer, Ice.ObjectPrx> seenProxy = new java.util.HashMap<Integer, Ice.ObjectPrx>();
+ java.util.Map<Integer, Ice.Endpoint> seenEndpoint = new java.util.HashMap<Integer, Ice.Endpoint>();
+ int proxyCollisions = 0;
+ int endpointCollisions = 0;
+ int i = 0;
+ int maxCollisions = 10;
+ int maxIterations = 10000;
+
+ Ice.InitializationData initData = new Ice.InitializationData();
+ initData.properties = Ice.Util.createProperties(args);
+ initData.properties.setProperty("Ice.Plugin.IceSSL", "IceSSL.PluginFactory");
+ Ice.Communicator communicator = Ice.Util.initialize(args, initData);
+
+ System.out.print("testing proxy & endpoint hash algorithm collisions... ");
+ {
+ java.util.Random rand = new java.util.Random();
+ for(i = 0; proxyCollisions < maxCollisions &&
+ endpointCollisions < maxCollisions &&
+ i < maxIterations; ++i)
+ {
+ java.io.StringWriter sw = new java.io.StringWriter();
+ sw.write(Integer.toString(i));
+ sw.write(":tcp -p ");
+ sw.write(Integer.toString(rand.nextInt(65536)));
+ sw.write(" -t 10");
+ sw.write(Integer.toString(rand.nextInt(1000000)));
+ sw.write(":udp -p ");
+ sw.write(Integer.toString(rand.nextInt(65536)));
+ sw.write(" -h ");
+ sw.write(Integer.toString(rand.nextInt(100)));
+
+ Ice.ObjectPrx obj = communicator.stringToProxy(sw.toString());
+ java.util.List<Ice.Endpoint> endpoints = new java.util.ArrayList<Ice.Endpoint>(java.util.Arrays.asList(obj.ice_getEndpoints()));
+ if(seenProxy.containsKey(obj.hashCode()))
+ {
+ if(obj.equals(seenProxy.get(obj.hashCode())))
+ {
+ continue; // Same object
+ }
+ ++proxyCollisions;
+ }
+ else
+ {
+ seenProxy.put(obj.hashCode(), obj);
+ }
+
+ java.util.Iterator<Ice.Endpoint> j = endpoints.iterator();
+ while(j.hasNext())
+ {
+ Ice.Endpoint endpoint = j.next();
+ if(seenEndpoint.containsKey(endpoint.hashCode()))
+ {
+ if(endpoint.equals(seenEndpoint.get(endpoint.hashCode())))
+ {
+ continue; // Same endpoint
+ }
+ ++endpointCollisions;
+ System.out.println(endpoint.toString() + " == " + seenEndpoint.get(endpoint.hashCode()).toString() + " == " + endpoint.hashCode());
+ }
+ else
+ {
+ seenEndpoint.put(endpoint.hashCode(), endpoint);
+ }
+ //
+ // Check the same endpoint produce always the same hash
+ //
+ test(endpoint.hashCode() == endpoint.hashCode());
+ }
+ //
+ // Check the same proxy produce always the same hash
+ //
+ test(obj.hashCode() == obj.hashCode());
+ }
+ test(proxyCollisions < maxCollisions);
+ test(endpointCollisions < maxCollisions);
+
+ proxyCollisions = 0;
+ seenProxy = new java.util.HashMap<Integer, Ice.ObjectPrx>();
+ for(i = 0; proxyCollisions < maxCollisions &&
+ endpointCollisions < maxCollisions &&
+ i < maxIterations; ++i)
+ {
+ java.io.StringWriter sw = new java.io.StringWriter();
+ sw.write(Integer.toString(i));
+ sw.write(":tcp -p ");
+ sw.write(Integer.toString(rand.nextInt(65536)));
+ sw.write(" -t 10");
+ sw.write(Integer.toString(rand.nextInt(1000000)));
+ sw.write(":udp -p ");
+ sw.write(Integer.toString(rand.nextInt(65536)));
+ sw.write(" -h ");
+ sw.write(Integer.toString(rand.nextInt(100)));
+
+ Ice.ProxyIdentityKey obj = new Ice.ProxyIdentityKey(communicator.stringToProxy(sw.toString()));
+ if(seenProxy.containsKey(obj.hashCode()))
+ {
+ ++proxyCollisions;
+ }
+ else
+ {
+ seenProxy.put(obj.hashCode(), obj.getProxy());
+ }
+ //
+ // Check the same proxy produce always the same hash
+ //
+ test(obj.hashCode() == obj.hashCode());
+ }
+ test(proxyCollisions < maxCollisions);
+
+ proxyCollisions = 0;
+ seenProxy = new java.util.HashMap<Integer, Ice.ObjectPrx>();
+ for(i = 0; proxyCollisions < maxCollisions &&
+ endpointCollisions < maxCollisions &&
+ i < maxIterations; ++i)
+ {
+ java.io.StringWriter sw = new java.io.StringWriter();
+ sw.write(Integer.toString(i));
+ sw.write(":tcp -p ");
+ sw.write(Integer.toString(rand.nextInt(65536)));
+ sw.write(" -t 10");
+ sw.write(Integer.toString(rand.nextInt(1000000)));
+ sw.write(":udp -p ");
+ sw.write(Integer.toString(rand.nextInt(65536)));
+ sw.write(" -h ");
+ sw.write(Integer.toString(rand.nextInt(100)));
+
+ Ice.ProxyIdentityFacetKey obj = new Ice.ProxyIdentityFacetKey(communicator.stringToProxy(sw.toString()));
+ if(seenProxy.containsKey(obj.hashCode()))
+ {
+ ++proxyCollisions;
+ }
+ else
+ {
+ seenProxy.put(obj.hashCode(), obj.getProxy());
+ }
+ //
+ // Check the same proxy produce always the same hash
+ //
+ test(obj.hashCode() == obj.hashCode());
+ }
+ test(proxyCollisions < maxCollisions);
+
+ Ice.ObjectPrx prx1 = communicator.stringToProxy("Glacier2/router:tcp -p 10010");
+ Ice.ObjectPrx prx2 = communicator.stringToProxy("Glacier2/router:ssl -p 10011");
+ Ice.ObjectPrx prx3 = communicator.stringToProxy("Glacier2/router:udp -p 10012");
+ Ice.ObjectPrx prx4 = communicator.stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010");
+ Ice.ObjectPrx prx5 = communicator.stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011");
+ Ice.ObjectPrx prx6 = communicator.stringToProxy("Glacier2/router:udp -h zeroc.com -p 10012");
+ Ice.ObjectPrx prx7 = communicator.stringToProxy("Glacier2/router:tcp -p 10010 -t 10000");
+ Ice.ObjectPrx prx8 = communicator.stringToProxy("Glacier2/router:ssl -p 10011 -t 10000");
+ Ice.ObjectPrx prx9 = communicator.stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010 -t 10000");
+ Ice.ObjectPrx prx10 = communicator.stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011 -t 10000");
+
+ java.util.Map<String, Integer> proxyMap = new java.util.HashMap<String, Integer>();
+ proxyMap.put("prx1", prx1.hashCode());
+ proxyMap.put("prx2", prx2.hashCode());
+ proxyMap.put("prx3", prx3.hashCode());
+ proxyMap.put("prx4", prx4.hashCode());
+ proxyMap.put("prx5", prx5.hashCode());
+ proxyMap.put("prx6", prx6.hashCode());
+ proxyMap.put("prx7", prx7.hashCode());
+ proxyMap.put("prx8", prx8.hashCode());
+ proxyMap.put("prx9", prx9.hashCode());
+ proxyMap.put("prx10", prx10.hashCode());
+
+ test(communicator.stringToProxy("Glacier2/router:tcp -p 10010").hashCode() == proxyMap.get("prx1"));
+ test(communicator.stringToProxy("Glacier2/router:ssl -p 10011").hashCode() == proxyMap.get("prx2"));
+ test(communicator.stringToProxy("Glacier2/router:udp -p 10012").hashCode() == proxyMap.get("prx3"));
+ test(communicator.stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010").hashCode() == proxyMap.get("prx4"));
+ test(communicator.stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011").hashCode() == proxyMap.get("prx5"));
+ test(communicator.stringToProxy("Glacier2/router:udp -h zeroc.com -p 10012").hashCode() == proxyMap.get("prx6"));
+ test(communicator.stringToProxy("Glacier2/router:tcp -p 10010 -t 10000").hashCode() == proxyMap.get("prx7"));
+ test(communicator.stringToProxy("Glacier2/router:ssl -p 10011 -t 10000").hashCode() == proxyMap.get("prx8"));
+ test(communicator.stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010 -t 10000").hashCode() == proxyMap.get("prx9"));
+ test(communicator.stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011 -t 10000").hashCode() == proxyMap.get("prx10"));
+
+ test(new Ice.ProxyIdentityKey(prx1).hashCode() == new Ice.ProxyIdentityKey(prx1).hashCode());
+ test(new Ice.ProxyIdentityFacetKey(prx1).hashCode() == new Ice.ProxyIdentityFacetKey(prx1).hashCode());
+
+ test(new Ice.ProxyIdentityKey(prx1).hashCode() == new Ice.ProxyIdentityKey(prx2).hashCode());
+ test(new Ice.ProxyIdentityFacetKey(prx1).hashCode() == new Ice.ProxyIdentityFacetKey(prx2).hashCode());
+
+ test(new Ice.ProxyIdentityKey(prx1).hashCode() == new Ice.ProxyIdentityKey(prx3).hashCode());
+ test(new Ice.ProxyIdentityFacetKey(prx1).hashCode() == new Ice.ProxyIdentityFacetKey(prx3).hashCode());
+
+ test(new Ice.ProxyIdentityKey(prx1).hashCode() == new Ice.ProxyIdentityKey(prx4).hashCode());
+ test(new Ice.ProxyIdentityFacetKey(prx1).hashCode() == new Ice.ProxyIdentityFacetKey(prx4).hashCode());
+
+ test(new Ice.ProxyIdentityKey(prx1).hashCode() == new Ice.ProxyIdentityKey(prx5).hashCode());
+ test(new Ice.ProxyIdentityFacetKey(prx1).hashCode() == new Ice.ProxyIdentityFacetKey(prx5).hashCode());
+
+ test(new Ice.ProxyIdentityKey(prx1).hashCode() == new Ice.ProxyIdentityKey(prx6).hashCode());
+ test(new Ice.ProxyIdentityFacetKey(prx1).hashCode() == new Ice.ProxyIdentityFacetKey(prx6).hashCode());
+
+ test(new Ice.ProxyIdentityKey(prx1).hashCode() == new Ice.ProxyIdentityKey(prx7).hashCode());
+ test(new Ice.ProxyIdentityFacetKey(prx1).hashCode() == new Ice.ProxyIdentityFacetKey(prx7).hashCode());
+
+ test(new Ice.ProxyIdentityKey(prx1).hashCode() == new Ice.ProxyIdentityKey(prx8).hashCode());
+ test(new Ice.ProxyIdentityFacetKey(prx1).hashCode() == new Ice.ProxyIdentityFacetKey(prx8).hashCode());
+
+ test(new Ice.ProxyIdentityKey(prx1).hashCode() == new Ice.ProxyIdentityKey(prx9).hashCode());
+ test(new Ice.ProxyIdentityFacetKey(prx1).hashCode() == new Ice.ProxyIdentityFacetKey(prx9).hashCode());
+
+ test(new Ice.ProxyIdentityKey(prx1).hashCode() == new Ice.ProxyIdentityKey(prx10).hashCode());
+ test(new Ice.ProxyIdentityFacetKey(prx1).hashCode() == new Ice.ProxyIdentityFacetKey(prx10).hashCode());
+ }
+
+ System.out.println("ok");
+
+ System.out.print("testing struct hash algorithm collisions... ");
+ {
+ java.util.Map<Integer,Test.PointF> seenPointF = new java.util.HashMap<Integer, Test.PointF>();
+ java.util.Random rand = new java.util.Random();
+ int structCollisions = 0;
+ for(i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
+ {
+ Test.PointF pf = new Test.PointF(rand.nextFloat(), rand.nextFloat(), rand.nextFloat());
+ if(seenPointF.containsKey(pf.hashCode()))
+ {
+ if(pf.equals(seenPointF.get(pf.hashCode())))
+ {
+ continue; // same object
+ }
+ structCollisions++;
+ }
+ else
+ {
+ seenPointF.put(pf.hashCode(), pf);
+ }
+ //
+ // Check the same struct produce always the same hash
+ //
+ test(pf.hashCode() == pf.hashCode());
+ }
+ test(structCollisions < maxCollisions);
+
+ java.util.Map<Integer,Test.PointD> seenPointD = new java.util.HashMap<Integer, Test.PointD>();
+ rand = new java.util.Random();
+ structCollisions = 0;
+ for(i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
+ {
+ Test.PointD pd = new Test.PointD(rand.nextDouble(), rand.nextDouble(), rand.nextDouble());
+ if(seenPointD.containsKey(pd.hashCode()))
+ {
+ if(pd.equals(seenPointF.get(pd.hashCode())))
+ {
+ continue; // same object
+ }
+ structCollisions++;
+ }
+ else
+ {
+ seenPointD.put(pd.hashCode(), pd);
+ }
+ //
+ // Check the same struct produce always the same hash
+ //
+ test(pd.hashCode() == pd.hashCode());
+ }
+ test(structCollisions < maxCollisions);
+
+ java.util.Map<Integer,Test.Polyline> seenPolyline = new java.util.HashMap<Integer, Test.Polyline>();
+ structCollisions = 0;
+ for(i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
+ {
+ Test.Polyline polyline = new Test.Polyline();
+ java.util.List<Test.Point> vertices = new java.util.ArrayList<Test.Point>();
+ for(int j = 0; j < 100; ++j)
+ {
+ vertices.add(new Test.Point(rand.nextInt(100), rand.nextInt(100)));
+ }
+ polyline.vertices = new Test.Point[vertices.size()];
+ vertices.toArray(polyline.vertices);
+
+ if(seenPolyline.containsKey(polyline.hashCode()))
+ {
+ if(polyline.equals(seenPolyline.get(polyline.hashCode())))
+ {
+ continue; // same object
+ }
+ structCollisions++;
+ }
+ else
+ {
+ seenPolyline.put(polyline.hashCode(), polyline);
+ }
+ //
+ // Check the same struct produce always the same hash
+ //
+ test(polyline.hashCode() == polyline.hashCode());
+ }
+ test(structCollisions < maxCollisions);
+
+ java.util.Map<Integer,Test.ColorPalette> seenColorPalette = new java.util.HashMap<Integer, Test.ColorPalette>();
+ structCollisions = 0;
+ for(i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
+ {
+ Test.ColorPalette colorPalette = new Test.ColorPalette();
+ colorPalette.colors = new java.util.HashMap<Integer, Test.Color>();
+ for(int j = 0; j < 100; ++j)
+ {
+ colorPalette.colors.put(j, new Test.Color(rand.nextInt(255), rand.nextInt(255), rand.nextInt(255), rand.nextInt(255)));
+ }
+
+ if(seenColorPalette.containsKey(colorPalette.hashCode()))
+ {
+ if(colorPalette.equals(seenColorPalette.get(colorPalette.hashCode())))
+ {
+ continue; // same object
+ }
+ structCollisions++;
+ }
+ else
+ {
+ seenColorPalette.put(colorPalette.hashCode(), colorPalette);
+ }
+ //
+ // Check the same struct produce always the same hash
+ //
+ test(colorPalette.hashCode() == colorPalette.hashCode());
+ }
+ test(structCollisions < maxCollisions);
+
+ java.util.Map<Integer,Test.Color> seenColor = new java.util.HashMap<Integer, Test.Color>();
+ rand = new java.util.Random();
+ structCollisions = 0;
+ for(i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
+ {
+ Test.Color c = new Test.Color(rand.nextInt(255), rand.nextInt(255), rand.nextInt(255), rand.nextInt(255));
+ if(seenColor.containsKey(c.hashCode()))
+ {
+ if(c.equals(seenColor.get(c.hashCode())))
+ {
+ continue; // same object
+ }
+ structCollisions++;
+ }
+ else
+ {
+ seenColor.put(c.hashCode(), c);
+ }
+ //
+ // Check the same struct produce always the same hash
+ //
+ test(c.hashCode() == c.hashCode());
+ }
+ test(structCollisions < maxCollisions);
+
+ structCollisions = 0;
+ java.util.Map<Integer,Test.Draw> seenDraw = new java.util.HashMap<Integer, Test.Draw>();
+ structCollisions = 0;
+ for(i = 0; i < maxIterations && structCollisions < maxCollisions; ++i)
+ {
+ Test.Draw draw = new Test.Draw(
+ new Test.Color(rand.nextInt(255), rand.nextInt(255), rand.nextInt(255), rand.nextInt(255)),
+ new Test.Pen(rand.nextInt(10),
+ new Test.Color(rand.nextInt(255), rand.nextInt(255), rand.nextInt(255), rand.nextInt(255))),
+ false);
+
+ if(seenDraw.containsKey(draw.hashCode()))
+ {
+ if(draw.equals(seenDraw.get(draw.hashCode())))
+ {
+ continue; // same object
+ }
+ structCollisions++;
+ }
+ else
+ {
+ seenDraw.put(draw.hashCode(), draw);
+ }
+ //
+ // Check the same struct produce always the same hash
+ //
+ test(draw.hashCode() == draw.hashCode());
+ }
+ test(structCollisions < maxCollisions);
+ }
+ System.out.println("ok");
+
+ if(communicator != null)
+ {
+ try
+ {
+ communicator.destroy();
+ }
+ catch(Ice.LocalException ex)
+ {
+ System.out.println(ex.toString());
+ status = 1;
+ }
+ }
+ }
+ catch(Exception ex)
+ {
+ System.out.println(ex.toString());
+ status = 1;
+ }
+ System.gc();
+ System.exit(status);
+ }
+}
diff --git a/java/test/Ice/hash/Test.ice b/java/test/Ice/hash/Test.ice
new file mode 100644
index 00000000000..29f0a0c803d
--- /dev/null
+++ b/java/test/Ice/hash/Test.ice
@@ -0,0 +1,71 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#pragma once
+
+module Test
+{
+
+struct PointF
+{
+ float x;
+ float y;
+ float z;
+};
+
+struct PointD
+{
+ double x;
+ double y;
+ double z;
+};
+
+struct Point
+{
+ int x;
+ int y;
+};
+sequence<Point> Points;
+
+struct Polyline
+{
+ Points vertices;
+};
+
+struct Color
+{
+ int r;
+ int g;
+ int b;
+ int a;
+};
+
+
+dictionary<int, Color> StringColorMap;
+
+struct ColorPalette
+{
+ StringColorMap colors;
+};
+
+class Pen
+{
+ int thickness;
+ Test::Color color;
+};
+
+struct Draw
+{
+ Test::Color backgroundColor;
+ Test::Pen pen;
+ bool shared;
+};
+
+};
+
diff --git a/java/test/Ice/hash/run.py b/java/test/Ice/hash/run.py
new file mode 100755
index 00000000000..de3d7b155fb
--- /dev/null
+++ b/java/test/Ice/hash/run.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+# **********************************************************************
+#
+# Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
+#
+# This copy of Ice is licensed to you under the terms described in the
+# ICE_LICENSE file included in this distribution.
+#
+# **********************************************************************
+
+import os, sys
+
+path = [ ".", "..", "../..", "../../..", "../../../.." ]
+head = os.path.dirname(sys.argv[0])
+if len(head) > 0:
+ path = [os.path.join(head, p) for p in path]
+path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ]
+if len(path) == 0:
+ raise "can't find toplevel directory!"
+sys.path.append(os.path.join(path[0]))
+from scripts import *
+
+print "starting client...",
+clientProc = TestUtil.startClient("test.Ice.hash.Client",startReader=False)
+print "ok"
+clientProc.startReader()
+clientProc.waitTestSuccess()
+