- if (newSize > ptrTable->capacity)
- {
- unsigned int i;
-
- PtrValueHashEntry* oldTable = ptrTable->table;
- FULLEMPTY* oldFlags = ptrTable->fullEmptyFlags;
- Index oldSize = ptrTable->size;
-
- /* allocate the new storage and flags and re-insert the old entries */
- InitializeTable(ptrTable, newSize);
- for (i=0; i < oldSize; ++i)
- Insert(ptrTable, oldTable[i].key, oldTable[i].value);
- assert(ptrTable->size == oldSize);
+ if (newSize <= ptrTable->capacity)
+ return;
+
+#ifndef NDEBUG
+ printf("\n***\n*** WARNING: REALLOCATING SPACE FOR POINTER HASH TABLE.\n");
+ printf("*** oldSize = %ld, oldCapacity = %ld\n***\n\n",
+ ptrTable->size, ptrTable->capacity);
+ printf("*** NEW SEQUENCE NUMBER FOR A POINTER WILL PROBABLY NOT MATCH ");
+ printf(" THE OLD ONE!\n***\n\n");
+#endif
+
+ unsigned int i;
+ PtrValueHashEntry* oldTable = ptrTable->table;
+ FULLEMPTY* oldFlags = ptrTable->fullEmptyFlags;
+ Index oldSize = ptrTable->size;
+ Index oldCapacity = ptrTable->capacity;
+
+ /* allocate the new storage and flags and re-insert the old entries */
+ InitializeTable(ptrTable, newSize);
+ memcpy(ptrTable->table, oldTable,
+ oldCapacity * sizeof(PtrValueHashEntry));
+ memcpy(ptrTable->fullEmptyFlags, oldFlags,
+ oldCapacity * sizeof(FULLEMPTY));
+ ptrTable->size = oldSize;
+
+#ifndef NDEBUG
+ for (i=0; i < oldCapacity; ++i) {
+ assert(ptrTable->fullEmptyFlags[i] == oldFlags[i]);
+ assert(ptrTable->table[i].key == oldTable[i].key);
+ assert(ptrTable->table[i].value == oldTable[i].value);
+ }
+#endif