Add function to access element by index.
This commit is contained in:
parent
c4ee4853d5
commit
37adcb1365
|
@ -22,4 +22,6 @@ void vec_remove(vec*, void*);
|
|||
void* vec_find(vec*, void*, compare_func);
|
||||
int vec_foreach(vec*, void*, compare_func, foreach_func, ...);
|
||||
|
||||
void* vec_index(vec*, int);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -103,3 +103,12 @@ int vec_foreach(vec* v, void* data, compare_func compare, foreach_func foreach,
|
|||
}
|
||||
return return_code;
|
||||
}
|
||||
|
||||
void* vec_index(vec* v, int index){
|
||||
void* to_return = NULL;
|
||||
if(index < v->capacity && index >= 0) {
|
||||
void** data_array = v->data;
|
||||
to_return = data_array[index];
|
||||
}
|
||||
return to_return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user