示例#1
0
        public bool Contains(SortableObject value)
        {
            var index = this.GetHash(value.Number);

            if (this.Storage[index] == null)
            {
                return(false);
            }

            return(this.Storage[index].Contains(value));
        }
示例#2
0
        public bool Remove(SortableObject value)
        {
            var index = this.GetHash(value.Number);

            if (this.Storage[index] == null)
            {
                return(false);
            }

            this.Count--;
            return(this.Storage[index].Remove(value));
        }
示例#3
0
        public bool Add(SortableObject value)
        {
            if (this.Count >= this.Size)
            {
                this.Rebuild();
            }

            var index = this.GetHash(value.Number);

            if (this.Storage[index] == null)
            {
                this.Storage[index] = new LinkedList <SortableObject>();
            }

            this.Storage[index].AddLast(value);
            this.Count++;
            return(true);
        }
        public static void Test_Table(int seed, int n)
        {
            Stopwatch sw = new Stopwatch();

            HashTableWithLinkedList table = new HashTableWithLinkedList(100);

            SortableObject temp = new SortableObject();
            Random         rand = new Random(seed);

            for (int j = 0; j < n; j++)
            {
                temp = new SortableObject();

                temp.Number = rand.Next(1, 100);

                string word = "";
                for (int text = 0; text < 8; text++)
                {
                    word += (char)rand.Next(65, 90);
                }

                temp.Text = word;

                table.Add(temp);
            }

            //Console.WriteLine("Branch count {0}", table.BranchCount());

            SortableObject toFind = new SortableObject(78, "DNSBOFYT");

            sw.Start();

            bool doesContain = table.Contains(toFind);

            sw.Stop();


            Console.WriteLine("{1,9} took => {0}", sw.Elapsed, n);
        }