#221 closed defect (fixed)
psListGet/psListAdd/psListRemove maybe should just use psListIterator instead of location
| Reported by: | Owned by: | Paul Price | |
|---|---|---|---|
| Priority: | high | Milestone: | |
| Component: | PSLib SDRS | Version: | unspecified |
| Severity: | normal | Keywords: | |
| Cc: |
Description
It is fairly inefficient to index into a list by number, so I was wondering if
it wouldn't be better to write functions like psListGet, etc., to only use
iterators and make the 'head' and 'tail' attributes of psList simply
psListIterators as well. Here is what I'm proposing:
typedef struct {
psU32 size;
const psListIterator* head;
const psListIterator* tail;
psArray* iterators;
pthread_mutex_t lock;
} psList;
void* psListGet(const psListIterator* iter);
bool psListRemove(const psListIterator* iter);
To add an item to the front of the list, do:
psListAddBefore(list->head,di);
or on the at the end:
psListAddAfter(list->tail,di);
To get the head data item:
di = psListGet(list->head);
To get the fourth item, a user would need to make their own psListIterator, but
given that it is not very efficient to repeatedly index into the list by number,
as would likely be the tendency of the user to do, this is probably a much more
preferable option.
iter = psListIteratorAlloc(list,4);
di = psListGet(iter);
Of course, functions that change the psListIterator, like psGetNext, would
protect the head and tail iterators.
-rdd

It's true that it is inefficient to have to count through the list, but if the
user wants a value from the list given the position, then it is necessary (in
the example you give, it would be performed by psListIteratorAlloc). I think we
should keep the current specification, since it is more user friendly.