diff options
author | Alexander Dahl <post@lespocky.de> | 2014-08-21 15:42:50 +0200 |
---|---|---|
committer | Alexander Dahl <post@lespocky.de> | 2014-08-21 15:42:50 +0200 |
commit | 2f5789bdef5c65b951db1add50b08028b0051c36 (patch) | |
tree | 4cb30a8ce95dbac3f9f7dcefa5159ec7728695c5 /json_object.c | |
parent | d4e81f9ec8273914739808737fa0a27a3f0589fb (diff) | |
download | json-c-2f5789bdef5c65b951db1add50b08028b0051c36.tar.gz |
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.
Diffstat (limited to 'json_object.c')
-rw-r--r-- | json_object.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/json_object.c b/json_object.c index 8ed0239..c858a9e 100644 --- a/json_object.c +++ b/json_object.c @@ -889,6 +889,23 @@ void json_object_array_sort(struct json_object *jso, int(*sort_fn)(const void *, array_list_sort(jso->o.c_array, sort_fn); } +struct json_object* json_object_array_bsearch( + const struct json_object *key, + const struct json_object *jso, + int (*sort_fn)(const void *, const void *) ) +{ + struct json_object **result; + + result = (struct json_object **) array_list_bsearch( + (const void **) &key, jso->o.c_array, sort_fn ); + + if ( result == NULL ) { + return NULL; + } else { + return *result; + } +} + int json_object_array_length(struct json_object *jso) { return array_list_length(jso->o.c_array); |