Add iterators

This commit is contained in:
James Clark 1997-12-10 21:57:16 +00:00
parent 675ac10f75
commit ded70873bc
2 changed files with 24 additions and 0 deletions

View File

@ -87,3 +87,20 @@ void hashTableInit(HASH_TABLE *p)
p->used = 0;
p->v = 0;
}
void hashTableIterInit(HASH_TABLE_ITER *iter, const HASH_TABLE *table)
{
iter->p = table->v;
iter->end = iter->p + table->size;
}
NAMED *hashTableIterNext(HASH_TABLE_ITER *iter)
{
while (iter->p != iter->end) {
NAMED *tem = *(iter->p)++;
if (tem)
return tem;
}
return 0;
}

View File

@ -16,3 +16,10 @@ NAMED *lookup(HASH_TABLE *table, const char *name, size_t createSize);
void hashTableInit(HASH_TABLE *);
void hashTableDestroy(HASH_TABLE *);
typedef struct {
NAMED **p;
NAMED **end;
} HASH_TABLE_ITER;
void hashTableIterInit(HASH_TABLE_ITER *, const HASH_TABLE *);
NAMED *hashTableIterNext(HASH_TABLE_ITER *);