Fixed bugs to Dictionary Classes

This commit is contained in:
2014-05-17 23:17:11 +02:00
parent 4dab60c3fa
commit f1e6f18939
6 changed files with 96 additions and 39 deletions

View File

@@ -122,6 +122,22 @@ public class ChainingHashTable<K,V> implements Dictionary<K,V> {
}
}
protected Entry<K, V> insert_refactor(Entry<K,V> in_e) throws InvalidKeyException {
// in_e not checked because used internally
int h = hash(in_e.getKey());
if (table.get(h) == AVAIBLE) {
LogFile<K, V> n = new LogFile<K, V>();
table.set(h,n);
avaible_slots--;
elements++;
return n.insert(in_e);
} else {
LogFile<K, V> n = table.get(h);
elements++;
return n.insert(in_e);
}
}
@Override
public Entry<K, V> remove(Entry<K, V> e) throws InvalidEntryException {
if (e == null)
@@ -180,7 +196,7 @@ public class ChainingHashTable<K,V> implements Dictionary<K,V> {
table = table2;
for (Entry<K,V> e : ite){
insert(e.getKey(),e.getValue());
insert_refactor(e);
}
}