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); }
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 }
// 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); } }
public void setKey(Hashable aKey) { theKey = aKey; }
public Entries(Hashable aKey, Object someData) { theKey = aKey; theData = someData; }
public Entries() { theKey = null; theData = null; }