Add iterators
This commit is contained in:
parent
675ac10f75
commit
ded70873bc
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 *);
|
||||
|
Loading…
Reference in New Issue
Block a user