Add function to access element by index.

This commit is contained in:
Danila Fedorin 2016-12-20 23:28:07 -08:00
parent c4ee4853d5
commit 37adcb1365
2 changed files with 11 additions and 0 deletions

View File

@ -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

View File

@ -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;
}