Esempio n. 1
0
        public bool Insert(int key, string value)
        {
            if (Search(key) != null)
            {
                return(false);
            }

            int hash = HashCalculation.GetHash(values.Length, key, A);

            if (values[hash] == null)
            {
                values[hash] = new List <TableItem>();
            }
            values[hash].Add(new TableItem(key, value));
            return(true);
        }
Esempio n. 2
0
        public string Search(int key)
        {
            int hash = HashCalculation.GetHash(values.Length, key, A);

            if (values[hash] == null)
            {
                return(null);
            }

            foreach (TableItem item in values[hash])
            {
                if (item.Key == key)
                {
                    return(item.Value);
                }
            }
            return(null);
        }
Esempio n. 3
0
        public static double GetAverageMaxChainLength(double constA, int tableSize, int[][] arrays)
        {
            int[] chains = new int[tableSize];
            foreach (int[] array in arrays)
            {
                foreach (int num in array)
                {
                    chains[HashCalculation.GetHash(tableSize, num, constA)]++;
                }
            }
            double[] averageChains = new double[tableSize];
            for (int i = 0; i < tableSize; i++)
            {
                averageChains[i] = (double)chains[i] / arrays.Length;
            }

            return(averageChains.Max());
        }
Esempio n. 4
0
        public bool Delete(int key)
        {
            int hash = HashCalculation.GetHash(values.Length, key, A);

            if (values[hash] == null)
            {
                return(false);
            }

            foreach (TableItem item in values[hash])
            {
                if (item.Key == key)
                {
                    return(values[hash].Remove(item));
                }
            }

            return(false);
        }
Esempio n. 5
0
        public bool Insert(int key, string value)
        {
            int hash  = HashCalculation.GetDoubleHash(values.Length, key, 0, A);
            int index = hash;

            for (int iter = 1; values[index] != null; iter++)
            {
                if (index == hash && iter != 1)
                {
                    return(false);
                }
                if (deletedKeys.Contains(values[index].Key))
                {
                    break;
                }
                index = HashCalculation.GetDoubleHash(values.Length, key, iter, A);
            }
            values[index] = new TableItem(key, value);
            return(true);
        }
Esempio n. 6
0
        private TableItem SearchItem(int key)
        {
            if (deletedKeys.Contains(key))
            {
                return(null);
            }
            int hash  = HashCalculation.GetDoubleHash(values.Length, key, 0, A);
            int index = hash;

            for (int iter = 1; values[index] != null; iter++)
            {
                if (index == hash && iter != 1)
                {
                    break;
                }
                if (values[index].Key == key)
                {
                    return(values[index]);
                }
                index = HashCalculation.GetDoubleHash(values.Length, key, iter, A);
            }
            return(null);
        }
        private TableItem SearchItem(int key)
        {
            if (deletedKeys.Contains(key))
            {
                return(null);
            }
            int hash  = HashCalculation.GetHash(values.Length, key, A);
            int index = hash;

            while (values[index % values.Length] != null)
            {
                if ((index + 1) % values.Length == hash)
                {
                    break;
                }
                if (values[index % values.Length].Key == key)
                {
                    return(values[index % values.Length]);
                }
                index++;
            }
            return(null);
        }
        public bool Insert(int key, string value)
        {
            int hash  = HashCalculation.GetHash(values.Length, key, A);
            int index = hash;

            while (values[index % values.Length] != null)
            {
                if ((index + 1) % values.Length == hash)
                {
                    return(false);
                }
                if (values[index % values.Length].Key == key)
                {
                    return(false);
                }
                if (deletedKeys.Contains(values[index % values.Length].Key))
                {
                    break;
                }
                index++;
            }
            values[index] = new TableItem(key, value);
            return(true);
        }