mirror of
https://github.com/UberGames/rpgxEF.git
synced 2024-11-10 07:11:34 +00:00
Added list_at function
This commit is contained in:
parent
3ffe39bf3a
commit
6d73a796ca
2 changed files with 28 additions and 0 deletions
|
@ -337,3 +337,22 @@ void list_init(struct list * l, void (*destructor)(void*)) {
|
||||||
l->destructor = destructor;
|
l->destructor = destructor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
container_p list_at(list_p list, int idx) {
|
||||||
|
list_iter_p iter;
|
||||||
|
container_p c = NULL;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if(idx < 0 || idx >= list->length || list == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
iter = list_iterator(list, LIST_FRONT);
|
||||||
|
for(c = list_next(iter), i = 0; c != NULL; c = list_next(iter), i++) {
|
||||||
|
if(i == idx) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -324,4 +324,13 @@ void list_clear(list_p list);
|
||||||
*/
|
*/
|
||||||
void list_init(struct list * l, void (*destructor)(void*));
|
void list_init(struct list * l, void (*destructor)(void*));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the element at the given index.
|
||||||
|
*
|
||||||
|
* \param list a list
|
||||||
|
* \param idx index
|
||||||
|
* \return element at given index or NULL if index is out of bounds
|
||||||
|
*/
|
||||||
|
container_p list_at(list_p list, int idx);
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in a new issue