Esempio n. 1
0
        private void ResizeDataListIfNeeded()
        {
            if (this.Count > this.dataList.Length * MaxLoad)
            {
                var doubleSizedHashTable = new MyHashTable <K, T>(this.dataList.Length * 2);

                foreach (var position in this.dataList)
                {
                    if (position != null)
                    {
                        foreach (var item in position)
                        {
                            doubleSizedHashTable.Add(item.Key, item.Value);
                        }
                    }
                }

                this.dataList = doubleSizedHashTable.dataList;
            }
        }
Esempio n. 2
0
        public static void Main()
        {
            var myHashTable = new MyHashTable <string, string>();
            var random      = new Random();

            for (int i = 0; i < 50; i++)
            {
                myHashTable.Add(HelperMethods.GetRandomString(), HelperMethods.GetRandomString());
                Thread.Sleep(11);
            }

            myHashTable.Add("Hasan", "Seche");

            Console.WriteLine(myHashTable.Count);
            Console.WriteLine(myHashTable.Find("Hasan"));
            Console.WriteLine(myHashTable.Count);
            myHashTable.Remove("Hasan");
            //// Console.WriteLine(myHashTable.Find("Hasan"));
            myHashTable.Clear();
            Console.WriteLine(myHashTable.Count);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            MyHashTable <Point3D, int> dict = new MyHashTable <Point3D, int>(3, 0.9f);

            dict[new Point3D(1, 2, 3)] = 1;
            Console.WriteLine(dict[new Point3D(1, 2, 3)]);
            dict[new Point3D(1, 2, 3)] += 1;
            Console.WriteLine(dict[new Point3D(1, 2, 3)]);
            dict[new Point3D(3, 2, 2)] = 42;
            Console.WriteLine(dict[new Point3D(3, 2, 2)]);

            Console.WriteLine(dict[new Point3D(1, 2, 3)]);

            dict[new Point3D(4, 5, 6)] = 1111;
            Console.WriteLine(dict[new Point3D(4, 5, 6)]);

            dict.Remove(new Point3D(3, 2, 2));

            foreach (KeyValuePair <Point3D, int> entry in dict)
            {
                Console.WriteLine("Key: " + entry.Key + "; Value: " + entry.Value);
            }
        }