Removed const from HashTable_ForEach function

This commit is contained in:
Armin Novak 2021-05-18 09:06:10 +02:00 committed by akallabeth
parent 1e714df24e
commit 96eca171e2
3 changed files with 31 additions and 29 deletions

View File

@ -293,7 +293,7 @@ extern "C"
typedef struct _wHashTable wHashTable;
typedef BOOL (*HASH_TABLE_FOREACH_FN)(const void* key, const void* value, void* arg);
typedef BOOL (*HASH_TABLE_FOREACH_FN)(const void* key, void* value, void* arg);
WINPR_API size_t HashTable_Count(wHashTable* table);
WINPR_API BOOL HashTable_Insert(wHashTable* table, const void* key, const void* value);

View File

@ -698,32 +698,31 @@ BOOL HashTable_ContainsValue(wHashTable* table, const void* value)
wHashTable* HashTable_New(BOOL synchronized)
{
wHashTable* table;
table = (wHashTable*)calloc(1, sizeof(wHashTable));
wHashTable* table = (wHashTable*)calloc(1, sizeof(wHashTable));
if (table)
{
table->synchronized = synchronized;
InitializeCriticalSectionAndSpinCount(&(table->lock), 4000);
table->numOfBuckets = 64;
table->numOfElements = 0;
table->bucketArray = (wKeyValuePair**)calloc(table->numOfBuckets, sizeof(wKeyValuePair*));
if (!table)
goto fail;
if (!table->bucketArray)
{
free(table);
return NULL;
}
table->synchronized = synchronized;
InitializeCriticalSectionAndSpinCount(&(table->lock), 4000);
table->numOfBuckets = 64;
table->numOfElements = 0;
table->bucketArray = (wKeyValuePair**)calloc(table->numOfBuckets, sizeof(wKeyValuePair*));
table->idealRatio = 3.0;
table->lowerRehashThreshold = 0.0;
table->upperRehashThreshold = 15.0;
table->hash = HashTable_PointerHash;
table->key.fnObjectEquals = HashTable_PointerCompare;
table->value.fnObjectEquals = HashTable_PointerCompare;
}
if (!table->bucketArray)
goto fail;
table->idealRatio = 3.0;
table->lowerRehashThreshold = 0.0;
table->upperRehashThreshold = 15.0;
table->hash = HashTable_PointerHash;
table->key.fnObjectEquals = HashTable_PointerCompare;
table->value.fnObjectEquals = HashTable_PointerCompare;
return table;
fail:
HashTable_Free(table);
return NULL;
}
void HashTable_Free(wHashTable* table)
@ -732,7 +731,10 @@ void HashTable_Free(wHashTable* table)
wKeyValuePair* pair;
wKeyValuePair* nextPair;
if (table)
if (!table)
return;
if (table->bucketArray)
{
for (index = 0; index < table->numOfBuckets; index++)
{
@ -746,11 +748,11 @@ void HashTable_Free(wHashTable* table)
pair = nextPair;
}
}
DeleteCriticalSection(&(table->lock));
free(table->bucketArray);
free(table);
}
DeleteCriticalSection(&(table->lock));
free(table);
}
wObject* HashTable_KeyObject(wHashTable* table)

View File

@ -294,7 +294,7 @@ typedef struct
BOOL test3error;
} ForeachData;
BOOL foreachFn1(const void* key, const void* value, void* arg)
BOOL foreachFn1(const void* key, void* value, void* arg)
{
ForeachData* d = (ForeachData*)arg;
WINPR_UNUSED(key);
@ -302,7 +302,7 @@ BOOL foreachFn1(const void* key, const void* value, void* arg)
return TRUE;
}
BOOL foreachFn2(const void* key, const void* value, void* arg)
BOOL foreachFn2(const void* key, void* value, void* arg)
{
ForeachData* d = (ForeachData*)arg;
WINPR_UNUSED(key);
@ -314,7 +314,7 @@ BOOL foreachFn2(const void* key, const void* value, void* arg)
return TRUE;
}
BOOL foreachFn3(const void* key, const void* value, void* arg)
BOOL foreachFn3(const void* key, void* value, void* arg)
{
char* keyStr = (char*)key;