Add new function for vector (future proof)

This commit is contained in:
topjohnwu 2017-05-26 22:59:17 +08:00
parent bdc83da098
commit 69cfde4516
2 changed files with 7 additions and 0 deletions

View File

@ -23,6 +23,12 @@ void vec_push_back(struct vector *v, void *p) {
++vec_size(v);
}
void *vec_pop_back(struct vector *v) {
void *ret = vec_entry(v)[vec_size(v) - 1];
--vec_size(v);
return ret;
}
void vec_sort(struct vector *v, int (*compar)(const void *, const void *)) {
if (v == NULL) return;
qsort(vec_entry(v), vec_size(v), sizeof(void*), compar);

View File

@ -14,6 +14,7 @@ struct vector {
void vec_init(struct vector *v);
void vec_push_back(struct vector *v, void *p);
void *vec_pop_back(struct vector *v);
void vec_sort(struct vector *v, int (*compar)(const void *, const void *));
void vec_destroy(struct vector *v);
void vec_deep_destroy(struct vector *v);