Open
Description
I think improvement is needed in the bucketInsertEntry () method, because by going through this situation according to the bucket value being null in 152 rows, the same condition may appear as return null in the bucketSeekEntry method, accordingly we understand that there is no addition in that index according to the bucketIndex-given in the condition of correctness of the condition in 152 rows. Therefore, I think there is no need for additional checking, so it should not be logged into the bucketSeekEntry () method, we can do such a refactoring by considering these (I sampled the change over your codes):
private V bucketInsertEntry (int bucketIndex, Entry <K, V> entry) {
LinkedList <Entry <K, V >> bucket = table [bucketIndex];
if (bucket == null) {
table [bucketIndex] = bucket = new LinkedList<>();
bucket.add (entry);
if (++ size> threshold) resizeTable ();
return null; // Use null to indicate that there was no previous entry
}
Entry <K, V> existentEntry = bucketSeekEntry (bucketIndex, entry.key);
if (!existentEntry == null) {
V oldVal = existentEntry.value;
existentEntry.value = entry.value;
return oldVal;
}
return null;
}
Metadata
Assignees
Labels
No labels
Activity