Beispiel #1
0
        public bool addToTable(Hashable theItem, Object theData)
        {
            int locationToUse;

            // call has function and ensure it is within range of table
            locationToUse = theItem.getHash() % tableSize;
            // now we do a probe, looking for next empty space
            while ((theTable[locationToUse].getKey() != null) &
                   !theTable[locationToUse].isDeleted())
            {
                locationToUse = (locationToUse + 1) % tableSize;
            }
            theTable[locationToUse] = new Entries(theItem, theData);
            return(true);
        }
Beispiel #2
0
        // find key by hashing then probing until key or an empty space is found
        private int findKey(Hashable theItem)
        {
            int locationToUse;

            // call has function and ensure it is within range of table
            locationToUse = theItem.getHash() % tableSize;
            // now we do a probe, looking for next empty space
            while (!(theTable[locationToUse].isDeleted()) &
                   (theTable[locationToUse].getKey() != null) &&
                   !(theTable[locationToUse].getKey().Equals(theItem)))
            {
                Console.WriteLine("moving on");
                locationToUse = (locationToUse + 1) % tableSize;
            }
            if ((theTable[locationToUse].getKey() != null) &&
                (theTable[locationToUse].getKey().Equals(theItem)))
            {
                return(locationToUse);
            }
            else
            {
                return(-1);
            }
        }