mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-31 19:12:32 +01:00
Change to the linux kernel coding style
for arq in `git ls-files *.c`; do
echo $arq;
indent -linux -l115 $arq;
done
The different line break at 115 columns is because
I use a widescreen monitor :-)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@@ -7,39 +6,30 @@
|
||||
|
||||
#include "WUtil.h"
|
||||
|
||||
|
||||
|
||||
|
||||
#define INITIAL_CAPACITY 23
|
||||
|
||||
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
# define INLINE inline
|
||||
#else
|
||||
# define INLINE
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct HashItem {
|
||||
const void *key;
|
||||
const void *data;
|
||||
const void *key;
|
||||
const void *data;
|
||||
|
||||
struct HashItem *next; /* collided item list */
|
||||
struct HashItem *next; /* collided item list */
|
||||
} HashItem;
|
||||
|
||||
|
||||
typedef struct W_HashTable {
|
||||
WMHashTableCallbacks callbacks;
|
||||
WMHashTableCallbacks callbacks;
|
||||
|
||||
unsigned itemCount;
|
||||
unsigned size; /* table size */
|
||||
unsigned itemCount;
|
||||
unsigned size; /* table size */
|
||||
|
||||
HashItem **table;
|
||||
HashItem **table;
|
||||
} HashTable;
|
||||
|
||||
|
||||
|
||||
|
||||
#define HASH(table, key) (((table)->callbacks.hash ? \
|
||||
(*(table)->callbacks.hash)(key) : hashPtr(key)) % (table)->size)
|
||||
|
||||
@@ -49,452 +39,400 @@ typedef struct W_HashTable {
|
||||
#define RELKEY(table, key) if ((table)->callbacks.releaseKey) \
|
||||
(*(table)->callbacks.releaseKey)(key)
|
||||
|
||||
|
||||
|
||||
|
||||
static INLINE unsigned
|
||||
hashString(const char *key)
|
||||
static INLINE unsigned hashString(const char *key)
|
||||
{
|
||||
unsigned ret = 0;
|
||||
unsigned ctr = 0;
|
||||
unsigned ret = 0;
|
||||
unsigned ctr = 0;
|
||||
|
||||
while (*key) {
|
||||
ret ^= *(char*)key++ << ctr;
|
||||
ctr = (ctr + 1) % sizeof (char *);
|
||||
}
|
||||
while (*key) {
|
||||
ret ^= *(char *)key++ << ctr;
|
||||
ctr = (ctr + 1) % sizeof(char *);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static INLINE unsigned
|
||||
hashPtr(const void *key)
|
||||
static INLINE unsigned hashPtr(const void *key)
|
||||
{
|
||||
return ((size_t)key / sizeof(char*));
|
||||
return ((size_t) key / sizeof(char *));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void
|
||||
rellocateItem(WMHashTable *table, HashItem *item)
|
||||
static void rellocateItem(WMHashTable * table, HashItem * item)
|
||||
{
|
||||
unsigned h;
|
||||
unsigned h;
|
||||
|
||||
h = HASH(table, item->key);
|
||||
h = HASH(table, item->key);
|
||||
|
||||
item->next = table->table[h];
|
||||
table->table[h] = item;
|
||||
item->next = table->table[h];
|
||||
table->table[h] = item;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
rebuildTable(WMHashTable *table)
|
||||
static void rebuildTable(WMHashTable * table)
|
||||
{
|
||||
HashItem *next;
|
||||
HashItem **oldArray;
|
||||
int i;
|
||||
int oldSize;
|
||||
int newSize;
|
||||
HashItem *next;
|
||||
HashItem **oldArray;
|
||||
int i;
|
||||
int oldSize;
|
||||
int newSize;
|
||||
|
||||
oldArray = table->table;
|
||||
oldSize = table->size;
|
||||
oldArray = table->table;
|
||||
oldSize = table->size;
|
||||
|
||||
newSize = table->size*2;
|
||||
newSize = table->size * 2;
|
||||
|
||||
table->table = wmalloc(sizeof(char*)*newSize);
|
||||
memset(table->table, 0, sizeof(char*)*newSize);
|
||||
table->size = newSize;
|
||||
table->table = wmalloc(sizeof(char *) * newSize);
|
||||
memset(table->table, 0, sizeof(char *) * newSize);
|
||||
table->size = newSize;
|
||||
|
||||
for (i = 0; i < oldSize; i++) {
|
||||
while (oldArray[i]!=NULL) {
|
||||
next = oldArray[i]->next;
|
||||
rellocateItem(table, oldArray[i]);
|
||||
oldArray[i] = next;
|
||||
}
|
||||
}
|
||||
wfree(oldArray);
|
||||
for (i = 0; i < oldSize; i++) {
|
||||
while (oldArray[i] != NULL) {
|
||||
next = oldArray[i]->next;
|
||||
rellocateItem(table, oldArray[i]);
|
||||
oldArray[i] = next;
|
||||
}
|
||||
}
|
||||
wfree(oldArray);
|
||||
}
|
||||
|
||||
|
||||
|
||||
WMHashTable*
|
||||
WMCreateHashTable(WMHashTableCallbacks callbacks)
|
||||
WMHashTable *WMCreateHashTable(WMHashTableCallbacks callbacks)
|
||||
{
|
||||
HashTable *table;
|
||||
HashTable *table;
|
||||
|
||||
table = wmalloc(sizeof(HashTable));
|
||||
memset(table, 0, sizeof(HashTable));
|
||||
table = wmalloc(sizeof(HashTable));
|
||||
memset(table, 0, sizeof(HashTable));
|
||||
|
||||
table->callbacks = callbacks;
|
||||
table->callbacks = callbacks;
|
||||
|
||||
table->size = INITIAL_CAPACITY;
|
||||
table->size = INITIAL_CAPACITY;
|
||||
|
||||
table->table = wmalloc(sizeof(HashItem*)*table->size);
|
||||
memset(table->table, 0, sizeof(HashItem*)*table->size);
|
||||
table->table = wmalloc(sizeof(HashItem *) * table->size);
|
||||
memset(table->table, 0, sizeof(HashItem *) * table->size);
|
||||
|
||||
return table;
|
||||
return table;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
WMResetHashTable(WMHashTable *table)
|
||||
void WMResetHashTable(WMHashTable * table)
|
||||
{
|
||||
HashItem *item, *tmp;
|
||||
int i;
|
||||
HashItem *item, *tmp;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < table->size; i++) {
|
||||
item = table->table[i];
|
||||
while (item) {
|
||||
tmp = item->next;
|
||||
RELKEY(table, item->key);
|
||||
wfree(item);
|
||||
item = tmp;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < table->size; i++) {
|
||||
item = table->table[i];
|
||||
while (item) {
|
||||
tmp = item->next;
|
||||
RELKEY(table, item->key);
|
||||
wfree(item);
|
||||
item = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
table->itemCount = 0;
|
||||
table->itemCount = 0;
|
||||
|
||||
if (table->size > INITIAL_CAPACITY) {
|
||||
wfree(table->table);
|
||||
table->size = INITIAL_CAPACITY;
|
||||
table->table = wmalloc(sizeof(HashItem*)*table->size);
|
||||
}
|
||||
memset(table->table, 0, sizeof(HashItem*)*table->size);
|
||||
if (table->size > INITIAL_CAPACITY) {
|
||||
wfree(table->table);
|
||||
table->size = INITIAL_CAPACITY;
|
||||
table->table = wmalloc(sizeof(HashItem *) * table->size);
|
||||
}
|
||||
memset(table->table, 0, sizeof(HashItem *) * table->size);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
WMFreeHashTable(WMHashTable *table)
|
||||
void WMFreeHashTable(WMHashTable * table)
|
||||
{
|
||||
HashItem *item, *tmp;
|
||||
int i;
|
||||
HashItem *item, *tmp;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < table->size; i++) {
|
||||
item = table->table[i];
|
||||
while (item) {
|
||||
tmp = item->next;
|
||||
RELKEY(table, item->key);
|
||||
wfree(item);
|
||||
item = tmp;
|
||||
}
|
||||
}
|
||||
wfree(table->table);
|
||||
wfree(table);
|
||||
for (i = 0; i < table->size; i++) {
|
||||
item = table->table[i];
|
||||
while (item) {
|
||||
tmp = item->next;
|
||||
RELKEY(table, item->key);
|
||||
wfree(item);
|
||||
item = tmp;
|
||||
}
|
||||
}
|
||||
wfree(table->table);
|
||||
wfree(table);
|
||||
}
|
||||
|
||||
|
||||
unsigned
|
||||
WMCountHashTable(WMHashTable *table)
|
||||
unsigned WMCountHashTable(WMHashTable * table)
|
||||
{
|
||||
return table->itemCount;
|
||||
return table->itemCount;
|
||||
}
|
||||
|
||||
|
||||
void*
|
||||
WMHashGet(WMHashTable *table, const void *key)
|
||||
void *WMHashGet(WMHashTable * table, const void *key)
|
||||
{
|
||||
unsigned h;
|
||||
HashItem *item;
|
||||
unsigned h;
|
||||
HashItem *item;
|
||||
|
||||
h = HASH(table, key);
|
||||
item = table->table[h];
|
||||
h = HASH(table, key);
|
||||
item = table->table[h];
|
||||
|
||||
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)
|
||||
return (void*)item->data;
|
||||
else
|
||||
return NULL;
|
||||
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)
|
||||
return (void *)item->data;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
unsigned h;
|
||||
HashItem *item;
|
||||
|
||||
h = HASH(table, key);
|
||||
item = table->table[h];
|
||||
h = HASH(table, key);
|
||||
item = table->table[h];
|
||||
|
||||
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;
|
||||
}
|
||||
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)
|
||||
void *WMHashInsert(WMHashTable * table, const void *key, const void *data)
|
||||
{
|
||||
unsigned h;
|
||||
HashItem *item;
|
||||
int replacing = 0;
|
||||
unsigned h;
|
||||
HashItem *item;
|
||||
int replacing = 0;
|
||||
|
||||
h = HASH(table, key);
|
||||
/* look for the entry */
|
||||
item = table->table[h];
|
||||
if (table->callbacks.keyIsEqual) {
|
||||
while (item) {
|
||||
if ((*table->callbacks.keyIsEqual)(key, item->key)) {
|
||||
replacing = 1;
|
||||
break;
|
||||
}
|
||||
item = item->next;
|
||||
}
|
||||
} else {
|
||||
while (item) {
|
||||
if (key == item->key) {
|
||||
replacing = 1;
|
||||
break;
|
||||
}
|
||||
item = item->next;
|
||||
}
|
||||
}
|
||||
h = HASH(table, key);
|
||||
/* look for the entry */
|
||||
item = table->table[h];
|
||||
if (table->callbacks.keyIsEqual) {
|
||||
while (item) {
|
||||
if ((*table->callbacks.keyIsEqual) (key, item->key)) {
|
||||
replacing = 1;
|
||||
break;
|
||||
}
|
||||
item = item->next;
|
||||
}
|
||||
} else {
|
||||
while (item) {
|
||||
if (key == item->key) {
|
||||
replacing = 1;
|
||||
break;
|
||||
}
|
||||
item = item->next;
|
||||
}
|
||||
}
|
||||
|
||||
if (replacing) {
|
||||
const void *old;
|
||||
if (replacing) {
|
||||
const void *old;
|
||||
|
||||
old = item->data;
|
||||
item->data = data;
|
||||
RELKEY(table, item->key);
|
||||
item->key = DUPKEY(table, key);
|
||||
old = item->data;
|
||||
item->data = data;
|
||||
RELKEY(table, item->key);
|
||||
item->key = DUPKEY(table, key);
|
||||
|
||||
return (void*)old;
|
||||
} else {
|
||||
HashItem *nitem;
|
||||
return (void *)old;
|
||||
} else {
|
||||
HashItem *nitem;
|
||||
|
||||
nitem = wmalloc(sizeof(HashItem));
|
||||
nitem->key = DUPKEY(table, key);
|
||||
nitem->data = data;
|
||||
nitem->next = table->table[h];
|
||||
table->table[h] = nitem;
|
||||
nitem = wmalloc(sizeof(HashItem));
|
||||
nitem->key = DUPKEY(table, key);
|
||||
nitem->data = data;
|
||||
nitem->next = table->table[h];
|
||||
table->table[h] = nitem;
|
||||
|
||||
table->itemCount++;
|
||||
}
|
||||
table->itemCount++;
|
||||
}
|
||||
|
||||
/* OPTIMIZE: put this in an idle handler.*/
|
||||
if (table->itemCount > table->size) {
|
||||
/* OPTIMIZE: put this in an idle handler. */
|
||||
if (table->itemCount > table->size) {
|
||||
#ifdef DEBUG0
|
||||
printf("rebuilding hash table...\n");
|
||||
printf("rebuilding hash table...\n");
|
||||
#endif
|
||||
rebuildTable(table);
|
||||
rebuildTable(table);
|
||||
#ifdef DEBUG0
|
||||
printf("finished rebuild.\n");
|
||||
printf("finished rebuild.\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static HashItem*
|
||||
deleteFromList(HashTable *table, HashItem *item, const void *key)
|
||||
static HashItem *deleteFromList(HashTable * table, HashItem * item, const void *key)
|
||||
{
|
||||
HashItem *next;
|
||||
HashItem *next;
|
||||
|
||||
if (item==NULL)
|
||||
return NULL;
|
||||
if (item == NULL)
|
||||
return NULL;
|
||||
|
||||
if ((table->callbacks.keyIsEqual
|
||||
&& (*table->callbacks.keyIsEqual)(key, item->key))
|
||||
|| (!table->callbacks.keyIsEqual && key==item->key)) {
|
||||
if ((table->callbacks.keyIsEqual && (*table->callbacks.keyIsEqual) (key, item->key))
|
||||
|| (!table->callbacks.keyIsEqual && key == item->key)) {
|
||||
|
||||
next = item->next;
|
||||
RELKEY(table, item->key);
|
||||
wfree(item);
|
||||
next = item->next;
|
||||
RELKEY(table, item->key);
|
||||
wfree(item);
|
||||
|
||||
table->itemCount--;
|
||||
table->itemCount--;
|
||||
|
||||
return next;
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
item->next = deleteFromList(table, item->next, key);
|
||||
item->next = deleteFromList(table, item->next, key);
|
||||
|
||||
return item;
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
WMHashRemove(WMHashTable *table, const void *key)
|
||||
void WMHashRemove(WMHashTable * table, const void *key)
|
||||
{
|
||||
unsigned h;
|
||||
unsigned h;
|
||||
|
||||
h = HASH(table, key);
|
||||
h = HASH(table, key);
|
||||
|
||||
table->table[h] = deleteFromList(table, table->table[h], key);
|
||||
table->table[h] = deleteFromList(table, table->table[h], key);
|
||||
}
|
||||
|
||||
|
||||
WMHashEnumerator
|
||||
WMEnumerateHashTable(WMHashTable *table)
|
||||
WMHashEnumerator WMEnumerateHashTable(WMHashTable * table)
|
||||
{
|
||||
WMHashEnumerator enumerator;
|
||||
WMHashEnumerator enumerator;
|
||||
|
||||
enumerator.table = table;
|
||||
enumerator.index = 0;
|
||||
enumerator.nextItem = table->table[0];
|
||||
enumerator.table = table;
|
||||
enumerator.index = 0;
|
||||
enumerator.nextItem = table->table[0];
|
||||
|
||||
return enumerator;
|
||||
return enumerator;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void*
|
||||
WMNextHashEnumeratorItem(WMHashEnumerator *enumerator)
|
||||
void *WMNextHashEnumeratorItem(WMHashEnumerator * enumerator)
|
||||
{
|
||||
const void *data = NULL;
|
||||
const void *data = NULL;
|
||||
|
||||
/* this assumes the table doesn't change between
|
||||
* WMEnumerateHashTable() and WMNextHashEnumeratorItem() calls */
|
||||
/* this assumes the table doesn't change between
|
||||
* WMEnumerateHashTable() and WMNextHashEnumeratorItem() calls */
|
||||
|
||||
if (enumerator->nextItem==NULL) {
|
||||
HashTable *table = enumerator->table;
|
||||
while (++enumerator->index < table->size) {
|
||||
if (table->table[enumerator->index]!=NULL) {
|
||||
enumerator->nextItem = table->table[enumerator->index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (enumerator->nextItem == NULL) {
|
||||
HashTable *table = enumerator->table;
|
||||
while (++enumerator->index < table->size) {
|
||||
if (table->table[enumerator->index] != NULL) {
|
||||
enumerator->nextItem = table->table[enumerator->index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (enumerator->nextItem) {
|
||||
data = ((HashItem*)enumerator->nextItem)->data;
|
||||
enumerator->nextItem = ((HashItem*)enumerator->nextItem)->next;
|
||||
}
|
||||
if (enumerator->nextItem) {
|
||||
data = ((HashItem *) enumerator->nextItem)->data;
|
||||
enumerator->nextItem = ((HashItem *) enumerator->nextItem)->next;
|
||||
}
|
||||
|
||||
return (void*)data;
|
||||
return (void *)data;
|
||||
}
|
||||
|
||||
|
||||
void*
|
||||
WMNextHashEnumeratorKey(WMHashEnumerator *enumerator)
|
||||
void *WMNextHashEnumeratorKey(WMHashEnumerator * enumerator)
|
||||
{
|
||||
const void *key = NULL;
|
||||
const void *key = NULL;
|
||||
|
||||
/* this assumes the table doesn't change between
|
||||
* WMEnumerateHashTable() and WMNextHashEnumeratorKey() calls */
|
||||
/* this assumes the table doesn't change between
|
||||
* WMEnumerateHashTable() and WMNextHashEnumeratorKey() calls */
|
||||
|
||||
if (enumerator->nextItem==NULL) {
|
||||
HashTable *table = enumerator->table;
|
||||
while (++enumerator->index < table->size) {
|
||||
if (table->table[enumerator->index]!=NULL) {
|
||||
enumerator->nextItem = table->table[enumerator->index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (enumerator->nextItem == NULL) {
|
||||
HashTable *table = enumerator->table;
|
||||
while (++enumerator->index < table->size) {
|
||||
if (table->table[enumerator->index] != NULL) {
|
||||
enumerator->nextItem = table->table[enumerator->index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (enumerator->nextItem) {
|
||||
key = ((HashItem*)enumerator->nextItem)->key;
|
||||
enumerator->nextItem = ((HashItem*)enumerator->nextItem)->next;
|
||||
}
|
||||
if (enumerator->nextItem) {
|
||||
key = ((HashItem *) enumerator->nextItem)->key;
|
||||
enumerator->nextItem = ((HashItem *) enumerator->nextItem)->next;
|
||||
}
|
||||
|
||||
return (void*)key;
|
||||
return (void *)key;
|
||||
}
|
||||
|
||||
|
||||
Bool
|
||||
WMNextHashEnumeratorItemAndKey(WMHashEnumerator *enumerator,
|
||||
void **item, void **key)
|
||||
Bool WMNextHashEnumeratorItemAndKey(WMHashEnumerator * enumerator, void **item, void **key)
|
||||
{
|
||||
/* this assumes the table doesn't change between
|
||||
* WMEnumerateHashTable() and WMNextHashEnumeratorItemAndKey() calls */
|
||||
/* this assumes the table doesn't change between
|
||||
* WMEnumerateHashTable() and WMNextHashEnumeratorItemAndKey() calls */
|
||||
|
||||
if (enumerator->nextItem==NULL) {
|
||||
HashTable *table = enumerator->table;
|
||||
while (++enumerator->index < table->size) {
|
||||
if (table->table[enumerator->index]!=NULL) {
|
||||
enumerator->nextItem = table->table[enumerator->index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (enumerator->nextItem == NULL) {
|
||||
HashTable *table = enumerator->table;
|
||||
while (++enumerator->index < table->size) {
|
||||
if (table->table[enumerator->index] != NULL) {
|
||||
enumerator->nextItem = table->table[enumerator->index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (enumerator->nextItem) {
|
||||
if (item)
|
||||
*item = (void*)((HashItem*)enumerator->nextItem)->data;
|
||||
if (key)
|
||||
*key = (void*)((HashItem*)enumerator->nextItem)->key;
|
||||
enumerator->nextItem = ((HashItem*)enumerator->nextItem)->next;
|
||||
if (enumerator->nextItem) {
|
||||
if (item)
|
||||
*item = (void *)((HashItem *) enumerator->nextItem)->data;
|
||||
if (key)
|
||||
*key = (void *)((HashItem *) enumerator->nextItem)->key;
|
||||
enumerator->nextItem = ((HashItem *) enumerator->nextItem)->next;
|
||||
|
||||
return True;
|
||||
}
|
||||
return True;
|
||||
}
|
||||
|
||||
return False;
|
||||
return False;
|
||||
}
|
||||
|
||||
|
||||
static Bool
|
||||
compareStrings(const char *key1, const char *key2)
|
||||
static Bool compareStrings(const char *key1, const char *key2)
|
||||
{
|
||||
return strcmp(key1, key2)==0;
|
||||
return strcmp(key1, key2) == 0;
|
||||
}
|
||||
|
||||
|
||||
typedef unsigned (*hashFunc)(const void*);
|
||||
typedef Bool (*isEqualFunc)(const void*, const void*);
|
||||
typedef void* (*retainFunc)(const void*);
|
||||
typedef void (*releaseFunc)(const void*);
|
||||
|
||||
typedef unsigned (*hashFunc) (const void *);
|
||||
typedef Bool(*isEqualFunc) (const void *, const void *);
|
||||
typedef void *(*retainFunc) (const void *);
|
||||
typedef void (*releaseFunc) (const void *);
|
||||
|
||||
const WMHashTableCallbacks WMIntHashCallbacks = {
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
const WMHashTableCallbacks WMStringHashCallbacks = {
|
||||
(hashFunc)hashString,
|
||||
(isEqualFunc)compareStrings,
|
||||
(retainFunc)wstrdup,
|
||||
(releaseFunc)wfree
|
||||
(hashFunc) hashString,
|
||||
(isEqualFunc) compareStrings,
|
||||
(retainFunc) wstrdup,
|
||||
(releaseFunc) wfree
|
||||
};
|
||||
|
||||
|
||||
|
||||
const WMHashTableCallbacks WMStringPointerHashCallbacks = {
|
||||
(hashFunc)hashString,
|
||||
(isEqualFunc)compareStrings,
|
||||
NULL,
|
||||
NULL
|
||||
(hashFunc) hashString,
|
||||
(isEqualFunc) compareStrings,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user