mirror of
https://github.com/json-c/json-c.git
synced 2026-03-23 23:19:06 +08:00
add bsearch for arrays
Arrays can already be sorted with json_object_array_sort() which uses qsort() of the standard C library. This adds a counterpart using the bsearch() from C.
This commit is contained in:
10
arraylist.c
10
arraylist.c
@@ -91,8 +91,14 @@ array_list_add(struct array_list *arr, void *data)
|
||||
void
|
||||
array_list_sort(struct array_list *arr, int(*sort_fn)(const void *, const void *))
|
||||
{
|
||||
qsort(arr->array, arr->length, sizeof(arr->array[0]),
|
||||
(int (*)(const void *, const void *))sort_fn);
|
||||
qsort(arr->array, arr->length, sizeof(arr->array[0]), sort_fn);
|
||||
}
|
||||
|
||||
void* array_list_bsearch( const void **key, struct array_list *arr,
|
||||
int (*sort_fn)(const void *, const void *) )
|
||||
{
|
||||
return bsearch( key, arr->array, arr->length, sizeof(arr->array[0]),
|
||||
sort_fn );
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
Reference in New Issue
Block a user