I am trying to re-size a hash table
. I find that my logic is correct, but the code is all wrong. I know that when adding elements into a hash table you must consider the load factor
, if the load factor
is exceeded, the capacity doubles.
Example. Size = 3, Capacity = 5
.
Load Factor = 5 * 0.75 = 3.75
If we add an element Size = 4
, which exceeds the load factor
, thus Capacity = 10
.
However, I am return the original Capacity
.
/**
* size if load >.75 or < .5
*/
private void resize(int newCap)
{
//
double capacity = buckets.length * 0.75;
//System.out.println(capacity);
if (currentSize > capacity) {
int C = buckets.length * 2;
newCap = C
//System.out.println(C);
}
}
/**
* Gets the length of the array backing this HashSet
* @return the length of the array backing this HashSet
*/
public int getCap()
{
//
int capac = buckets.cap
resize(capac);
return capac;
}