Skip to content

Commit

Permalink
array: add array_sort utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Jun 15, 2017
1 parent 4f0c14b commit 4051804
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,7 @@ bool array_resize(Array *arr, size_t len) {
}
return false;
}

void array_sort(Array *arr, int (*compar)(const void*, const void*)) {
qsort(arr->items, arr->len, arr->elem_size, compar);
}
4 changes: 4 additions & 0 deletions array.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,9 @@ bool array_truncate(Array*, size_t length);
* @endrst
*/
bool array_resize(Array*, size_t length);
/**
* Sort array, the comparision function works as for `qsort(3)`.
*/
void array_sort(Array*, int (*compar)(const void*, const void*));

#endif

0 comments on commit 4051804

Please sign in to comment.