static void _parcHashMap_Resize(PARCHashMap *hashMap, size_t newCapacity) { if (newCapacity < hashMap->minCapacity) { return; } PARCLinkedList **newBuckets = parcMemory_AllocateAndClear(newCapacity * sizeof(PARCLinkedList*)); for (unsigned int i = 0; i < hashMap->capacity; i++) { if (hashMap->buckets[i] != NULL) { if (!parcLinkedList_IsEmpty(hashMap->buckets[i])) { PARCIterator *elementIt = parcLinkedList_CreateIterator(hashMap->buckets[i]); while (parcIterator_HasNext(elementIt)) { _PARCHashMapEntry *entry = parcIterator_Next(elementIt); PARCHashCode keyHash = parcObject_HashCode(entry->key); int newBucket = keyHash % newCapacity; if (newBuckets[newBucket] == NULL) { newBuckets[newBucket] = parcLinkedList_Create(); } parcLinkedList_Append(newBuckets[newBucket], entry); } parcIterator_Release(&elementIt); } parcLinkedList_Release(&hashMap->buckets[i]); } } PARCLinkedList **cleanupBuckets = hashMap->buckets; hashMap->buckets = newBuckets; hashMap->capacity = newCapacity; parcMemory_Deallocate(&cleanupBuckets); }
static void _parcSortedList_Finalize(PARCSortedList **instancePtr) { assertNotNull(instancePtr, "Parameter must be a non-null pointer to a PARCSortedList pointer."); PARCSortedList *instance = *instancePtr; parcSortedList_OptionalAssertValid(instance); parcLinkedList_Release(&instance->list); }
static bool _ccnxManifestHashGroup_Destructor(CCNxManifestHashGroup **groupP) { if ((*groupP)->pointers != NULL) { parcLinkedList_Release(&(*groupP)->pointers); } if ((*groupP)->overallDataDigest != NULL) { parcBuffer_Release((PARCBuffer **) &(*groupP)->overallDataDigest); } if ((*groupP)->locator != NULL) { ccnxName_Release((CCNxName **) &(*groupP)->locator); } return true; }
static void _parcHashMap_Finalize(PARCHashMap **instancePtr) { assertNotNull(instancePtr, "Parameter must be a non-null pointer to a PARCHashMap pointer."); PARCHashMap *hashMap = *instancePtr; for (unsigned int i = 0; i < hashMap->capacity; i++) { if (hashMap->buckets[i] != NULL) { parcLinkedList_Release(&hashMap->buckets[i]); } } parcMemory_Deallocate(&hashMap->buckets); /* cleanup the instance fields here */ }
static void _stressTestNext(PARCSecureRandom *rng) { PARCLinkedList *seen = parcLinkedList_Create(); size_t duplicates = 0; for (size_t i = 0; i < NUM_TESTS; i++) { uint32_t next = parcSecureRandom_Next(rng); PARCBuffer *buffer = parcBuffer_Allocate(sizeof(next)); parcBuffer_Flip(parcBuffer_PutUint32(buffer, next)); if (parcLinkedList_Contains(seen, buffer)) { duplicates++; } else { parcLinkedList_Append(seen, buffer); } parcBuffer_Release(&buffer); } assertFalse(duplicates > (NUM_TESTS * EPSILON), "The RNG failed to generate random values: saw %zu duplicates", duplicates); parcLinkedList_Release(&seen); }
static void _stressTestNextBytes(PARCSecureRandom *rng) { PARCLinkedList *seen = parcLinkedList_Create(); size_t duplicates = 0; for (size_t i = 0; i < NUM_TESTS; i++) { PARCBuffer *buffer = parcBuffer_Allocate(32); int numBytes = parcSecureRandom_NextBytes(rng, buffer); assertTrue(numBytes == 32, "Expected 32 bytes from the RNG, got %d", numBytes); if (parcLinkedList_Contains(seen, buffer)) { duplicates++; } else { parcLinkedList_Append(seen, buffer); } parcBuffer_Release(&buffer); } assertFalse(duplicates > (NUM_TESTS * EPSILON), "The RNG failed to generate random values: saw %zu duplicates", duplicates); parcLinkedList_Release(&seen); }