mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-09 07:08:02 +02:00
glib-aux: rename nm_utils_array_find_binary_search() to nm_array_bsearch()
The "nm_utils_" prefix is just too verbose. Drop it. Also, Posix has a bsearch function. As this function is similar, rename it. Note that currently the arguments are provided in differnt order from bsearch(). That will be partly addressed next. That is the main reason for the rename. The next commit will swap the arguments, so do a rename first to get a compilation error when backporting a patch that uses the changed API.
This commit is contained in:
parent
1c067fe4c6
commit
2953ebccba
15 changed files with 158 additions and 169 deletions
|
|
@ -7904,12 +7904,12 @@ nm_manager_set_capability(NMManager *self, NMCapability cap)
|
||||||
|
|
||||||
priv = NM_MANAGER_GET_PRIVATE(self);
|
priv = NM_MANAGER_GET_PRIVATE(self);
|
||||||
|
|
||||||
idx = nm_utils_array_find_binary_search(nm_g_array_index_p(priv->capabilities, guint32, 0),
|
idx = nm_array_find_bsearch(nm_g_array_index_p(priv->capabilities, guint32, 0),
|
||||||
sizeof(guint32),
|
sizeof(guint32),
|
||||||
priv->capabilities->len,
|
priv->capabilities->len,
|
||||||
&cap_i,
|
&cap_i,
|
||||||
nm_cmp_uint32_p_with_data,
|
nm_cmp_uint32_p_with_data,
|
||||||
NULL);
|
NULL);
|
||||||
if (idx >= 0)
|
if (idx >= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1080,12 +1080,12 @@ nms_ifcfg_well_known_key_find_info(const char *key, gssize *out_idx)
|
||||||
|
|
||||||
G_STATIC_ASSERT(G_STRUCT_OFFSET(NMSIfcfgKeyTypeInfo, key_name) == 0);
|
G_STATIC_ASSERT(G_STRUCT_OFFSET(NMSIfcfgKeyTypeInfo, key_name) == 0);
|
||||||
|
|
||||||
idx = nm_utils_array_find_binary_search(nms_ifcfg_well_known_keys,
|
idx = nm_array_find_bsearch(nms_ifcfg_well_known_keys,
|
||||||
sizeof(nms_ifcfg_well_known_keys[0]),
|
sizeof(nms_ifcfg_well_known_keys[0]),
|
||||||
G_N_ELEMENTS(nms_ifcfg_well_known_keys),
|
G_N_ELEMENTS(nms_ifcfg_well_known_keys),
|
||||||
&key,
|
&key,
|
||||||
nm_strcmp_p_with_data,
|
nm_strcmp_p_with_data,
|
||||||
NULL);
|
NULL);
|
||||||
NM_SET_OUT(out_idx, idx);
|
NM_SET_OUT(out_idx, idx);
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
|
|
@ -279,12 +279,12 @@ nm_supplicant_settings_verify_setting(const char *key, const char *value, const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
opt_idx = nm_utils_array_find_binary_search(opt_table,
|
opt_idx = nm_array_find_bsearch(opt_table,
|
||||||
sizeof(opt_table[0]),
|
sizeof(opt_table[0]),
|
||||||
G_N_ELEMENTS(opt_table),
|
G_N_ELEMENTS(opt_table),
|
||||||
&key,
|
&key,
|
||||||
nm_strcmp_p_with_data,
|
nm_strcmp_p_with_data,
|
||||||
NULL);
|
NULL);
|
||||||
if (opt_idx < 0) {
|
if (opt_idx < 0) {
|
||||||
if (nm_streq(key, "mode")) {
|
if (nm_streq(key, "mode")) {
|
||||||
if (len != 1)
|
if (len != 1)
|
||||||
|
|
|
||||||
|
|
@ -271,12 +271,12 @@ nm_ethtool_data_get_by_optname(const char *optname)
|
||||||
|
|
||||||
_ASSERT_data();
|
_ASSERT_data();
|
||||||
|
|
||||||
idx = nm_utils_array_find_binary_search((gconstpointer *) _by_name,
|
idx = nm_array_find_bsearch((gconstpointer *) _by_name,
|
||||||
sizeof(_by_name[0]),
|
sizeof(_by_name[0]),
|
||||||
_NM_ETHTOOL_ID_NUM,
|
_NM_ETHTOOL_ID_NUM,
|
||||||
optname,
|
optname,
|
||||||
_by_name_cmp,
|
_by_name_cmp,
|
||||||
NULL);
|
NULL);
|
||||||
return (idx < 0) ? NULL : nm_ethtool_data[_by_name[idx]];
|
return (idx < 0) ? NULL : nm_ethtool_data[_by_name[idx]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -752,11 +752,11 @@ nml_dbus_meta_iface_get(const char *dbus_iface_name)
|
||||||
|
|
||||||
if (NM_STR_HAS_PREFIX(dbus_iface_name, COMMON_PREFIX)) {
|
if (NM_STR_HAS_PREFIX(dbus_iface_name, COMMON_PREFIX)) {
|
||||||
/* optimize, that in fact all our interfaces have the same prefix. */
|
/* optimize, that in fact all our interfaces have the same prefix. */
|
||||||
idx = nm_utils_ptrarray_find_binary_search((gconstpointer *) _nml_dbus_meta_ifaces,
|
idx = nm_ptrarray_find_bsearch((gconstpointer *) _nml_dbus_meta_ifaces,
|
||||||
G_N_ELEMENTS(_nml_dbus_meta_ifaces),
|
G_N_ELEMENTS(_nml_dbus_meta_ifaces),
|
||||||
&dbus_iface_name[NM_STRLEN(COMMON_PREFIX)],
|
&dbus_iface_name[NM_STRLEN(COMMON_PREFIX)],
|
||||||
_strcmp_common_prefix,
|
_strcmp_common_prefix,
|
||||||
NULL);
|
NULL);
|
||||||
} else
|
} else
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
@ -775,12 +775,12 @@ nml_dbus_meta_property_get(const NMLDBusMetaIface *meta_iface,
|
||||||
nm_assert(meta_iface);
|
nm_assert(meta_iface);
|
||||||
nm_assert(dbus_property_name);
|
nm_assert(dbus_property_name);
|
||||||
|
|
||||||
idx = nm_utils_array_find_binary_search(meta_iface->dbus_properties,
|
idx = nm_array_find_bsearch(meta_iface->dbus_properties,
|
||||||
sizeof(meta_iface->dbus_properties[0]),
|
sizeof(meta_iface->dbus_properties[0]),
|
||||||
meta_iface->n_dbus_properties,
|
meta_iface->n_dbus_properties,
|
||||||
&dbus_property_name,
|
&dbus_property_name,
|
||||||
nm_strcmp_p_with_data,
|
nm_strcmp_p_with_data,
|
||||||
NULL);
|
NULL);
|
||||||
if (idx < 0) {
|
if (idx < 0) {
|
||||||
NM_SET_OUT(out_idx, meta_iface->n_dbus_properties);
|
NM_SET_OUT(out_idx, meta_iface->n_dbus_properties);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
|
|
@ -349,12 +349,12 @@ nm_auth_permission_from_string(const char *str)
|
||||||
|
|
||||||
if (!NM_STR_HAS_PREFIX(str, AUTH_PERMISSION_PREFIX))
|
if (!NM_STR_HAS_PREFIX(str, AUTH_PERMISSION_PREFIX))
|
||||||
return NM_CLIENT_PERMISSION_NONE;
|
return NM_CLIENT_PERMISSION_NONE;
|
||||||
idx = nm_utils_array_find_binary_search(nm_auth_permission_sorted,
|
idx = nm_array_find_bsearch(nm_auth_permission_sorted,
|
||||||
sizeof(nm_auth_permission_sorted[0]),
|
sizeof(nm_auth_permission_sorted[0]),
|
||||||
G_N_ELEMENTS(nm_auth_permission_sorted),
|
G_N_ELEMENTS(nm_auth_permission_sorted),
|
||||||
&str[NM_STRLEN(AUTH_PERMISSION_PREFIX)],
|
&str[NM_STRLEN(AUTH_PERMISSION_PREFIX)],
|
||||||
_nm_auth_permission_from_string_cmp,
|
_nm_auth_permission_from_string_cmp,
|
||||||
NULL);
|
NULL);
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
return NM_CLIENT_PERMISSION_NONE;
|
return NM_CLIENT_PERMISSION_NONE;
|
||||||
return nm_auth_permission_sorted[idx];
|
return nm_auth_permission_sorted[idx];
|
||||||
|
|
|
||||||
|
|
@ -3188,11 +3188,11 @@ _parse_info_find(NMSetting *setting,
|
||||||
|
|
||||||
G_STATIC_ASSERT_EXPR(G_STRUCT_OFFSET(ParseInfoProperty, property_name) == 0);
|
G_STATIC_ASSERT_EXPR(G_STRUCT_OFFSET(ParseInfoProperty, property_name) == 0);
|
||||||
|
|
||||||
idx = nm_utils_ptrarray_find_binary_search((gconstpointer *) pis->properties,
|
idx = nm_ptrarray_find_bsearch((gconstpointer *) pis->properties,
|
||||||
NM_PTRARRAY_LEN(pis->properties),
|
NM_PTRARRAY_LEN(pis->properties),
|
||||||
&property_name,
|
&property_name,
|
||||||
nm_strcmp_p_with_data,
|
nm_strcmp_p_with_data,
|
||||||
NULL);
|
NULL);
|
||||||
if (idx >= 0)
|
if (idx >= 0)
|
||||||
pip = pis->properties[idx];
|
pip = pis->properties[idx];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -693,12 +693,12 @@ nm_meta_setting_infos_by_name(const char *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
G_STATIC_ASSERT_EXPR(G_STRUCT_OFFSET(NMMetaSettingInfo, setting_name) == 0);
|
G_STATIC_ASSERT_EXPR(G_STRUCT_OFFSET(NMMetaSettingInfo, setting_name) == 0);
|
||||||
idx = nm_utils_array_find_binary_search(nm_meta_setting_infos,
|
idx = nm_array_find_bsearch(nm_meta_setting_infos,
|
||||||
sizeof(NMMetaSettingInfo),
|
sizeof(NMMetaSettingInfo),
|
||||||
_NM_META_SETTING_TYPE_NUM,
|
_NM_META_SETTING_TYPE_NUM,
|
||||||
&name,
|
&name,
|
||||||
nm_strcmp_p_with_data,
|
nm_strcmp_p_with_data,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
return idx >= 0 ? &nm_meta_setting_infos[idx] : NULL;
|
return idx >= 0 ? &nm_meta_setting_infos[idx] : NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2934,12 +2934,12 @@ _rr_dbus_attr_from_name(const char *name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
idx = nm_utils_array_find_binary_search(rr_dbus_data,
|
idx = nm_array_find_bsearch(rr_dbus_data,
|
||||||
sizeof(rr_dbus_data[0]),
|
sizeof(rr_dbus_data[0]),
|
||||||
_RR_DBUS_ATTR_NUM,
|
_RR_DBUS_ATTR_NUM,
|
||||||
&name,
|
&name,
|
||||||
nm_strcmp_p_with_data,
|
nm_strcmp_p_with_data,
|
||||||
NULL);
|
NULL);
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
return _RR_DBUS_ATTR_NUM;
|
return _RR_DBUS_ATTR_NUM;
|
||||||
return idx;
|
return idx;
|
||||||
|
|
|
||||||
|
|
@ -477,12 +477,12 @@ _nm_sett_info_setting_get_property_info(const NMSettInfoSetting *sett_info,
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
G_STATIC_ASSERT_EXPR(G_STRUCT_OFFSET(NMSettInfoProperty, name) == 0);
|
G_STATIC_ASSERT_EXPR(G_STRUCT_OFFSET(NMSettInfoProperty, name) == 0);
|
||||||
idx = nm_utils_array_find_binary_search(sett_info->property_infos,
|
idx = nm_array_find_bsearch(sett_info->property_infos,
|
||||||
sizeof(NMSettInfoProperty),
|
sizeof(NMSettInfoProperty),
|
||||||
sett_info->property_infos_len,
|
sett_info->property_infos_len,
|
||||||
&property_name,
|
&property_name,
|
||||||
nm_strcmp_p_with_data,
|
nm_strcmp_p_with_data,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
|
|
@ -5020,11 +5020,8 @@ _nm_variant_attribute_spec_find_binary_search(const NMVariantAttributeSpec *cons
|
||||||
|
|
||||||
G_STATIC_ASSERT_EXPR(G_STRUCT_OFFSET(NMVariantAttributeSpec, name) == 0);
|
G_STATIC_ASSERT_EXPR(G_STRUCT_OFFSET(NMVariantAttributeSpec, name) == 0);
|
||||||
|
|
||||||
idx = nm_utils_ptrarray_find_binary_search((gconstpointer *) array,
|
idx =
|
||||||
len,
|
nm_ptrarray_find_bsearch((gconstpointer *) array, len, &name, nm_strcmp_p_with_data, NULL);
|
||||||
&name,
|
|
||||||
nm_strcmp_p_with_data,
|
|
||||||
NULL);
|
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
return array[idx];
|
return array[idx];
|
||||||
|
|
|
||||||
|
|
@ -8784,19 +8784,15 @@ _test_find_binary_search_do(const int *array, gsize len)
|
||||||
|
|
||||||
expected_result = nm_utils_ptrarray_find_first(parray, len, pneedle);
|
expected_result = nm_utils_ptrarray_find_first(parray, len, pneedle);
|
||||||
|
|
||||||
idx = nm_utils_ptrarray_find_binary_search_range(parray,
|
idx = nm_ptrarray_find_bsearch_range(parray,
|
||||||
len,
|
len,
|
||||||
pneedle,
|
pneedle,
|
||||||
_test_find_binary_search_cmp,
|
_test_find_binary_search_cmp,
|
||||||
NULL,
|
NULL,
|
||||||
&idx_first,
|
&idx_first,
|
||||||
&idx_last);
|
&idx_last);
|
||||||
|
|
||||||
idx2 = nm_utils_ptrarray_find_binary_search(parray,
|
idx2 = nm_ptrarray_find_bsearch(parray, len, pneedle, _test_find_binary_search_cmp, NULL);
|
||||||
len,
|
|
||||||
pneedle,
|
|
||||||
_test_find_binary_search_cmp,
|
|
||||||
NULL);
|
|
||||||
g_assert_cmpint(idx, ==, idx2);
|
g_assert_cmpint(idx, ==, idx2);
|
||||||
|
|
||||||
if (expected_result >= 0) {
|
if (expected_result >= 0) {
|
||||||
|
|
@ -8861,12 +8857,12 @@ _test_find_binary_search_do_uint32(const int *int_array, gsize len)
|
||||||
expected_result = idx;
|
expected_result = idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
idx = nm_utils_array_find_binary_search(array,
|
idx = nm_array_find_bsearch(array,
|
||||||
sizeof(guint32),
|
sizeof(guint32),
|
||||||
len,
|
len,
|
||||||
&NEEDLE,
|
&NEEDLE,
|
||||||
nm_cmp_uint32_p_with_data,
|
nm_cmp_uint32_p_with_data,
|
||||||
NULL);
|
NULL);
|
||||||
if (expected_result >= 0)
|
if (expected_result >= 0)
|
||||||
g_assert_cmpint(expected_result, ==, idx);
|
g_assert_cmpint(expected_result, ==, idx);
|
||||||
else {
|
else {
|
||||||
|
|
@ -8960,29 +8956,25 @@ test_nm_utils_ptrarray_find_binary_search_with_duplicates(void)
|
||||||
for (i = 0; i < i_len + BIN_SEARCH_W_DUPS_JITTER; i++) {
|
for (i = 0; i < i_len + BIN_SEARCH_W_DUPS_JITTER; i++) {
|
||||||
gconstpointer p = GINT_TO_POINTER(i);
|
gconstpointer p = GINT_TO_POINTER(i);
|
||||||
|
|
||||||
idx = nm_utils_ptrarray_find_binary_search_range(arr,
|
idx = nm_ptrarray_find_bsearch_range(arr,
|
||||||
i_len,
|
i_len,
|
||||||
p,
|
p,
|
||||||
_test_bin_search2_cmp,
|
_test_bin_search2_cmp,
|
||||||
NULL,
|
NULL,
|
||||||
&idx_first,
|
&idx_first,
|
||||||
&idx_last);
|
&idx_last);
|
||||||
|
|
||||||
idx_first2 = nm_utils_ptrarray_find_first(arr, i_len, p);
|
idx_first2 = nm_utils_ptrarray_find_first(arr, i_len, p);
|
||||||
|
|
||||||
idx2 = nm_utils_array_find_binary_search(arr,
|
idx2 = nm_array_find_bsearch(arr,
|
||||||
sizeof(gpointer),
|
sizeof(gpointer),
|
||||||
i_len,
|
i_len,
|
||||||
&p,
|
&p,
|
||||||
_test_bin_search2_cmp_p,
|
_test_bin_search2_cmp_p,
|
||||||
NULL);
|
NULL);
|
||||||
g_assert_cmpint(idx, ==, idx2);
|
g_assert_cmpint(idx, ==, idx2);
|
||||||
|
|
||||||
idx2 = nm_utils_ptrarray_find_binary_search(arr,
|
idx2 = nm_ptrarray_find_bsearch(arr, i_len, p, _test_bin_search2_cmp, NULL);
|
||||||
i_len,
|
|
||||||
p,
|
|
||||||
_test_bin_search2_cmp,
|
|
||||||
NULL);
|
|
||||||
g_assert_cmpint(idx, ==, idx2);
|
g_assert_cmpint(idx, ==, idx2);
|
||||||
|
|
||||||
if (idx_first2 < 0) {
|
if (idx_first2 < 0) {
|
||||||
|
|
@ -11254,7 +11246,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
g_test_add_func("/core/general/_nm_utils_ascii_str_to_int64", test_nm_utils_ascii_str_to_int64);
|
g_test_add_func("/core/general/_nm_utils_ascii_str_to_int64", test_nm_utils_ascii_str_to_int64);
|
||||||
g_test_add_func("/core/general/nm_utils_is_power_of_two", test_nm_utils_is_power_of_two);
|
g_test_add_func("/core/general/nm_utils_is_power_of_two", test_nm_utils_is_power_of_two);
|
||||||
g_test_add_func("/core/general/nm_utils_ptrarray_find_binary_search_range",
|
g_test_add_func("/core/general/nm_ptrarray_find_bsearch_range",
|
||||||
test_nm_utils_ptrarray_find_binary_search);
|
test_nm_utils_ptrarray_find_binary_search);
|
||||||
g_test_add_func("/core/general/nm_utils_ptrarray_find_binary_search_with_duplicates",
|
g_test_add_func("/core/general/nm_utils_ptrarray_find_binary_search_with_duplicates",
|
||||||
test_nm_utils_ptrarray_find_binary_search_with_duplicates);
|
test_nm_utils_ptrarray_find_binary_search_with_duplicates);
|
||||||
|
|
|
||||||
|
|
@ -3093,12 +3093,12 @@ nm_utils_named_value_list_find(const NMUtilsNamedValue *arr,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (sorted) {
|
if (sorted) {
|
||||||
return nm_utils_array_find_binary_search(arr,
|
return nm_array_find_bsearch(arr,
|
||||||
sizeof(NMUtilsNamedValue),
|
sizeof(NMUtilsNamedValue),
|
||||||
len,
|
len,
|
||||||
&name,
|
&name,
|
||||||
nm_strcmp_p_with_data,
|
nm_strcmp_p_with_data,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
if (nm_streq(arr[i].name, name))
|
if (nm_streq(arr[i].name, name))
|
||||||
|
|
@ -3786,11 +3786,11 @@ nm_utils_ptrarray_is_sorted(gconstpointer *list,
|
||||||
}
|
}
|
||||||
|
|
||||||
gssize
|
gssize
|
||||||
nm_utils_ptrarray_find_binary_search(gconstpointer *list,
|
nm_ptrarray_find_bsearch(gconstpointer *list,
|
||||||
gsize len,
|
gsize len,
|
||||||
gconstpointer needle,
|
gconstpointer needle,
|
||||||
GCompareDataFunc cmpfcn,
|
GCompareDataFunc cmpfcn,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
gssize imin, imax, imid;
|
gssize imin, imax, imid;
|
||||||
int cmp;
|
int cmp;
|
||||||
|
|
@ -3823,13 +3823,13 @@ nm_utils_ptrarray_find_binary_search(gconstpointer *list,
|
||||||
}
|
}
|
||||||
|
|
||||||
gssize
|
gssize
|
||||||
nm_utils_ptrarray_find_binary_search_range(gconstpointer *list,
|
nm_ptrarray_find_bsearch_range(gconstpointer *list,
|
||||||
gsize len,
|
gsize len,
|
||||||
gconstpointer needle,
|
gconstpointer needle,
|
||||||
GCompareDataFunc cmpfcn,
|
GCompareDataFunc cmpfcn,
|
||||||
gpointer user_data,
|
gpointer user_data,
|
||||||
gssize *out_idx_first,
|
gssize *out_idx_first,
|
||||||
gssize *out_idx_last)
|
gssize *out_idx_last)
|
||||||
{
|
{
|
||||||
gssize imin, imax, imid, i2min, i2max, i2mid;
|
gssize imin, imax, imid, i2min, i2max, i2mid;
|
||||||
int cmp;
|
int cmp;
|
||||||
|
|
@ -3904,7 +3904,7 @@ nm_utils_ptrarray_find_binary_search_range(gconstpointer *list,
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nm_utils_array_find_binary_search:
|
* nm_array_find_bsearch:
|
||||||
* @list: the list to search. It must be sorted according to @cmpfcn ordering.
|
* @list: the list to search. It must be sorted according to @cmpfcn ordering.
|
||||||
* @elem_size: the size in bytes of each element in the list
|
* @elem_size: the size in bytes of each element in the list
|
||||||
* @len: the number of elements in @list
|
* @len: the number of elements in @list
|
||||||
|
|
@ -3928,12 +3928,12 @@ nm_utils_ptrarray_find_binary_search_range(gconstpointer *list,
|
||||||
* position where it should be.
|
* position where it should be.
|
||||||
*/
|
*/
|
||||||
gssize
|
gssize
|
||||||
nm_utils_array_find_binary_search(gconstpointer list,
|
nm_array_find_bsearch(gconstpointer list,
|
||||||
gsize elem_size,
|
gsize elem_size,
|
||||||
gsize len,
|
gsize len,
|
||||||
gconstpointer needle,
|
gconstpointer needle,
|
||||||
GCompareDataFunc cmpfcn,
|
GCompareDataFunc cmpfcn,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
gssize imin, imax, imid;
|
gssize imin, imax, imid;
|
||||||
int cmp;
|
int cmp;
|
||||||
|
|
|
||||||
|
|
@ -2103,42 +2103,42 @@ gboolean nm_utils_ptrarray_is_sorted(gconstpointer *list,
|
||||||
GCompareDataFunc cmpfcn,
|
GCompareDataFunc cmpfcn,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
gssize nm_utils_ptrarray_find_binary_search(gconstpointer *list,
|
gssize nm_ptrarray_find_bsearch(gconstpointer *list,
|
||||||
gsize len,
|
gsize len,
|
||||||
gconstpointer needle,
|
gconstpointer needle,
|
||||||
GCompareDataFunc cmpfcn,
|
GCompareDataFunc cmpfcn,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
gssize nm_utils_ptrarray_find_binary_search_range(gconstpointer *list,
|
gssize nm_ptrarray_find_bsearch_range(gconstpointer *list,
|
||||||
gsize len,
|
gsize len,
|
||||||
gconstpointer needle,
|
gconstpointer needle,
|
||||||
GCompareDataFunc cmpfcn,
|
GCompareDataFunc cmpfcn,
|
||||||
gpointer user_data,
|
gpointer user_data,
|
||||||
gssize *out_idx_first,
|
gssize *out_idx_first,
|
||||||
gssize *out_idx_last);
|
gssize *out_idx_last);
|
||||||
|
|
||||||
#define nm_strv_find_binary_search(strv, len, needle) \
|
#define nm_strv_find_binary_search(strv, len, needle) \
|
||||||
({ \
|
({ \
|
||||||
const char *const *const _strv = NM_CAST_STRV_CC(strv); \
|
const char *const *const _strv = NM_CAST_STRV_CC(strv); \
|
||||||
const gsize _len = (len); \
|
const gsize _len = (len); \
|
||||||
const char *const _needle = (needle); \
|
const char *const _needle = (needle); \
|
||||||
\
|
\
|
||||||
nm_assert(_len == 0 || _strv); \
|
nm_assert(_len == 0 || _strv); \
|
||||||
nm_assert(_needle); \
|
nm_assert(_needle); \
|
||||||
\
|
\
|
||||||
nm_utils_ptrarray_find_binary_search((gconstpointer *) _strv, \
|
nm_ptrarray_find_bsearch((gconstpointer *) _strv, \
|
||||||
_len, \
|
_len, \
|
||||||
_needle, \
|
_needle, \
|
||||||
nm_strcmp_with_data, \
|
nm_strcmp_with_data, \
|
||||||
NULL); \
|
NULL); \
|
||||||
})
|
})
|
||||||
|
|
||||||
gssize nm_utils_array_find_binary_search(gconstpointer list,
|
gssize nm_array_find_bsearch(gconstpointer list,
|
||||||
gsize elem_size,
|
gsize elem_size,
|
||||||
gsize len,
|
gsize len,
|
||||||
gconstpointer needle,
|
gconstpointer needle,
|
||||||
GCompareDataFunc cmpfcn,
|
GCompareDataFunc cmpfcn,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
gssize nm_utils_ptrarray_find_first(gconstpointer *list, gssize len, gconstpointer needle);
|
gssize nm_utils_ptrarray_find_first(gconstpointer *list, gssize len, gconstpointer needle);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -693,12 +693,12 @@ nm_meta_setting_infos_by_name(const char *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
G_STATIC_ASSERT_EXPR(G_STRUCT_OFFSET(NMMetaSettingInfo, setting_name) == 0);
|
G_STATIC_ASSERT_EXPR(G_STRUCT_OFFSET(NMMetaSettingInfo, setting_name) == 0);
|
||||||
idx = nm_utils_array_find_binary_search(nm_meta_setting_infos,
|
idx = nm_array_find_bsearch(nm_meta_setting_infos,
|
||||||
sizeof(NMMetaSettingInfo),
|
sizeof(NMMetaSettingInfo),
|
||||||
_NM_META_SETTING_TYPE_NUM,
|
_NM_META_SETTING_TYPE_NUM,
|
||||||
&name,
|
&name,
|
||||||
nm_strcmp_p_with_data,
|
nm_strcmp_p_with_data,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
return idx >= 0 ? &nm_meta_setting_infos[idx] : NULL;
|
return idx >= 0 ? &nm_meta_setting_infos[idx] : NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue