pHashTable->numEntries = pHashTable->numDeadEntries = 0;
pHashTable->freeFunc = freeFunc;
pHashTable->pEntries =
- (HashEntry*) malloc(pHashTable->tableSize * sizeof(HashEntry));
+ (HashEntry*) calloc(pHashTable->tableSize, sizeof(HashEntry));
if (pHashTable->pEntries == NULL) {
free(pHashTable);
return NULL;
}
- memset(pHashTable->pEntries, 0, pHashTable->tableSize * sizeof(HashEntry));
return pHashTable;
}
int i;
assert(countTombStones(pHashTable) == pHashTable->numDeadEntries);
- //LOGI("before: dead=%d", pHashTable->numDeadEntries);
+ //ALOGI("before: dead=%d", pHashTable->numDeadEntries);
pNewEntries = (HashEntry*) calloc(newSize, sizeof(HashEntry));
if (pNewEntries == NULL)
pEntry = pHashTable->pEntries;
}
- //LOGI("+++ look probing %d...", pEntry - pHashTable->pEntries);
+ //ALOGI("+++ look probing %d...", pEntry - pHashTable->pEntries);
}
if (pEntry->data == NULL) {
{
if (!resizeHash(pHashTable, pHashTable->tableSize * 2)) {
/* don't really have a way to indicate failure */
- LOGE("Dalvik hash resize failure");
+ ALOGE("Dalvik hash resize failure");
dvmAbort();
}
/* note "pEntry" is now invalid */
} else {
- //LOGW("okay %d/%d/%d",
+ //ALOGW("okay %d/%d/%d",
// pHashTable->numEntries, pHashTable->tableSize,
// (pHashTable->tableSize * LOAD_NUMER) / LOAD_DENOM);
}
pEnd = &pHashTable->pEntries[pHashTable->tableSize];
while (pEntry->data != NULL) {
if (pEntry->data == item) {
- //LOGI("+++ stepping on entry %d", pEntry - pHashTable->pEntries);
+ //ALOGI("+++ stepping on entry %d", pEntry - pHashTable->pEntries);
pEntry->data = HASH_TOMBSTONE;
pHashTable->numEntries--;
pHashTable->numDeadEntries++;
pEntry = pHashTable->pEntries;
}
- //LOGI("+++ del probing %d...", pEntry - pHashTable->pEntries);
+ //ALOGI("+++ del probing %d...", pEntry - pHashTable->pEntries);
}
return false;
*/
int dvmHashForeachRemove(HashTable* pHashTable, HashForeachRemoveFunc func)
{
- int i, val;
+ int i, val, tableSize;
- for (i = 0; i < pHashTable->tableSize; i++) {
+ tableSize = pHashTable->tableSize;
+
+ for (i = 0; i < tableSize; i++) {
HashEntry* pEnt = &pHashTable->pEntries[i];
if (pEnt->data != NULL && pEnt->data != HASH_TOMBSTONE) {
*/
int dvmHashForeach(HashTable* pHashTable, HashForeachFunc func, void* arg)
{
- int i, val;
+ int i, val, tableSize;
- for (i = 0; i < pHashTable->tableSize; i++) {
+ tableSize = pHashTable->tableSize;
+
+ for (i = 0; i < tableSize; i++) {
HashEntry* pEnt = &pHashTable->pEntries[i];
if (pEnt->data != NULL && pEnt->data != HASH_TOMBSTONE) {
totalProbe += count;
}
- LOGI("Probe: min=%d max=%d, total=%d in %d (%d), avg=%.3f",
+ ALOGI("Probe: min=%d max=%d, total=%d in %d (%d), avg=%.3f",
minProbe, maxProbe, totalProbe, numEntries, pHashTable->tableSize,
(float) totalProbe / (float) numEntries);
}