mongory 2.1.1-aarch64-linux → 2.2.0-aarch64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/README.md +45 -74
  4. data/docs/clang_bridge.md +2 -2
  5. data/docs/performance.md +28 -1
  6. data/lib/core/2.6/mongory_ext.so +0 -0
  7. data/lib/core/2.7/mongory_ext.so +0 -0
  8. data/lib/core/3.0/mongory_ext.so +0 -0
  9. data/lib/core/3.1/mongory_ext.so +0 -0
  10. data/lib/core/3.2/mongory_ext.so +0 -0
  11. data/lib/core/3.3/mongory_ext.so +0 -0
  12. data/lib/core/3.4/mongory_ext.so +0 -0
  13. data/lib/core/4.0/mongory_ext.so +0 -0
  14. data/lib/mongory/converters/abstract_converter.rb +5 -5
  15. data/lib/mongory/converters/converted.rb +0 -4
  16. data/lib/mongory/converters/key_converter.rb +13 -36
  17. data/lib/mongory/converters/value_converter.rb +4 -4
  18. data/lib/mongory/matchers.rb +8 -7
  19. data/lib/mongory/query_builder.rb +9 -0
  20. data/lib/mongory/utils/context.rb +0 -6
  21. data/lib/mongory/utils/singleton_builder.rb +1 -4
  22. data/lib/mongory/version.rb +1 -1
  23. data/lib/mongory.rb +0 -1
  24. data/mongory.gemspec +13 -12
  25. data/script/coverage.rb +84 -0
  26. metadata +9 -54
  27. data/ext/mongory_ext/extconf.rb +0 -115
  28. data/ext/mongory_ext/mongory-core/include/mongory-core/adapters/json.h +0 -62
  29. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/array.h +0 -122
  30. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/config.h +0 -217
  31. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/error.h +0 -82
  32. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/memory_pool.h +0 -115
  33. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/table.h +0 -127
  34. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/value.h +0 -175
  35. data/ext/mongory_ext/mongory-core/include/mongory-core/matchers/matcher.h +0 -103
  36. data/ext/mongory_ext/mongory-core/include/mongory-core.h +0 -12
  37. data/ext/mongory_ext/mongory-core/src/foundations/array.c +0 -336
  38. data/ext/mongory_ext/mongory-core/src/foundations/array_private.h +0 -20
  39. data/ext/mongory_ext/mongory-core/src/foundations/config.c +0 -335
  40. data/ext/mongory_ext/mongory-core/src/foundations/config_private.h +0 -49
  41. data/ext/mongory_ext/mongory-core/src/foundations/error.c +0 -48
  42. data/ext/mongory_ext/mongory-core/src/foundations/memory_pool.c +0 -406
  43. data/ext/mongory_ext/mongory-core/src/foundations/memory_pool_private.h +0 -45
  44. data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.c +0 -117
  45. data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.h +0 -43
  46. data/ext/mongory_ext/mongory-core/src/foundations/table.c +0 -502
  47. data/ext/mongory_ext/mongory-core/src/foundations/utils.c +0 -206
  48. data/ext/mongory_ext/mongory-core/src/foundations/utils.h +0 -77
  49. data/ext/mongory_ext/mongory-core/src/foundations/value.c +0 -548
  50. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.c +0 -193
  51. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.h +0 -117
  52. data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.c +0 -241
  53. data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.h +0 -83
  54. data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.c +0 -730
  55. data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.h +0 -131
  56. data/ext/mongory_ext/mongory-core/src/matchers/existence_matcher.c +0 -158
  57. data/ext/mongory_ext/mongory-core/src/matchers/existence_matcher.h +0 -48
  58. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.c +0 -199
  59. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.h +0 -58
  60. data/ext/mongory_ext/mongory-core/src/matchers/implicit_array_matcher.c +0 -204
  61. data/ext/mongory_ext/mongory-core/src/matchers/implicit_array_matcher.h +0 -47
  62. data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.c +0 -483
  63. data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.h +0 -46
  64. data/ext/mongory_ext/mongory-core/src/matchers/matcher.c +0 -529
  65. data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.c +0 -117
  66. data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.h +0 -29
  67. data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.c +0 -61
  68. data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.h +0 -23
  69. data/ext/mongory_ext/mongory-core/src/matchers/value_matcher.c +0 -416
  70. data/ext/mongory_ext/mongory-core/src/matchers/value_matcher.h +0 -97
  71. data/ext/mongory_ext/mongory_ext.c +0 -66
  72. data/ext/mongory_ext/mongory_ext_internal.h +0 -74
  73. data/ext/mongory_ext/rb_mongory_adapters.c +0 -140
  74. data/ext/mongory_ext/rb_mongory_matcher.c +0 -440
  75. data/ext/mongory_ext/rb_mongory_value.c +0 -327
