mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-28 19:10:09 +01:00
glib-aux: add nm_utils_ptrarray_is_sorted() helper
(cherry picked from commit f51d3862f9)
This commit is contained in:
parent
c5914709f2
commit
830c970196
2 changed files with 28 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue