14
14
* limitations under the License.
15
15
*/
16
16
17
+ #include "mc-optional-private.h"
17
18
#include "mc-range-edge-generation-private.h"
18
19
19
20
#include "mc-array-private.h"
@@ -28,14 +29,19 @@ struct _mc_edges_t {
28
29
char * leaf ;
29
30
};
30
31
31
- static mc_edges_t * mc_edges_new (const char * leaf , size_t sparsity , uint32_t trimFactor , mongocrypt_status_t * status ) {
32
+ static mc_edges_t * mc_edges_new (const char * leaf ,
33
+ size_t sparsity ,
34
+ mc_optional_uint32_t opt_trimFactor ,
35
+ mongocrypt_status_t * status ,
36
+ bool use_range_v2 ) {
32
37
BSON_ASSERT_PARAM (leaf );
33
38
if (sparsity < 1 ) {
34
39
CLIENT_ERR ("sparsity must be 1 or larger" );
35
40
return NULL ;
36
41
}
37
42
38
43
const size_t leaf_len = strlen (leaf );
44
+ const uint32_t trimFactor = trimFactorDefault (leaf_len , opt_trimFactor , use_range_v2 );
39
45
if (trimFactor != 0 && trimFactor >= leaf_len ) {
40
46
// We append a total of leaf_len + 1 (for the root) - trimFactor edges. When this number is equal to 1, we
41
47
// degenerate into equality, which is not desired, so trimFactor must be less than leaf_len.
@@ -142,7 +148,7 @@ mc_bitstring mc_convert_to_bitstring_u128(mlib_int128 i) {
142
148
return ret ;
143
149
}
144
150
145
- mc_edges_t * mc_getEdgesInt32 (mc_getEdgesInt32_args_t args , mongocrypt_status_t * status ) {
151
+ mc_edges_t * mc_getEdgesInt32 (mc_getEdgesInt32_args_t args , mongocrypt_status_t * status , bool use_range_v2 ) {
146
152
mc_OSTType_Int32 got ;
147
153
if (!mc_getTypeInfo32 ((mc_getTypeInfo32_args_t ){.value = args .value , .min = args .min , .max = args .max },
148
154
& got ,
@@ -158,11 +164,11 @@ mc_edges_t *mc_getEdgesInt32(mc_getEdgesInt32_args_t args, mongocrypt_status_t *
158
164
mc_bitstring valueBin = mc_convert_to_bitstring_u32 (got .value );
159
165
size_t offset = mc_count_leading_zeros_u32 (got .max );
160
166
const char * leaf = valueBin .str + offset ;
161
- mc_edges_t * ret = mc_edges_new (leaf , args .sparsity , args .trimFactor , status );
167
+ mc_edges_t * ret = mc_edges_new (leaf , args .sparsity , args .trimFactor , status , use_range_v2 );
162
168
return ret ;
163
169
}
164
170
165
- mc_edges_t * mc_getEdgesInt64 (mc_getEdgesInt64_args_t args , mongocrypt_status_t * status ) {
171
+ mc_edges_t * mc_getEdgesInt64 (mc_getEdgesInt64_args_t args , mongocrypt_status_t * status , bool use_range_v2 ) {
166
172
mc_OSTType_Int64 got ;
167
173
if (!mc_getTypeInfo64 ((mc_getTypeInfo64_args_t ){.value = args .value , .min = args .min , .max = args .max },
168
174
& got ,
@@ -178,7 +184,7 @@ mc_edges_t *mc_getEdgesInt64(mc_getEdgesInt64_args_t args, mongocrypt_status_t *
178
184
mc_bitstring valueBin = mc_convert_to_bitstring_u64 (got .value );
179
185
size_t offset = mc_count_leading_zeros_u64 (got .max );
180
186
const char * leaf = valueBin .str + offset ;
181
- mc_edges_t * ret = mc_edges_new (leaf , args .sparsity , args .trimFactor , status );
187
+ mc_edges_t * ret = mc_edges_new (leaf , args .sparsity , args .trimFactor , status , use_range_v2 );
182
188
return ret ;
183
189
}
184
190
@@ -202,7 +208,7 @@ mc_edges_t *mc_getEdgesDouble(mc_getEdgesDouble_args_t args, mongocrypt_status_t
202
208
mc_bitstring valueBin = mc_convert_to_bitstring_u64 (got .value );
203
209
size_t offset = mc_count_leading_zeros_u64 (got .max );
204
210
const char * leaf = valueBin .str + offset ;
205
- mc_edges_t * ret = mc_edges_new (leaf , args .sparsity , args .trimFactor , status );
211
+ mc_edges_t * ret = mc_edges_new (leaf , args .sparsity , args .trimFactor , status , use_range_v2 );
206
212
return ret ;
207
213
}
208
214
@@ -227,7 +233,7 @@ mc_edges_t *mc_getEdgesDecimal128(mc_getEdgesDecimal128_args_t args, mongocrypt_
227
233
mc_bitstring bits = mc_convert_to_bitstring_u128 (got .value );
228
234
size_t offset = mc_count_leading_zeros_u128 (got .max );
229
235
const char * leaf = bits .str + offset ;
230
- mc_edges_t * ret = mc_edges_new (leaf , args .sparsity , args .trimFactor , status );
236
+ mc_edges_t * ret = mc_edges_new (leaf , args .sparsity , args .trimFactor , status , use_range_v2 );
231
237
return ret ;
232
238
}
233
239
#endif // MONGOCRYPT_HAVE_DECIMAL128_SUPPORT
0 commit comments