@@ -1,483 +0,0 @@
1
- /**
2
- * @file inclusion_matcher.c
3
- * @brief Implements $in and $nin matchers for checking value inclusion in an
4
- * array. Uses an immutable, arena-allocated, type-bucketed O(1) hash set for
5
- * condition arrays with >= 16 elements while falling back to linear scan for
6
- * small arrays.
7
- */
8
- #include "inclusion_matcher.h"
9
- #include "base_matcher.h" // For mongory_matcher_base_new
10
- #include "../foundations/array_private.h" // For mongory_array_includes
11
- #include "mongory-core/foundations/array.h" // For mongory_array operations
12
- #include "mongory-core/foundations/error.h" // For mongory_error
13
- #include "mongory-core/foundations/value.h" // For mongory_value
14
- #include <math.h> // For floor, isnan, isfinite, fabs
15
- #include <mongory-core.h> // General include
16
- #include <stdint.h> // For uint64_t, int64_t, INT64_C
17
- #include <string.h> // For strlen, memcmp, memset, memcpy
18
- #include "../foundations/utils.h" // For mongory_string_cpy, mongory_log
19
-
20
- #define MONGORY_IN_HASH_THRESHOLD 16
21
- #define MONGORY_IN_SAFE_INT_MAX (INT64_C(1) << 53)
22
-
23
- typedef struct mongory_in_str_slot {
24
- const char *str;
25
- size_t len;
26
- uint64_t hash;
27
- } mongory_in_str_slot;
28
-
29
- typedef enum mongory_in_num_kind {
30
- MONGORY_IN_NUM_EMPTY = 0,
31
- MONGORY_IN_NUM_INT = 1,
32
- MONGORY_IN_NUM_DOUBLE = 2
33
- } mongory_in_num_kind;
34
-
35
- typedef struct mongory_in_num_slot {
36
- mongory_in_num_kind kind;
37
- uint64_t key_bits; // int64_t bits (for INT) or IEEE-754 double bits (for DOUBLE)
38
- uint64_t hash;
39
- mongory_value *val;
40
- } mongory_in_num_slot;
41
-
42
- typedef struct mongory_in_set {
43
- bool has_null;
44
- bool has_true;
45
- bool has_false;
46
-
47
- mongory_in_str_slot *str_slots;
48
- size_t str_mask;
49
-
50
- mongory_in_num_slot *num_slots;
51
- size_t num_mask;
52
-
53
- mongory_value **fallback;
54
- size_t fallback_count;
55
- } mongory_in_set;
56
-
57
- typedef struct mongory_inclusion_matcher {
58
- mongory_matcher base;
59
- mongory_in_set *set;
60
- } mongory_inclusion_matcher;
61
-
62
- static inline uint64_t mongory_fnv1a_64(const char *s, size_t len) {
63
- uint64_t h = UINT64_C(14695981039346656037);
64
- for (size_t i = 0; i < len; i++) {
65
- h ^= (uint64_t)(unsigned char)s[i];
66
- h *= UINT64_C(1099511628211);
67
- }
68
- return h;
69
- }
70
-
71
- static inline uint64_t mongory_splitmix64(uint64_t x) {
72
- x += UINT64_C(0x9e3779b97f4a7c15);
73
- x = (x ^ (x >> 30)) * UINT64_C(0xbf58476d1ce4e5b9);
74
- x = (x ^ (x >> 27)) * UINT64_C(0x94d049bb133111eb);
75
- return x ^ (x >> 31);
76
- }
77
-
78
- static inline size_t mongory_next_pow2(size_t n) {
79
- size_t cap = 32;
80
- while (cap < n && cap < ((size_t)1 << (sizeof(size_t) * 8 - 1))) {
81
- cap <<= 1;
82
- }
83
- return cap;
84
- }
85
-
86
- /**
87
- * Classifies a numeric mongory_value into a canonical hashable key:
88
- * - Returns MONGORY_IN_NUM_INT for exact integers within [-2^53, 2^53] (including
89
- * integral doubles like 1.0 and -0.0), so 1 == 1.0 and -0.0 == 0 share the same key.
90
- * - Returns MONGORY_IN_NUM_DOUBLE for finite non-integer doubles within [-2^53, 2^53]
91
- * and +/-Infinity.
92
- * - Returns MONGORY_IN_NUM_EMPTY if the value is NaN (never matches) or exceeds
93
- * safe exact-integer range (caller routes large numbers to fallback).
94
- */
95
- static inline mongory_in_num_kind mongory_in_classify_num(const mongory_value *v, uint64_t *out_bits, bool *out_is_nan) {
96
- *out_is_nan = false;
97
- if (v->type == MONGORY_TYPE_INT) {
98
- int64_t i = v->data.i;
99
- if (i >= -MONGORY_IN_SAFE_INT_MAX && i <= MONGORY_IN_SAFE_INT_MAX) {
100
- *out_bits = (uint64_t)i;
101
- return MONGORY_IN_NUM_INT;
102
- }
103
- return MONGORY_IN_NUM_EMPTY;
104
- }
105
- if (v->type == MONGORY_TYPE_DOUBLE) {
106
- double d = v->data.d;
107
- if (isnan(d)) {
108
- *out_is_nan = true;
109
- return MONGORY_IN_NUM_EMPTY;
110
- }
111
- if (d == 0.0) {
112
- *out_bits = 0;
113
- return MONGORY_IN_NUM_INT;
114
- }
115
- if (isfinite(d)) {
116
- if (fabs(d) > (double)MONGORY_IN_SAFE_INT_MAX) {
117
- return MONGORY_IN_NUM_EMPTY;
118
- }
119
- if (floor(d) == d) {
120
- int64_t i = (int64_t)d;
121
- *out_bits = (uint64_t)i;
122
- return MONGORY_IN_NUM_INT;
123
- }
124
- }
125
- uint64_t bits = 0;
126
- memcpy(&bits, &d, sizeof(bits));
127
- *out_bits = bits;
128
- return MONGORY_IN_NUM_DOUBLE;
129
- }
130
- return MONGORY_IN_NUM_EMPTY;
131
- }
132
-
133
- static mongory_in_set *mongory_in_set_build(mongory_memory_pool *pool, mongory_array *arr) {
134
- size_t count = arr->count;
135
- size_t str_count = 0;
136
- size_t num_count = 0;
137
- size_t fb_count = 0;
138
-
139
- for (size_t i = 0; i < count; i++) {
140
- mongory_value *elem = arr->get(arr, i);
141
- if (!elem) {
142
- continue;
143
- }
144
- switch (elem->type) {
145
- case MONGORY_TYPE_NULL:
146
- case MONGORY_TYPE_BOOL:
147
- break;
148
- case MONGORY_TYPE_STRING:
149
- if (elem->data.s != NULL) {
150
- str_count++;
151
- }
152
- break;
153
- case MONGORY_TYPE_INT:
154
- case MONGORY_TYPE_DOUBLE: {
155
- uint64_t bits = 0;
156
- bool is_nan = false;
157
- if (mongory_in_classify_num(elem, &bits, &is_nan) != MONGORY_IN_NUM_EMPTY) {
158
- num_count++;
159
- } else if (!is_nan) {
160
- fb_count++;
161
- }
162
- break;
163
- }
164
- default:
165
- fb_count++;
166
- break;
167
- }
168
- }
169
-
170
- mongory_in_set *set = MG_ALLOC_PTR(pool, mongory_in_set);
171
- if (!set) {
172
- pool->error = &MONGORY_ALLOC_ERROR;
173
- return NULL;
174
- }
175
- memset(set, 0, sizeof(*set));
176
-
177
- if (str_count > 0) {
178
- size_t cap = mongory_next_pow2(str_count * 2);
179
- set->str_slots = (mongory_in_str_slot *)pool->alloc(pool, cap * sizeof(mongory_in_str_slot));
180
- if (!set->str_slots) {
181
- pool->error = &MONGORY_ALLOC_ERROR;
182
- return NULL;
183
- }
184
- memset(set->str_slots, 0, cap * sizeof(mongory_in_str_slot));
185
- set->str_mask = cap - 1;
186
- }
187
-
188
- if (num_count > 0) {
189
- size_t cap = mongory_next_pow2(num_count * 2);
190
- set->num_slots = (mongory_in_num_slot *)pool->alloc(pool, cap * sizeof(mongory_in_num_slot));
191
- if (!set->num_slots) {
192
- pool->error = &MONGORY_ALLOC_ERROR;
193
- return NULL;
194
- }
195
- memset(set->num_slots, 0, cap * sizeof(mongory_in_num_slot));
196
- set->num_mask = cap - 1;
197
- }
198
-
199
- if (fb_count > 0) {
200
- set->fallback = (mongory_value **)pool->alloc(pool, fb_count * sizeof(mongory_value *));
201
- if (!set->fallback) {
202
- pool->error = &MONGORY_ALLOC_ERROR;
203
- return NULL;
204
- }
205
- }
206
-
207
- for (size_t i = 0; i < count; i++) {
208
- mongory_value *elem = arr->get(arr, i);
209
- if (!elem) {
210
- continue;
211
- }
212
- switch (elem->type) {
213
- case MONGORY_TYPE_NULL:
214
- set->has_null = true;
215
- break;
216
- case MONGORY_TYPE_BOOL:
217
- if (elem->data.b) {
218
- set->has_true = true;
219
- } else {
220
- set->has_false = true;
221
- }
222
- break;
223
- case MONGORY_TYPE_STRING: {
224
- const char *s = elem->data.s;
225
- if (!s) {
226
- break;
227
- }
228
- size_t len = strlen(s);
229
- uint64_t h = mongory_fnv1a_64(s, len);
230
- size_t idx = (size_t)(h & set->str_mask);
231
- while (set->str_slots[idx].str != NULL) {
232
- if (set->str_slots[idx].hash == h && set->str_slots[idx].len == len &&
233
- memcmp(set->str_slots[idx].str, s, len) == 0) {
234
- break;
235
- }
236
- idx = (idx + 1) & set->str_mask;
237
- }
238
- if (set->str_slots[idx].str == NULL) {
239
- set->str_slots[idx].str = s;
240
- set->str_slots[idx].len = len;
241
- set->str_slots[idx].hash = h;
242
- }
243
- break;
244
- }
245
- case MONGORY_TYPE_INT:
246
- case MONGORY_TYPE_DOUBLE: {
247
- uint64_t bits = 0;
248
- bool is_nan = false;
249
- mongory_in_num_kind kind = mongory_in_classify_num(elem, &bits, &is_nan);
250
- if (kind != MONGORY_IN_NUM_EMPTY) {
251
- uint64_t h = mongory_splitmix64(bits ^ ((uint64_t)kind << 60));
252
- size_t idx = (size_t)(h & set->num_mask);
253
- while (set->num_slots[idx].kind != MONGORY_IN_NUM_EMPTY) {
254
- if (set->num_slots[idx].kind == kind && set->num_slots[idx].key_bits == bits) {
255
- break;
256
- }
257
- idx = (idx + 1) & set->num_mask;
258
- }
259
- if (set->num_slots[idx].kind == MONGORY_IN_NUM_EMPTY) {
260
- set->num_slots[idx].kind = kind;
261
- set->num_slots[idx].key_bits = bits;
262
- set->num_slots[idx].hash = h;
263
- set->num_slots[idx].val = elem;
264
- }
265
- } else if (!is_nan) {
266
- set->fallback[set->fallback_count++] = elem;
267
- }
268
- break;
269
- }
270
- default:
271
- set->fallback[set->fallback_count++] = elem;
272
- break;
273
- }
274
- }
275
-
276
- return set;
277
- }
278
-
279
- static inline bool mongory_in_set_contains_scalar(const mongory_in_set *set, mongory_value *v) {
280
- if (!v) {
281
- return false;
282
- }
283
- switch (v->type) {
284
- case MONGORY_TYPE_NULL:
285
- return set->has_null;
286
- case MONGORY_TYPE_BOOL:
287
- return v->data.b ? set->has_true : set->has_false;
288
- case MONGORY_TYPE_STRING: {
289
- if (!set->str_slots || !v->data.s) {
290
- return false;
291
- }
292
- const char *s = v->data.s;
293
- size_t len = strlen(s);
294
- uint64_t h = mongory_fnv1a_64(s, len);
295
- size_t idx = (size_t)(h & set->str_mask);
296
- while (set->str_slots[idx].str != NULL) {
297
- if (set->str_slots[idx].hash == h && set->str_slots[idx].len == len &&
298
- memcmp(set->str_slots[idx].str, s, len) == 0) {
299
- return true;
300
- }
301
- idx = (idx + 1) & set->str_mask;
302
- }
303
- return false;
304
- }
305
- case MONGORY_TYPE_INT:
306
- case MONGORY_TYPE_DOUBLE: {
307
- uint64_t bits = 0;
308
- bool is_nan = false;
309
- mongory_in_num_kind kind = mongory_in_classify_num(v, &bits, &is_nan);
310
- if (is_nan) {
311
- return false;
312
- }
313
- if (kind != MONGORY_IN_NUM_EMPTY) {
314
- if (!set->num_slots) {
315
- return false;
316
- }
317
- uint64_t h = mongory_splitmix64(bits ^ ((uint64_t)kind << 60));
318
- size_t idx = (size_t)(h & set->num_mask);
319
- while (set->num_slots[idx].kind != MONGORY_IN_NUM_EMPTY) {
320
- if (set->num_slots[idx].kind == kind && set->num_slots[idx].key_bits == bits &&
321
- set->num_slots[idx].val->comp(set->num_slots[idx].val, v) == 0) {
322
- return true;
323
- }
324
- idx = (idx + 1) & set->num_mask;
325
- }
326
- return false;
327
- }
328
- // Large integer/double outside exact 2^53 range -> check fallback
329
- for (size_t i = 0; i < set->fallback_count; i++) {
330
- mongory_value *cand = set->fallback[i];
331
- if (cand->comp(cand, v) == 0) {
332
- return true;
333
- }
334
- }
335
- return false;
336
- }
337
- default:
338
- for (size_t i = 0; i < set->fallback_count; i++) {
339
- mongory_value *cand = set->fallback[i];
340
- if (cand->comp(cand, v) == 0) {
341
- return true;
342
- }
343
- }
344
- return false;
345
- }
346
- }
347
-
348
- /**
349
- * @brief Validates that the condition for an inclusion matcher is a valid
350
- * array.
351
- */
352
- static inline bool mongory_matcher_validate_array_condition(mongory_value *condition) {
353
- if (condition == NULL) {
354
- return false;
355
- }
356
- if (condition->type != MONGORY_TYPE_ARRAY) {
357
- return false;
358
- }
359
- if (condition->data.a == NULL) {
360
- return false;
361
- }
362
- return true;
363
- }
364
-
365
- static inline bool mongory_matcher_in_match(mongory_matcher *matcher, mongory_value *value_to_check) {
366
- if (!value_to_check || !matcher->condition || !matcher->condition->data.a) {
367
- return false;
368
- }
369
-
370
- mongory_inclusion_matcher *inc = (mongory_inclusion_matcher *)matcher;
371
- mongory_in_set *set = inc->set;
372
-
373
- if (set != NULL) {
374
- if (value_to_check->type != MONGORY_TYPE_ARRAY) {
375
- return mongory_in_set_contains_scalar(set, value_to_check);
376
- }
377
- mongory_array *input_array = value_to_check->data.a;
378
- if (!input_array) {
379
- return false;
380
- }
381
- for (size_t i = 0; i < input_array->count; i++) {
382
- mongory_value *input_item = input_array->get(input_array, i);
383
- if (mongory_in_set_contains_scalar(set, input_item)) {
384
- return true;
385
- }
386
- }
387
- return false;
388
- }
389
-
390
- mongory_array *condition_array = matcher->condition->data.a;
391
-
392
- if (value_to_check->type != MONGORY_TYPE_ARRAY) {
393
- return mongory_array_includes(condition_array, value_to_check);
394
- }
395
-
396
- mongory_array *input_array = value_to_check->data.a;
397
- if (!input_array) {
398
- return false;
399
- }
400
-
401
- for (size_t i = 0; i < input_array->count; i++) {
402
- mongory_value *input_item = input_array->get(input_array, i);
403
- if (mongory_array_includes(condition_array, input_item)) {
404
- return true;
405
- }
406
- }
407
-
408
- return false;
409
- }
410
-
411
- static mongory_inclusion_matcher *mongory_inclusion_matcher_alloc(mongory_memory_pool *pool, mongory_value *condition,
412
- void *extern_ctx, const char *name,
413
- mongory_matcher_match_func match_fn) {
414
- if (!pool || !pool->alloc) {
415
- return NULL;
416
- }
417
- if (!mongory_compile_budget_count_node(pool)) {
418
- return NULL;
419
- }
420
- mongory_inclusion_matcher *inc = MG_ALLOC_PTR(pool, mongory_inclusion_matcher);
421
- if (!inc) {
422
- pool->error = &MONGORY_ALLOC_ERROR;
423
- return NULL;
424
- }
425
-
426
- inc->base.original_match = match_fn;
427
- inc->base.sub_count = 0;
428
- inc->base.pool = pool;
429
- inc->base.condition = condition;
430
- inc->base.name = mongory_string_cpy(pool, (char *)name);
431
- if (!inc->base.name) {
432
- return NULL;
433
- }
434
- inc->base.match = match_fn;
435
- inc->base.explain = mongory_matcher_base_explain;
436
- inc->base.traverse = mongory_matcher_leaf_traverse;
437
- inc->base.trace_stack = NULL;
438
- inc->base.trace_level = 0;
439
- inc->base.extern_ctx = extern_ctx;
440
- inc->base.parent = NULL;
441
- inc->set = NULL;
442
-
443
- mongory_array *cond_arr = condition->data.a;
444
- if (cond_arr->count >= MONGORY_IN_HASH_THRESHOLD) {
445
- inc->set = mongory_in_set_build(pool, cond_arr);
446
- if (!inc->set) {
447
- return NULL;
448
- }
449
- if (inc->set->fallback_count == 0) {
450
- inc->base.priority = 2.5;
451
- } else {
452
- inc->base.priority = 2.5 + mongory_log((double)inc->set->fallback_count + 1.0, 1.5);
453
- }
454
- } else {
455
- inc->base.priority = 1.0 + mongory_log((double)cond_arr->count + 1.0, 1.5);
456
- }
457
-
458
- return inc;
459
- }
460
-
461
- mongory_matcher *mongory_matcher_in_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx) {
462
- if (!mongory_matcher_validate_array_condition(condition)) {
463
- mongory_error_set(pool, MONGORY_ERROR_INVALID_ARGUMENT, "$in condition must be a valid array.");
464
- return NULL;
465
- }
466
- mongory_inclusion_matcher *inc =
467
- mongory_inclusion_matcher_alloc(pool, condition, extern_ctx, "In", mongory_matcher_in_match);
468
- return inc ? &inc->base : NULL;
469
- }
470
-
471
- static inline bool mongory_matcher_not_in_match(mongory_matcher *matcher, mongory_value *value) {
472
- return !mongory_matcher_in_match(matcher, value);
473
- }
474
-
475
- mongory_matcher *mongory_matcher_not_in_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx) {
476
- if (!mongory_matcher_validate_array_condition(condition)) {
477
- mongory_error_set(pool, MONGORY_ERROR_INVALID_ARGUMENT, "$nin condition must be a valid array.");
478
- return NULL;
479
- }
480
- mongory_inclusion_matcher *inc =
481
- mongory_inclusion_matcher_alloc(pool, condition, extern_ctx, "Nin", mongory_matcher_not_in_match);
482
- return inc ? &inc->base : NULL;
483
- }
@@ -1,46 +0,0 @@
1
- #ifndef MONGORY_MATCHER_INCLUSION_H
2
- #define MONGORY_MATCHER_INCLUSION_H
3
-
4
- /**
5
- * @file inclusion_matcher.h
6
- * @brief Defines constructors for inclusion matchers ($in, $nin).
7
- * This is an internal header for the matcher module.
8
- *
9
- * These matchers check if a value is present or not present in a given array
10
- * of values.
11
- */
12
-
13
- #include "base_matcher.h"
14
- #include "mongory-core/foundations/memory_pool.h"
15
- #include "mongory-core/foundations/value.h"
16
- #include "mongory-core/matchers/matcher.h" // For mongory_matcher structure
17
-
18
- /**
19
- * @brief Creates an "in" ($in) matcher.
20
- *
21
- * Matches if the input value is equal to any of the values in the `condition`
22
- * array. If the input value itself is an array, it matches if any element of
23
- * the input array is found in the `condition` array (set intersection).
24
- *
25
- * @param pool Memory pool for allocation.
26
- * @param condition A `mongory_value` of type `MONGORY_TYPE_ARRAY` containing
27
- * the set of values to check against.
28
- * @return A new `$in` matcher, or NULL on failure or invalid condition.
29
- */
30
- mongory_matcher *mongory_matcher_in_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx);
31
-
32
- /**
33
- * @brief Creates a "not in" ($nin) matcher.
34
- *
35
- * Matches if the input value is not equal to any of the values in the
36
- * `condition` array. If the input value itself is an array, it matches if no
37
- * element of the input array is found in the `condition` array.
38
- *
39
- * @param pool Memory pool for allocation.
40
- * @param condition A `mongory_value` of type `MONGORY_TYPE_ARRAY` containing
41
- * the set of values to check against.
42
- * @return A new `$nin` matcher, or NULL on failure or invalid condition.
43
- */
44
- mongory_matcher *mongory_matcher_not_in_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx);
45
-
46
- #endif /* MONGORY_MATCHER_INCLUSION_H */