mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 12:28:22 +01:00
WINGs: merge hashtable duplicate code
This patch is adding a new static function hashGetItem to factorize some code. Signed-off-by: Carlos R. Mafra <crmafra@gmail.com>
This commit is contained in:
committed by
Carlos R. Mafra
parent
118beb2c60
commit
2a3c11e202
@@ -154,7 +154,7 @@ unsigned WMCountHashTable(WMHashTable * table)
|
|||||||
return table->itemCount;
|
return table->itemCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *WMHashGet(WMHashTable * table, const void *key)
|
static HashItem *hashGetItem(WMHashTable *table, const void *key)
|
||||||
{
|
{
|
||||||
unsigned h;
|
unsigned h;
|
||||||
HashItem *item;
|
HashItem *item;
|
||||||
@@ -177,44 +177,32 @@ void *WMHashGet(WMHashTable * table, const void *key)
|
|||||||
item = item->next;
|
item = item->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item)
|
return item;
|
||||||
return (void *)item->data;
|
}
|
||||||
else
|
|
||||||
|
void *WMHashGet(WMHashTable * table, const void *key)
|
||||||
|
{
|
||||||
|
HashItem *item;
|
||||||
|
|
||||||
|
item = hashGetItem(table, key);
|
||||||
|
if (!item)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
return (void *)item->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bool WMHashGetItemAndKey(WMHashTable * table, const void *key, void **retItem, void **retKey)
|
Bool WMHashGetItemAndKey(WMHashTable * table, const void *key, void **retItem, void **retKey)
|
||||||
{
|
{
|
||||||
unsigned h;
|
|
||||||
HashItem *item;
|
HashItem *item;
|
||||||
|
|
||||||
h = HASH(table, key);
|
item = hashGetItem(table, key);
|
||||||
item = table->table[h];
|
if (!item)
|
||||||
|
|
||||||
if (table->callbacks.keyIsEqual) {
|
|
||||||
while (item) {
|
|
||||||
if ((*table->callbacks.keyIsEqual) (key, item->key)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
item = item->next;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
while (item) {
|
|
||||||
if (key == item->key) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
item = item->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (item) {
|
|
||||||
if (retKey)
|
|
||||||
*retKey = (void *)item->key;
|
|
||||||
if (retItem)
|
|
||||||
*retItem = (void *)item->data;
|
|
||||||
return True;
|
|
||||||
} else {
|
|
||||||
return False;
|
return False;
|
||||||
}
|
|
||||||
|
if (retKey)
|
||||||
|
*retKey = (void *)item->key;
|
||||||
|
if (retItem)
|
||||||
|
*retItem = (void *)item->data;
|
||||||
|
return True;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *WMHashInsert(WMHashTable * table, const void *key, const void *data)
|
void *WMHashInsert(WMHashTable * table, const void *key, const void *data)
|
||||||
|
|||||||
Reference in New Issue
Block a user