public void Put(int key, int value) { int hash = (key % TABLE_SIZE); if (table[hash] == null) { table[hash] = new LinkedHashEntry(key, value); } else { LinkedHashEntry entry = table[hash]; while (entry.GetNext() != null && entry.GetKey() != key) { entry = entry.GetNext(); } if (entry.GetKey() == key) { entry.SetValue(value); } else { entry.SetNext(new LinkedHashEntry(key, value)); } } }
public void Remove(int key) { int hash = (key % TABLE_SIZE); if (table[hash] != null) { LinkedHashEntry prevEntry = null; LinkedHashEntry entry = table[hash]; while (entry.GetNext() != null && entry.GetKey() != key) { prevEntry = entry; entry = entry.GetNext(); } if (entry.GetKey() == key) { if (prevEntry == null) { table[hash] = entry.GetNext(); } else { prevEntry.SetNext(entry.GetNext()); } } } }