static void Main(string[] args) { TwoDPointWithHash newPoint1 = new TwoDPointWithHash(1, 1); TwoDPointWithHash newPoint2 = new TwoDPointWithHash(10, 10); Console.WriteLine($"Hash for point1: {newPoint1.GetHashCode()}\tHash for point2: {newPoint2.GetHashCode()}"); // проверка совпадений хэш кодов int countHashRe = 0; Dictionary <int, Tuple <int, int> > dict = new Dictionary <int, Tuple <int, int> >(); for (int i = 0; i < 1000; i++) { for (int j = 0; j < 1000; j++) { TwoDPointWithHash point = new TwoDPointWithHash(i, j); int hash = point.GetHashCode(); if (dict.ContainsKey(hash)) { //Console.WriteLine($"Hash exists by {dict[hash].Item1}:{dict[hash].Item2}, current point {i}:{j}"); countHashRe++; } else { dict.Add(hash, new Tuple <int, int>(i, j)); } } } Console.WriteLine($"Совпадений: {countHashRe}"); Console.WriteLine("Нажмите любую клавишу для выхода"); Console.ReadKey(); }
static void Main(string[] args) { var hashs = new List <int>(); for (var i = 0; i < 1000; i++) { for (var j = 0; j < 1000; j++) { var point = new TwoDPointWithHash(i, j); hashs.Add(point.GetHashCode()); } } var uniqueValues = hashs.Distinct().ToList(); double errors = hashs.Count - uniqueValues.Count; double proc = errors / hashs.Count * 100; Console.WriteLine(uniqueValues.Count); Console.WriteLine(errors); Console.WriteLine(proc); //12 task FileSystemWatcher }
public static void Main(string[] args) { TwoDPoint point1 = new TwoDPoint(1, 1); TwoDPoint point2 = new TwoDPoint(10, 10); Console.WriteLine("Hash for point1: {0}\tHash for point2: {1}", point1.GetHashCode(), point2.GetHashCode()); TwoDPointWithHash newPoint1 = new TwoDPointWithHash(1, 1); TwoDPointWithHash newPoint2 = new TwoDPointWithHash(10, 10); Console.WriteLine("Hash for point1: {0}\tHash for point2: {1}", newPoint1.GetHashCode(), newPoint2.GetHashCode()); Console.ReadKey(); }
static void Main(string[] args) { List <int> hashCodes = new List <int>(); List <int> Xs = new List <int>(); List <int> Ys = new List <int>(); int range = 1000; for (int i = 0; i < range; i++) { for (int j = 0; j < range; j++) { TwoDPointWithHash point = new TwoDPointWithHash(i, j); hashCodes.Add(point.GetHashCode()); } } for (int i = -1; i > -range; i--) { for (int j = 0; j > -range; j--) { TwoDPointWithHash point = new TwoDPointWithHash(i, j); hashCodes.Add(point.GetHashCode()); } } List <int> unique = hashCodes.Distinct().ToList(); List <int> sam1 = new List <int>(); HashSet <int> hash = new HashSet <int>(); foreach (int number in hashCodes) { if (!hash.Add(number)) { sam1.Add(number); } } Console.WriteLine($"All count = {hashCodes.Count}"); Console.WriteLine($"Unique count = {unique.Count}"); Console.WriteLine($"The same count = {hashCodes.Count - unique.Count}"); double countOfSame = (double)(hashCodes.Count - unique.Count) * 100 / hashCodes.Count; Console.WriteLine($"Percent = {countOfSame}"); Console.ReadKey(); }
static void Main(string[] args) { TwoDPoint point1 = new TwoDPoint(1, 10); TwoDPoint point2 = new TwoDPoint(1, 10); Console.WriteLine("Hash for point1: {0}\tHash for point2: {1}", point1.GetHashCode(), point2.GetHashCode()); TwoDPointWithHash newPoint1 = new TwoDPointWithHash(10, 10); TwoDPointWithHash newPoint2 = new TwoDPointWithHash(1, 1); Console.WriteLine("Hash for point1: {0}\tHash for point2: {1}", newPoint1.GetHashCode(), newPoint2.GetHashCode()); // уникальных точек будет 2, хотя координаты их одинаковы Console.WriteLine("TwoDPoint:"); var twoDPointList = new List <TwoDPoint> { point1, point2 }; var distinctTwoDPointList = twoDPointList.Distinct(); foreach (var point in distinctTwoDPointList) { Console.WriteLine("Distinct point: {0}", point); } // одна уникальная точка Console.WriteLine("TwoDPointWithHash:"); var twoDPointWithHashList = new List <TwoDPointWithHash> { newPoint1, newPoint2 }; var distinctTwoDPointWithHashList = twoDPointWithHashList.Distinct(); foreach (var point in distinctTwoDPointWithHashList) { Console.WriteLine("Distinct point: {0}", point); } Console.ReadKey(); }
public static void Demo(/*string[] args*/) { TwoDPoint point1 = new TwoDPoint(1, 10); TwoDPoint point2 = new TwoDPoint(1, 10); Console.WriteLine("Hash for point1: {0}\tHash for point2: {1}", point1.GetHashCode(), point2.GetHashCode()); TwoDPointWithHash newPoint1 = new TwoDPointWithHash(1, 1); TwoDPointWithHash newPoint2 = new TwoDPointWithHash(10, 10); Console.WriteLine("Hash for point1: {0}\tHash for point2: {1}", newPoint1.GetHashCode(), newPoint2.GetHashCode()); // уникальных точек будет 2, хотя координаты их одинаковы //Console.WriteLine("TwoDPointWithHash:"); // Здесь надо изменить заголовок для точек типа TwoDPoint Console.WriteLine("TwoDPoint:"); var twoDPointList = new List <TwoDPoint> { point1, point2 }; var distinctTwoDPointList = twoDPointList.Distinct(); foreach (var point in distinctTwoDPointList) { Console.WriteLine("Distinct point: {0}", point); } // одна уникальная точка Console.WriteLine("TwoDPointWithHash:"); var twoDPointWithHashList = new List <TwoDPointWithHash> { newPoint1, newPoint2 }; var distinctTwoDPointWithHashList = twoDPointWithHashList.Distinct(); foreach (var point in distinctTwoDPointWithHashList) { Console.WriteLine("Distinct point: {0}", point); } }
static void Main(string[] args) { int n = 1000000; Dictionary <TwoDPointWithHash, int> dict = new Dictionary <TwoDPointWithHash, int>(); for (int i = 0; i < n; i++) { TwoDPointWithHash point = new TwoDPointWithHash(rand.Next(-1000000, 1000000), rand.Next(-1000000, 1000000)); if (!dict.ContainsKey(point)) { dict.Add(point, point.GetHashCode()); } } var distinct = dict.Values.Distinct(); Console.WriteLine($"The same: {dict.Count - distinct.Count()}, hashes all: {dict.Count}, percent: {(double)(dict.Count - distinct.Count()) * 100.0 /(double)dict.Count}"); Console.ReadLine(); }
static void Main(string[] args) { var hash = new List <int>(); for (var i = 0; i < 1000; i++) { for (var j = 0; j < 1000; j++) { var point = new TwoDPointWithHash(i, j); hash.Add(point.GetHashCode()); } } Console.WriteLine($"All count {hash.Count}"); var unique = hash.Distinct().ToList(); Console.WriteLine($"Unique count {unique.Count}"); var theSameCount = hash.Count - unique.Count; Console.WriteLine($"The same count {theSameCount}"); Console.WriteLine($"percent {(double)((double)theSameCount * 100 / (double)hash.Count)}"); Console.ReadKey(); }
static void Main(string[] args) { TwoDPointWithHash twoDPointWithHash = new TwoDPointWithHash(5, 5); List <int> hashlist = new List <int>(); bool identity; int hashcode; int count = 0; for (int i = -50; i < 50; i++) { for (int j = -50; j < 50; j++) { count++; identity = true; twoDPointWithHash = new TwoDPointWithHash(i, j); hashcode = twoDPointWithHash.GetHashCode(); foreach (int k in hashlist) { if (k == hashcode) { identity = false; } } if (identity) { hashlist.Add(hashcode); } } } double uniqueness = hashlist.Count * 100 / count; Console.WriteLine($"Uniqueness is " + uniqueness + "%"); Console.ReadKey(); }
static void Main(string[] args) { TwoDPointWithHash td = new TwoDPointWithHash(10, 10); td.GetHashCode(); }