I created a HashMap to store entries. Now when there is a collision of hashcodes, how can I resize the buckets. Right now I just have the buckets set to an arbitrary prime number and I can't figure out how to make the buckets resize themselves if buckets reach capacity.
public class BucketList<K, V> extends LinkedList<Bucket<K, V>> {
private final int NUM_BUCKETS = 997; //Arbitrary prime number
public BucketList() {
initializeBuckets();
}
public void add(int index, BucketEntry<K, V> entry) {
Bucket<K, V> bucket = get(index);
if (bucket == null){
set(index, new Bucket<>(entry));
} else {
BucketEntry<K, V> current = bucket.findEntry(entry.getKey());
if (current != null) {
current.setValue(entry.getValue());
} else
{
bucket.add(entry);
}
}
}
private void initializeBuckets() {
for (int i = 0; i < NUM_BUCKETS; i++) {
add(null);
}
}
}