public void TupleHashcodeTest() { Tuple <int, int> t1 = new Tuple <int, int>(2, 9); Tuple <int, int> t2 = new Tuple <int, int>(2, 9); Assert.AreEqual(t1.GetHashCode(), t2.GetHashCode()); }
public int GetHashCode(Tuple <string, string> obj) { //We create a lowwercase invariant tuple and return its hash code. This will make Equals fire for comparison. var invariantTuple = new Tuple <string, string>(obj?.Item1?.ToLowerInvariant(), obj?.Item2?.ToLowerInvariant()); return(invariantTuple.GetHashCode()); }
public override int GetHashCode() { var hashBase = new Tuple <ITextBuffer, int>( Snapshot.TextBuffer, Snapshot.Version.VersionNumber); return(hashBase.GetHashCode()); }
public void TestInequalTuples() { Tuple <int> a1 = new Tuple <int>(3); Tuple <int> b1 = new Tuple <int>(4); Assert.False(a1.Equals(b1), "1 equals"); Assert.False(a1.GetHashCode() == b1.GetHashCode(), "1 =="); Assert.True(a1.GetHashCode() != b1.GetHashCode(), "1 !="); Tuple <int, int> a2 = new Tuple <int, int>(1, 7); Tuple <int, int> b2 = new Tuple <int, int>(1, 8); Assert.False(a2.Equals(b2), "2 equals"); Assert.False(a2.GetHashCode() == b2.GetHashCode(), "2 =="); Assert.True(a2.GetHashCode() != b2.GetHashCode(), "2 !="); }
public void TestHowTupleHashcodeWorks() { var testTuple00 = new Tuple <string, Type>(MY_TEST_STRING, typeof(int)); var testTuple01 = new Tuple <string, Type>("myTestString", typeof(int)); Assert.AreEqual(testTuple00.GetHashCode(), testTuple01.GetHashCode()); }
public override int GetHashCode() { unchecked { return(((_channel != null ? _channel.GetHashCode() : 0) * 397) ^ (_runningOp != null ? _runningOp.GetHashCode() : 0)); } }
public override int GetHashCode() { var hashBase = new Tuple <string, ITextBuffer, int>( Classification, Snapshot.TextBuffer, Snapshot.Version.VersionNumber); return(hashBase.GetHashCode()); }
public override int GetHashCode() { var tuple = new Tuple <int, int, int, int, int, int>( Position.X, Position.Y, Position.Z, Velocity.X, Velocity.Y, Velocity.Z); int hash = tuple.GetHashCode(); return(hash); }
public void SetLibraryGeometries() { foreach (KeyValuePair <Tuple <Document, ElementId>, IList <ModelGeometry> > current in this.Geometries) { Tuple <Document, ElementId> key = current.Key; if (current.Value != null && current.Value.Count > 0) { ModelMaterial exportedMaterial = this.Material[key]; string nodeName = exportedMaterial.Name; GeometrySourcePositions(key.GetHashCode(), current.Value, nodeName); GeometrySourceNormals(key.GetHashCode(), current.Value); GeometrySourceMap(key.GetHashCode(), exportedMaterial, current.Value); GeometryVertices(key.GetHashCode()); GeometryTrianglesWithMap(key.GetHashCode(), current.Value); } } }
public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hash = 17; hash = hash * 23 + _position.GetHashCode(); hash = hash * 23 + _velocity.GetHashCode(); return(hash); } }
static int SubSequence(string str1, string str2, int m, int n, Dictionary <int, int> table) { subSeq2++; if (m == 0 || n == 0) { return(0); } if (str1[m - 1] == str2[n - 1]) { Tuple <string, string, int, int> sub = new Tuple <string, string, int, int>(str1, str2, m - 1, n - 1); int subHashCode = sub.GetHashCode(); int s = 0; if (table.ContainsKey(subHashCode)) { s = table[subHashCode]; } else { s = SubSequence(str1, str2, m - 1, n - 1, table); table.Add(subHashCode, s); } return(1 + s); } Tuple <string, string, int, int> sub1 = new Tuple <string, string, int, int>(str1, str2, m - 1, n); int subHashCode1 = sub1.GetHashCode(); int s1 = 0; if (table.ContainsKey(subHashCode1)) { s1 = table[subHashCode1]; } else { s1 = SubSequence(str1, str2, m - 1, n, table); table.Add(subHashCode1, s1); } Tuple <string, string, int, int> sub2 = new Tuple <string, string, int, int>(str1, str2, m, n - 1); int subHashCode2 = sub2.GetHashCode(); int s2 = 0; if (table.ContainsKey(subHashCode2)) { s2 = table[subHashCode2]; } else { s2 = SubSequence(str1, str2, m, n - 1, table); table.Add(subHashCode2, s2); } return(Math.Max(s1, s2)); }
/// <summary> /// Returns a hash code for this instance. /// </summary> /// <returns> /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// </returns> public override int GetHashCode() { if (m_HashCode != -1) { return(m_HashCode); } int baseValue = ((int)(Type)) << 27; switch (Type) { case DataType.Void: case DataType.Nil: m_HashCode = 0; break; case DataType.Boolean: m_HashCode = Boolean ? 1 : 2; break; case DataType.Number: m_HashCode = baseValue ^ Number.GetHashCode(); break; case DataType.String: m_HashCode = baseValue ^ String.GetHashCode(); break; case DataType.Function: m_HashCode = baseValue ^ Function.GetHashCode(); break; case DataType.ClrFunction: m_HashCode = baseValue ^ Callback.GetHashCode(); break; case DataType.Table: m_HashCode = baseValue ^ Table.GetHashCode(); break; case DataType.Tuple: case DataType.TailCallRequest: m_HashCode = baseValue ^ Tuple.GetHashCode(); break; case DataType.UserData: case DataType.Thread: default: m_HashCode = 999; break; } return(m_HashCode); }
public override int GetHashCode() { unchecked { int hashCode = (moveA != null ? moveA.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (moveB != null ? moveB.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (moveC != null ? moveC.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (moveD != null ? moveD.GetHashCode() : 0); return(hashCode); } }
/// <summary> /// /// </summary> private void WriteXmlLibraryGeometries() { this.WriteXmlLibraryGeometriesBegin(); foreach (KeyValuePair <Tuple <Document, ElementId>, IList <ModelGeometry> > current in this.documentAndMaterialIdToGeometries) { Tuple <Document, ElementId> key = current.Key; if (current.Value != null && current.Value.Count > 0) { ModelMaterial exportedMaterial = this.documentAndMaterialIdToExportedMaterial[key]; this.sb.Clear(); this.WriteXmlGeometryBegin(key.GetHashCode(), exportedMaterial); this.WriteXmlGeometrySourcePositions(key.GetHashCode(), current.Value); this.WriteXmlGeometrySourceNormals(key.GetHashCode(), current.Value); this.WriteXmlGeometrySourceMap(key.GetHashCode(), exportedMaterial, current.Value); this.WriteXmlGeometryVertices(key.GetHashCode()); this.WriteXmlGeometryTrianglesWithMap(key.GetHashCode(), current.Value); this.WriteXmlGeometryEnd(); int val = 10485760; while (this.sb.Length > 0) { int length = Math.Min(val, this.sb.Length); this.streamWriter.Write(this.sb.ToString(0, length)); this.sb.Remove(0, length); } } } this.WriteXmlLibraryGeometriesEnd(); }
private void LoopComputer_NewLoop(Dictionary <long, GeoNode> allNodesCache, Tuple <GeoPath, GeoPath> obj) { var listToSave = new List <GeoNode>(obj.Item1.Nodes.Count + obj.Item2.Nodes.Count); listToSave.AddRange(obj.Item1.Nodes); var tail = obj.Item2.Nodes.ToList(); tail.Reverse(); listToSave.AddRange(tail); var fName = obj.GetHashCode().ToString(); _osmOperations.SaveNodesToShape(GetFullFileName($@"loops\{fName}.shp"), allNodesCache, listToSave); }
public void CanGetHashCode() { //-- Arrange var tuple = m_Factory.New <IThreeItemTuple>().Init(first: 123, second: "ABC", third: TimeSpan.FromMinutes(5)); var dotNetFxTuple = new Tuple <int, string, TimeSpan>(123, "ABC", TimeSpan.FromMinutes(5)); //-- Act var hashCode = tuple.GetHashCode(); //-- Assert Assert.That(hashCode, Is.EqualTo(dotNetFxTuple.GetHashCode())); }
private void createMinhashSeeds() { HashSet <int> skipDups = new HashSet <int>(); Random r = new Random(); for (int i = 0; i < minhashes.Length; i++) { Tuple <int, int> seed = new Tuple <int, int>(r.Next(), r.Next()); if (skipDups.Add(seed.GetHashCode())) { minhashes[i] = seed; } else { i--; //duplicate seed, try again } } }
public void Execute() { Console.WriteLine($"Type\t\t\t==\t\tEquals\t\tHashCode\n"); int i = 1; int j = 1; Console.WriteLine($"Int32\t\t\t{i == j}\t\t{i.Equals(j)}\t\t{i.GetHashCode() == j.GetHashCode()}\n"); string s1 = "aa"; string s2 = "aa"; Console.WriteLine($"String\t\t\t{s1 == s2}\t\t{s1.Equals(s2)}\t\t{s1.GetHashCode() == s2.GetHashCode()}\n"); Tuple <int, int> t1 = new Tuple <int, int>(1, 2); Tuple <int, int> t2 = new Tuple <int, int>(1, 2); Console.WriteLine($"Tuple<int>\t\t{t1 == t2}\t\t{t1.Equals(t2)}\t\t{t1.GetHashCode() == t2.GetHashCode()}\n"); Tuple <string, string> t3 = new Tuple <string, string>("1", "2"); Tuple <string, string> t4 = new Tuple <string, string>("1", "2"); Console.WriteLine($"Tuple<string>\t\t{t3 == t4}\t\t{t3.Equals(t4)}\t\t{t3.GetHashCode() == t4.GetHashCode()}\n"); int[] a1 = { 1, 2, 3 }; int[] a2 = { 1, 2, 3 }; Console.WriteLine($"Array<int>\t\t{a1 == a2}\t\t{a1.Equals(a2)}\t\t{a1.GetHashCode() == a2.GetHashCode()}\n"); List <int> l1 = new List <int>() { 1, 2, 3 }; List <int> l2 = new List <int>() { 1, 2, 3 }; Console.WriteLine($"List<int>\t\t{l1 == l2}\t\t{l1.Equals(l2)}\t\t{l1.GetHashCode() == l2.GetHashCode()}\n"); Console.WriteLine("\n"); }
private int GetCommandKey(SlackBotCommand command) { int commandId = CommandTypeRegistry.GetCommandId(command.Name); CommandScope scope = CommandTypeRegistry.GetCommandType(command.Name).GetCommandScope(); object preKey = null; switch (scope) { case CommandScope.Global: preKey = commandId; break; case CommandScope.Channel: preKey = new Tuple <int, string>(commandId, command.Channel.id); break; case CommandScope.User: preKey = new Tuple <int, string, string>(commandId, command.Channel.id, command.User.id); break; } return(preKey.GetHashCode()); }
public void TestEquality() { Tuple t1 = new Tuple("1", 1.0); Tuple t2 = new Tuple("1", 1.0); Assert.AreEqual(t1, t2); Assert.AreEqual(t1.GetHashCode(), t2.GetHashCode()); Assert.IsTrue(t1.Equals(t2)); t1 = new Tuple("1", 1.0); t2 = new Tuple("2", 1.0); Assert.AreNotEqual(t1, t2); Assert.AreNotEqual(t1.GetHashCode(), t2.GetHashCode()); Assert.IsFalse(t1.Equals(t2)); t1 = new Tuple("1", 1.0); t2 = new Tuple("1", 1.0, 1); Assert.AreNotEqual(t1, t2); Assert.AreNotEqual(t1.GetHashCode(), t2.GetHashCode()); Assert.IsFalse(t1.Equals(t2)); }
public static int[][] CreateMinHashSeeds(int signatureSize) { var seeds = new int[signatureSize][]; HashSet <int> skipDups = new HashSet <int>(); Random r = new Random(); for (int i = 0; i < seeds.Length; i++) { Tuple <int, int> seed = new Tuple <int, int>(r.Next(), r.Next()); if (skipDups.Add(seed.GetHashCode())) { seeds[i] = new int[] { seed.Item1, seed.Item2 } } ; else { i--; //duplicate seed, try again } } return(seeds); }
public void Run() { string guid1 = Guid.NewGuid().ToString(); string guid2 = Guid.NewGuid().ToString(); Tuple <string, string> tp1 = Tuple.Create(guid1, guid2); Tuple <string, string> tp2 = Tuple.Create(guid1, guid2); Foo foo1 = new Foo(guid1, guid2); Foo foo2 = new Foo(guid1, guid2); int hashCode; bool equals; double hashCodeCostTp = new Runner(() => hashCode = tp1.GetHashCode()).Execute(1000).Ticks; double hashCodeCostFoo = new Runner(() => hashCode = foo1.GetHashCode()).Execute(1000).Ticks; double equalsCostTp = new Runner(() => equals = tp1.Equals(tp2)).Execute(1000).Ticks; double equalsCostFoo = new Runner(() => equals = foo1.Equals(foo2)).Execute(1000).Ticks; Console.WriteLine(hashCodeCostFoo + " " + hashCodeCostTp + " " + hashCodeCostTp / hashCodeCostFoo); Console.WriteLine(equalsCostFoo + " " + equalsCostTp + " " + equalsCostTp / equalsCostFoo); }
public void TestTupleHashCode() { Tuple <int, int> key1 = new Tuple <int, int>(1, 2); Tuple <int, int> key2 = new Tuple <int, int>(1, 2); Assert.True(key1.Equals(key2), "Equals works"); Dictionary <Tuple <int, int>, int> dic = new Dictionary <Tuple <int, int>, int>(); dic.Add(key1, 1); int output1; dic.TryGetValue(key1, out output1); Assert.AreEqual(1, output1, "TryGetValue for key1"); int output2; dic.TryGetValue(key2, out output2); Assert.AreEqual(1, output2, "TryGetValue for key2"); Assert.AreEqual(key1.GetHashCode(), key2.GetHashCode(), "Same GetHashCode"); }
/// <summary> /// Ensures that the code delegate for the filter is in the CodeDelegatesCollection /// </summary> /// <param name="backOfficeRequestContext"></param> /// <param name="dataTypeId"></param> /// <param name="blockType"></param> /// <param name="codedelegate"> </param> /// <returns></returns> private static string SetupCodeDelegate( IBackOfficeRequestContext backOfficeRequestContext, HiveId dataTypeId, CSharpCodeBlockType blockType, Func <object, string, string> codedelegate) { var delegateParameter = new Tuple <HiveId, CSharpCodeBlockType>(dataTypeId, blockType); //first, check if we have this registered (multiple ids may exist for the same delegate, but in thsi case it will never be true) var ids = CodeDelegateVirtualPath.GetVirtualPathIdsForDelegate(delegateParameter).ToArray(); if (ids.Any()) { return(ids.First()); } //need to lookup the data type to get its alias as we'll use this for the path using (var uow = backOfficeRequestContext.Application.Hive.OpenReader <IContentStore>()) { var dt = uow.Repositories.Schemas.Get <AttributeType>(true, dataTypeId).SingleOrDefault(); if (dt == null) { throw new InvalidOperationException("Could not find AttributeType with id " + dataTypeId); } //create a unique path for our object which will be used in the virtual path creation, if we don't set this //then the ToString of the object key will be used which is much harder to debug. var path = dt.Alias + "_" + delegateParameter.Item2 + "_" + delegateParameter.GetHashCode().ToString().Replace("-", "0"); //only alphanumeric chars allowed var virtualPathId = CodeDelegateVirtualPath.GetOrCreateVirtualPathId(delegateParameter, path); //add the delegate to the collection CodeDelegatesCollection.TryAdd(virtualPathId, codedelegate); return(virtualPathId); } }
public void CanHashCodeTwoFiveSizedTuples() { var tuple1 = new Tuple<int>(1, 2, 3, 4, 5); var tuple2 = new Tuple<int>(1, 2, 3, 4, 5); var tuple3 = new Tuple<int>(1, 2, 3, 4, 6); tuple2.GetHashCode().Should().Be(tuple1.GetHashCode()); tuple3.GetHashCode().Should().Not.Be(tuple1.GetHashCode()); }
public int GetHashCode(Tuple <string, CallInfo, bool, bool, PSMethodInvocationConstraints> obj) { return(obj.GetHashCode()); }
public void Value_type_tuple() { // This is a bit contrived, just need an easy class (ie non-value type) var helper = new IdHelperForClassType<Tuple<int, int>>(); var tuple1 = new Tuple<int, int>(1, 2); var tuple2 = new Tuple<int, int>(1, 3); var tuple1Again = new Tuple<int, int>(1, 2); Assert.AreEqual(true, helper.IsNull(null)); Assert.AreEqual(true, helper.IsDefaultValue(null)); Assert.AreEqual(false, helper.IsDefaultValue(tuple1)); Assert.AreEqual(true, helper.AreEqual(null, null)); Assert.AreEqual(true, helper.AreEqual(tuple1, tuple1Again)); Assert.AreEqual(-1, helper.Compare(null, tuple1)); Assert.AreEqual(-1, helper.Compare(tuple1, tuple2)); Assert.AreEqual(+1, helper.Compare(tuple2, null)); Assert.AreEqual(+1, helper.Compare(tuple2, tuple1)); Assert.That(helper.Compare(null, null), Is.EqualTo(0)); Assert.AreEqual(0, helper.Compare(tuple1, tuple1Again)); Assert.AreEqual(tuple1.GetHashCode(), helper.GetHashCode(tuple1)); Assert.AreEqual(0, helper.GetHashCode(null)); }
public int GetHashCode(Tuple <Tuple <XYZ, XYZ>, Tuple <XYZ, XYZ>, XYZ> obj) { return(obj.GetHashCode()); }
public override int GetHashCode() { Tuple <string, string> cardTuple = new Tuple <string, string>(this.value, this.suit); return(cardTuple.GetHashCode()); }
public override int GetHashCode() { return((_applicationCredentials?.GetHashCode()).GetValueOrDefault()); }
public override int GetHashCode() { var tuple = new Tuple<string, string> (Id, Destination); return tuple.GetHashCode (); }
public static int GetHashCode(Tuple<string, string> fromStatusSubStatus, Tuple<string, string> toStatusSubStatus) { return (fromStatusSubStatus.GetHashCode() << 8) + toStatusSubStatus.GetHashCode(); }
public void GetHashCodeIsTheSame() { var sut2 = new Tuple<int, string>(integer, stringy); sut.GetHashCode().ShouldEqual(sut2.GetHashCode()); }
public void GetHashCodeIsTheSame() { var sut2 = new Tuple<int, string>(integer, stringy); Assert.Equal(sut2.GetHashCode(), sut.GetHashCode()); }
public void GetHashCodeIsDifferent() { var sut2 = new Tuple<int, string>(integer + 1, stringy); Assert.NotEqual(sut2.GetHashCode(), sut.GetHashCode()); }
public int GetHashCode(Tuple <ITypeName, TypeResolutionState> obj) { return(obj.GetHashCode()); }
public void CanHashCodeTwoFiveSizedNullableTuples() { var tuple1 = new Tuple<int?>(1, 2, null, 4, 5); var tuple2 = new Tuple<int?>(1, 2, null, 4, 5); var tuple3 = new Tuple<int?>(1, 2, 3, 4, null); tuple2.GetHashCode().Should().Be(tuple1.GetHashCode()); tuple3.GetHashCode().Should().Not.Be(tuple1.GetHashCode()); }
public override int GetHashCode() { return(_tuple.GetHashCode()); }
public void CannotHashCodeTwoDifferentSizesTuples() { var tuple1 = new Tuple<int>(1, 2, 3, 4, 5); var tuple2 = new Tuple<int>(1, 2, 3, 4, 5, 6); tuple2.GetHashCode().Should().Not.Be(tuple1.GetHashCode()); }