binsearch: make BINARY_ARRAY_SEARCH_GTE compare against a pointer
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 22 Dec 2016 03:09:22 +0000 (16:09 +1300)
committerDouglas Bagnall <dbagnall@samba.org>
Thu, 9 Feb 2017 02:17:15 +0000 (03:17 +0100)
This is in preparation for improvements in our handling of linked
attributes where we make changes to the pointer in the process of
comparing it (for caching purposes).

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/util/binsearch.h
lib/util/tests/binsearch.c
source4/dsdb/samdb/ldb_modules/vlv_pagination.c

index 454e5ce4742416d9123cc625f5bd1f218000e6d6..4204c9c6fcaf6e8201042bc4b7a9058d366f2f00 100644 (file)
        if ((array_size) > 0) {                                 \
                for (_b = 0, _e = (array_size)-1; _b <= _e; ) { \
                        int32_t _i = (_b + _e) / 2;                     \
        if ((array_size) > 0) {                                 \
                for (_b = 0, _e = (array_size)-1; _b <= _e; ) { \
                        int32_t _i = (_b + _e) / 2;                     \
-                       int _r = comparison_fn(target, array[_i]); \
+                       int _r = comparison_fn(target, &array[_i]); \
                        if (_r == 0) {                                  \
                                (exact) = &array[_i];                   \
                                _e = _i - 1;                            \
                        if (_r == 0) {                                  \
                                (exact) = &array[_i];                   \
                                _e = _i - 1;                            \
index c6ef47e85d0402818d9e68fd542adaa4a385691e..b3ecda165f35b58af644b7f52519f9deb6522264 100644 (file)
@@ -31,6 +31,11 @@ static int int_cmp(int a, int b)
        return a - b;
 }
 
        return a - b;
 }
 
+static int int_cmp_p(int a, int *b)
+{
+       return a - *b;
+}
+
 static bool test_binsearch_v(struct torture_context *tctx)
 {
        int array[] = { -11, -7, 0, 1, 723, 1000000};
 static bool test_binsearch_v(struct torture_context *tctx)
 {
        int array[] = { -11, -7, 0, 1, 723, 1000000};
@@ -72,7 +77,7 @@ static bool test_binsearch_gte(struct torture_context *tctx)
                                i, target);
 
                BINARY_ARRAY_SEARCH_GTE(array, a_len, target,
                                i, target);
 
                BINARY_ARRAY_SEARCH_GTE(array, a_len, target,
-                                       int_cmp, result, next);
+                                       int_cmp_p, result, next);
 
                if (result == NULL) {
                        /* we think there is no exact match */
 
                if (result == NULL) {
                        /* we think there is no exact match */
@@ -134,7 +139,7 @@ static bool test_binsearch_gte(struct torture_context *tctx)
                                i, target);
 
                BINARY_ARRAY_SEARCH_GTE(array, a_len, target,
                                i, target);
 
                BINARY_ARRAY_SEARCH_GTE(array, a_len, target,
-                                       int_cmp, result, result);
+                                       int_cmp_p, result, result);
 
                if (result == NULL) {
                        /* we think the target is greater than all elements */
 
                if (result == NULL) {
                        /* we think the target is greater than all elements */
index bd8df7def5366d9b48d8247d67976f662c3e31da..5b744e3c18177fe5f199b6a2da704ac2673b813e 100644 (file)
@@ -232,7 +232,7 @@ static int send_referrals(struct results_store *store,
 /* vlv_value_compare() is used in a binary search */
 
 static int vlv_value_compare(struct vlv_sort_context *target,
 /* vlv_value_compare() is used in a binary search */
 
 static int vlv_value_compare(struct vlv_sort_context *target,
-                            struct GUID guid)
+                            struct GUID *guid)
 {
        struct ldb_result *result = NULL;
        struct ldb_message_element *el = NULL;
 {
        struct ldb_result *result = NULL;
        struct ldb_message_element *el = NULL;
@@ -243,7 +243,7 @@ static int vlv_value_compare(struct vlv_sort_context *target,
                NULL
        };
 
                NULL
        };
 
-       ret = vlv_search_by_dn_guid(ac->module, ac, &result, &guid, attrs);
+       ret = vlv_search_by_dn_guid(ac->module, ac, &result, guid, attrs);
 
        if (ret != LDB_SUCCESS) {
                target->status = ret;
 
        if (ret != LDB_SUCCESS) {
                target->status = ret;
@@ -259,7 +259,7 @@ static int vlv_value_compare(struct vlv_sort_context *target,
 
 /* The same as vlv_value_compare() but sorting in the opposite direction. */
 static int vlv_value_compare_rev(struct vlv_sort_context *target,
 
 /* The same as vlv_value_compare() but sorting in the opposite direction. */
 static int vlv_value_compare_rev(struct vlv_sort_context *target,
-                            struct GUID guid)
+                            struct GUID *guid)
 {
        return -vlv_value_compare(target, guid);
 }
 {
        return -vlv_value_compare(target, guid);
 }