summaryrefslogtreecommitdiff
path: root/json_object.c
diff options
context:
space:
mode:
authorAlexander Dahl <post@lespocky.de>2014-08-21 15:42:50 +0200
committerAlexander Dahl <post@lespocky.de>2014-08-21 15:42:50 +0200
commit2f5789bdef5c65b951db1add50b08028b0051c36 (patch)
tree4cb30a8ce95dbac3f9f7dcefa5159ec7728695c5 /json_object.c
parentd4e81f9ec8273914739808737fa0a27a3f0589fb (diff)
downloadjson-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.c17
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);