diff options
author | Antony Kellermann | 2018-08-25 18:32:09 -0400 |
---|---|---|
committer | Antony Kellermann | 2018-08-25 18:32:09 -0400 |
commit | 76c21390503fce8c5193e928e22813c2b0c43ce6 (patch) | |
tree | 2462eeba24291604cb0f3cd415b2c7383f481a13 | |
parent | b231f8f4e4bcce0cd19b8ff48273572085b9d510 (diff) | |
download | aur-76c21390503fce8c5193e928e22813c2b0c43ce6.tar.gz |
Added ref_data bsearch
-rw-r--r-- | api.c | 16 | ||||
-rw-r--r-- | api.h | 3 |
2 files changed, 19 insertions, 0 deletions
@@ -646,6 +646,22 @@ Info* info_array_get_info_from_symbol(const Info_Array* pInfo_Array, const char* return NULL; } +int ref_data_get_index_from_name_bsearch(const Ref_Data* pRef_Data, const char* name, + size_t left, size_t right) { + if (right < left) + return -1; + + size_t mid = left + (right - left) / 2; + int cmp = strcmp(name, pRef_Data->names[mid]); + if (cmp == 0) + return (int) mid; + + if (cmp > 0) + return ref_data_get_index_from_name_bsearch(pRef_Data, name, mid + 1, right); + + return ref_data_get_index_from_name_bsearch(pRef_Data, name, left, mid - 1); +} + void api_ref_data_destroy(Ref_Data** phRef_Data) { if (*phRef_Data == NULL) return; @@ -336,6 +336,9 @@ void info_store_earnings_from_json(Info* pInfo, const Json* jearnings); */ Info* info_array_get_info_from_symbol(const Info_Array* pInfo_Array, const char* symbol); +int ref_data_get_index_from_name_bsearch(const Ref_Data* pRef_Data, const char* name, + size_t left, size_t right); + /** * Destroys Ref_Data object and frees memory. Sets the pointer of the Ref_Data to NULL * @param phRef_Data the Ref_Data to destroy |