mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-18 20:10:29 +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;
|
||||
}
|
||||
|
||||
void *WMHashGet(WMHashTable * table, const void *key)
|
||||
static HashItem *hashGetItem(WMHashTable *table, const void *key)
|
||||
{
|
||||
unsigned h;
|
||||
HashItem *item;
|
||||
@@ -177,44 +177,32 @@ void *WMHashGet(WMHashTable * table, const void *key)
|
||||
item = item->next;
|
||||
}
|
||||
}
|
||||
if (item)
|
||||
return (void *)item->data;
|
||||
else
|
||||
return item;
|
||||
}
|
||||
|
||||
void *WMHashGet(WMHashTable * table, const void *key)
|
||||
{
|
||||
HashItem *item;
|
||||
|
||||
item = hashGetItem(table, key);
|
||||
if (!item)
|
||||
return NULL;
|
||||
return (void *)item->data;
|
||||
}
|
||||
|
||||
Bool WMHashGetItemAndKey(WMHashTable * table, const void *key, void **retItem, void **retKey)
|
||||
{
|
||||
unsigned h;
|
||||
HashItem *item;
|
||||
|
||||
h = HASH(table, key);
|
||||
item = table->table[h];
|
||||
item = hashGetItem(table, key);
|
||||
if (!item)
|
||||
return False;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void *WMHashInsert(WMHashTable * table, const void *key, const void *data)
|
||||
|
||||
Reference in New Issue
Block a user