glib-aux: add nm_utils_ptrarray_is_sorted() helper

(cherry picked from commit f51d3862f9)
This commit is contained in:
Thomas Haller 2021-06-15 08:37:56 +02:00
parent c5914709f2
commit 830c970196
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 28 additions and 0 deletions

View file

@ -3948,6 +3948,28 @@ nm_utils_ptrarray_find_first(gconstpointer *list, gssize len, gconstpointer need
/*****************************************************************************/
gboolean
nm_utils_ptrarray_is_sorted(gconstpointer * list,
gsize len,
gboolean require_strict,
GCompareDataFunc cmpfcn,
gpointer user_data)
{
gsize i;
for (i = 1; i < len; i++) {
int c;
c = cmpfcn(list[i - 1], list[i], user_data);
if (G_LIKELY(c < 0))
continue;
if (c > 0 || require_strict)
return FALSE;
}
return TRUE;
}
gssize
nm_utils_ptrarray_find_binary_search(gconstpointer * list,
gsize len,

View file

@ -2133,6 +2133,12 @@ nm_g_hash_table_remove(GHashTable *hash, gconstpointer key)
/*****************************************************************************/
gboolean nm_utils_ptrarray_is_sorted(gconstpointer * list,
gsize len,
gboolean require_strict,
GCompareDataFunc cmpfcn,
gpointer user_data);
gssize nm_utils_ptrarray_find_binary_search(gconstpointer * list,
gsize len,
gconstpointer needle,