Hashtable: skip rehashing if the size is the same

Hashtable_setSize should not rehash if the actual size stays the same as
the number of buckets and natural positions stay the same too.
main
Denis Lisov 4 years ago committed by cgzones
parent bc08c7dc2a
commit d084a80023
  1. 6
      Hashtable.c

@ -191,10 +191,14 @@ void Hashtable_setSize(Hashtable* this, size_t size) {
if (size <= this->items)
return;
size_t newSize = nextPrime(size);
if (newSize == this->size)
return;
HashtableItem* oldBuckets = this->buckets;
size_t oldSize = this->size;
this->size = nextPrime(size);
this->size = newSize;
this->buckets = (HashtableItem*) xCalloc(this->size, sizeof(HashtableItem));
this->items = 0;

Loading…
Cancel
Save