Пример #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);
        }
Пример #2
0
        public Object removeFromTable(Hashable theItem)
        {
            int    locationToUse = findKey(theItem);
            Object temp;

            if (locationToUse == -1) // could not find key
            {
                return((Object)null);
            }
            else
            {
                temp = theTable[locationToUse].getData();
                theTable[locationToUse].setDeleted(true);
                theTable[locationToUse].setKey(null);
                theTable[locationToUse].setData(null);
                return(temp);
            }

            // now we do a probe, looking for key
        }
Пример #3
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);
            }
        }
Пример #4
0
 public void setKey(Hashable aKey)
 {
     theKey = aKey;
 }
Пример #5
0
 public Entries(Hashable aKey, Object someData)
 {
     theKey  = aKey;
     theData = someData;
 }
Пример #6
0
 public Entries()
 {
     theKey  = null;
     theData = null;
 }