mongory 2.1.1 → 2.2.0

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 (52) 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/ext/mongory_ext/extconf.rb +15 -0
  7. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/config.h +28 -43
  8. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/memory_pool.h +0 -1
  9. data/ext/mongory_ext/mongory-core/include/mongory-core/matchers/matcher.h +3 -4
  10. data/ext/mongory_ext/mongory-core/src/foundations/array.c +28 -5
  11. data/ext/mongory_ext/mongory-core/src/foundations/config.c +24 -22
  12. data/ext/mongory_ext/mongory-core/src/foundations/config_private.h +3 -3
  13. data/ext/mongory_ext/mongory-core/src/foundations/memory_pool.c +22 -13
  14. data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.c +4 -3
  15. data/ext/mongory_ext/mongory-core/src/foundations/table.c +60 -224
  16. data/ext/mongory_ext/mongory-core/src/foundations/table_private.h +36 -0
  17. data/ext/mongory_ext/mongory-core/src/foundations/utils.c +30 -47
  18. data/ext/mongory_ext/mongory-core/src/foundations/utils.h +2 -5
  19. data/ext/mongory_ext/mongory-core/src/foundations/value.c +18 -32
  20. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.c +89 -104
  21. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.h +18 -11
  22. data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.c +35 -150
  23. data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.c +244 -418
  24. data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.h +30 -0
  25. data/ext/mongory_ext/mongory-core/src/matchers/existence_matcher.c +15 -56
  26. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.c +18 -39
  27. data/ext/mongory_ext/mongory-core/src/matchers/implicit_array_matcher.c +14 -15
  28. data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.c +67 -118
  29. data/ext/mongory_ext/mongory-core/src/matchers/matcher.c +373 -123
  30. data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.c +20 -12
  31. data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.h +1 -4
  32. data/ext/mongory_ext/mongory-core/src/matchers/value_matcher.c +214 -171
  33. data/ext/mongory_ext/mongory-core/src/matchers/value_matcher.h +8 -16
  34. data/ext/mongory_ext/mongory_ext.c +26 -4
  35. data/ext/mongory_ext/mongory_ext_internal.h +15 -3
  36. data/ext/mongory_ext/rb_mongory_adapters.c +52 -19
  37. data/ext/mongory_ext/rb_mongory_matcher.c +115 -36
  38. data/ext/mongory_ext/rb_mongory_value.c +124 -51
  39. data/lib/mongory/converters/abstract_converter.rb +5 -5
  40. data/lib/mongory/converters/converted.rb +0 -4
  41. data/lib/mongory/converters/key_converter.rb +13 -36
  42. data/lib/mongory/converters/value_converter.rb +4 -4
  43. data/lib/mongory/matchers.rb +8 -7
  44. data/lib/mongory/query_builder.rb +9 -0
  45. data/lib/mongory/utils/context.rb +0 -6
  46. data/lib/mongory/utils/singleton_builder.rb +1 -4
  47. data/lib/mongory/version.rb +1 -1
  48. data/lib/mongory.rb +0 -1
  49. data/script/coverage.rb +84 -0
  50. metadata +7 -7
  51. data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.c +0 -117
  52. data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.h +0 -29
@@ -26,43 +26,25 @@
26
26
  * @return mongory_matcher* A pointer to the newly created comparison matcher,
27
27
  * or NULL on failure.
28
28
  */
29
- static inline mongory_matcher *mongory_matcher_compare_new(mongory_memory_pool *pool, mongory_value *condition,
30
- mongory_matcher_match_func match_func, void *extern_ctx) {
31
- mongory_matcher *matcher = mongory_matcher_base_new(pool, condition, extern_ctx);
32
- if (matcher == NULL) {
33
- return NULL; // Base matcher allocation failed.
34
- }
35
- matcher->match = match_func;
36
- matcher->original_match = match_func; // Store original match function
37
- return matcher;
29
+ static inline mongory_matcher *mongory_matcher_named_compare_new(mongory_memory_pool *pool, mongory_value *condition,
30
+ mongory_matcher_match_func match_func,
31
+ const char *name, double priority, void *extern_ctx) {
32
+ return (mongory_matcher *)mongory_matcher_alloc_init(
33
+ pool, sizeof(mongory_matcher), condition, extern_ctx, match_func, mongory_matcher_leaf_traverse, name, priority);
38
34
  }
39
35
 
40
36
  // ============================================================================
41
37
  // Static Match Functions
42
- //
43
- // These functions contain the actual logic for each comparison operator.
44
- // They all follow the `mongory_matcher_match_func` signature and are passed
45
- // to the generic constructor.
46
38
  // ============================================================================
47
39
 
48
- /**
49
- * @brief Match function for equality ($eq).
50
- *
51
- * Compares the input `value` with the matcher's `condition` using the
52
- * polymorphic `comp` function of the value. If `value` is an array, also
53
- * checks if any element in the array is equal to `condition`.
54
- *
55
- * @param matcher The equality matcher instance.
56
- * @param value The value to check.
57
- * @return True if `value` (or any of its elements when `value` is an array)
58
- * is equal to `matcher->condition`; false otherwise.
59
- */
60
40
  static inline bool mongory_matcher_equal_match(mongory_matcher *matcher, mongory_value *value) {
61
- if (!value || !value->comp || !matcher->condition)
62
- return false; // Invalid inputs
41
+ if (!value) // MISSING equals only a null condition.
42
+ return matcher->condition && matcher->condition->type == MONGORY_TYPE_NULL;
43
+ if (!value->comp || !matcher->condition)
44
+ return false;
63
45
  int result = value->comp(value, matcher->condition);
64
46
  if (result == 0) {
65
- return true; // 0 indicates equality.
47
+ return true;
66
48
  }
67
49
  if (value->type == MONGORY_TYPE_ARRAY && value->data.a) {
68
50
  mongory_array *arr = value->data.a;
@@ -77,54 +59,15 @@ static inline bool mongory_matcher_equal_match(mongory_matcher *matcher, mongory
77
59
  }
78
60
 
79
61
  mongory_matcher *mongory_matcher_equal_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx) {
80
- mongory_matcher *matcher = mongory_matcher_compare_new(pool, condition, mongory_matcher_equal_match, extern_ctx);
81
- if (!matcher) {
82
- return NULL;
83
- }
84
- matcher->name = mongory_string_cpy(pool, "Eq");
85
- matcher->priority = 1.0;
86
- return matcher;
62
+ return mongory_matcher_named_compare_new(pool, condition, mongory_matcher_equal_match, "Eq", 1.0, extern_ctx);
87
63
  }
88
64
 
89
- /**
90
- * @brief Match function for inequality ($ne).
91
- *
92
- * This is the logical inverse of the `equal_match` function.
93
- * If `value` is an array, returns false if either the array itself or any of
94
- * its elements is equal to `matcher->condition`.
95
- *
96
- * @param matcher The inequality matcher instance.
97
- * @param value The value to check.
98
- * @return True if neither `value` nor any of its elements (when `value` is an
99
- * array) is equal to `matcher->condition`.
100
- */
101
65
  static inline bool mongory_matcher_not_equal_match(mongory_matcher *matcher, mongory_value *value) {
102
- if (!value || !value->comp || !matcher->condition)
103
- return true; // Invalid inputs, treat as "not equal"
104
- int result = value->comp(value, matcher->condition);
105
- if (result == 0) {
106
- return false;
107
- }
108
- if (value->type == MONGORY_TYPE_ARRAY && value->data.a) {
109
- mongory_array *arr = value->data.a;
110
- for (size_t i = 0; i < arr->count; i++) {
111
- mongory_value *elem = arr->get(arr, i);
112
- if (elem && elem->comp && elem->comp(elem, matcher->condition) == 0) {
113
- return false;
114
- }
115
- }
116
- }
117
- return true;
66
+ return !mongory_matcher_equal_match(matcher, value);
118
67
  }
119
68
 
120
69
  mongory_matcher *mongory_matcher_not_equal_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx) {
121
- mongory_matcher *matcher = mongory_matcher_compare_new(pool, condition, mongory_matcher_not_equal_match, extern_ctx);
122
- if (!matcher) {
123
- return NULL;
124
- }
125
- matcher->name = mongory_string_cpy(pool, "Ne");
126
- matcher->priority = 1.0;
127
- return matcher;
70
+ return mongory_matcher_named_compare_new(pool, condition, mongory_matcher_not_equal_match, "Ne", 2.0, extern_ctx);
128
71
  }
129
72
 
130
73
  static inline bool mongory_value_is_orderable(const mongory_value *value) {
@@ -132,110 +75,52 @@ static inline bool mongory_value_is_orderable(const mongory_value *value) {
132
75
  (value->type == MONGORY_TYPE_INT || value->type == MONGORY_TYPE_DOUBLE || value->type == MONGORY_TYPE_STRING);
133
76
  }
134
77
 
135
- /**
136
- * @brief Match function for "greater than" ($gt).
137
- * @param matcher The $gt matcher instance.
138
- * @param value The value to check.
139
- * @return True if `value` is greater than `matcher->condition`, false
140
- * otherwise or on comparison failure.
141
- */
142
- static inline bool mongory_matcher_greater_than_match(mongory_matcher *matcher, mongory_value *value) {
143
- if (!mongory_value_is_orderable(value) || !mongory_value_is_orderable(matcher->condition) || !value->comp)
78
+ static inline bool mongory_compare_orderable(mongory_matcher *matcher, mongory_value *value, int *out) {
79
+ if (!mongory_value_is_orderable(value) || !mongory_value_is_orderable(matcher->condition) || !value->comp) {
144
80
  return false;
81
+ }
145
82
  int result = value->comp(value, matcher->condition);
146
83
  if (result == mongory_value_compare_fail) {
147
84
  return false;
148
85
  }
149
- return result == 1; // 1 indicates value > condition.
86
+ *out = result;
87
+ return true;
88
+ }
89
+
90
+ static inline bool mongory_matcher_greater_than_match(mongory_matcher *matcher, mongory_value *value) {
91
+ int result;
92
+ return mongory_compare_orderable(matcher, value, &result) && result == 1;
150
93
  }
151
94
 
152
95
  mongory_matcher *mongory_matcher_greater_than_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx) {
153
- mongory_matcher *matcher = mongory_matcher_compare_new(pool, condition, mongory_matcher_greater_than_match, extern_ctx);
154
- if (!matcher) {
155
- return NULL;
156
- }
157
- matcher->name = mongory_string_cpy(pool, "Gt");
158
- matcher->priority = 2.0;
159
- return matcher;
96
+ return mongory_matcher_named_compare_new(pool, condition, mongory_matcher_greater_than_match, "Gt", 2.0, extern_ctx);
160
97
  }
161
98
 
162
- /**
163
- * @brief Match function for "less than" ($lt).
164
- * @param matcher The $lt matcher instance.
165
- * @param value The value to check.
166
- * @return True if `value` is less than `matcher->condition`, false otherwise or
167
- * on comparison failure.
168
- */
169
99
  static inline bool mongory_matcher_less_than_match(mongory_matcher *matcher, mongory_value *value) {
170
- if (!mongory_value_is_orderable(value) || !mongory_value_is_orderable(matcher->condition) || !value->comp)
171
- return false;
172
- int result = value->comp(value, matcher->condition);
173
- if (result == mongory_value_compare_fail) {
174
- return false;
175
- }
176
- return result == -1; // -1 indicates value < condition.
100
+ int result;
101
+ return mongory_compare_orderable(matcher, value, &result) && result == -1;
177
102
  }
178
103
 
179
104
  mongory_matcher *mongory_matcher_less_than_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx) {
180
- mongory_matcher *matcher = mongory_matcher_compare_new(pool, condition, mongory_matcher_less_than_match, extern_ctx);
181
- if (!matcher) {
182
- return NULL;
183
- }
184
- matcher->name = mongory_string_cpy(pool, "Lt");
185
- matcher->priority = 2.0;
186
- return matcher;
105
+ return mongory_matcher_named_compare_new(pool, condition, mongory_matcher_less_than_match, "Lt", 2.0, extern_ctx);
187
106
  }
188
107
 
189
- /**
190
- * @brief Match function for "greater than or equal" ($gte).
191
- * @param matcher The $gte matcher instance.
192
- * @param value The value to check.
193
- * @return True if `value` is >= `matcher->condition`, false otherwise or on
194
- * comparison failure.
195
- */
196
108
  static inline bool mongory_matcher_greater_than_or_equal_match(mongory_matcher *matcher, mongory_value *value) {
197
- if (!mongory_value_is_orderable(value) || !mongory_value_is_orderable(matcher->condition) || !value->comp)
198
- return false;
199
- int result = value->comp(value, matcher->condition);
200
- if (result == mongory_value_compare_fail) {
201
- return false;
202
- }
203
- return result >= 0; // 0 or 1 indicates value >= condition.
109
+ int result;
110
+ return mongory_compare_orderable(matcher, value, &result) && result >= 0;
204
111
  }
205
112
 
206
113
  mongory_matcher *mongory_matcher_greater_than_or_equal_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx) {
207
- mongory_matcher *matcher = mongory_matcher_compare_new(pool, condition, mongory_matcher_greater_than_or_equal_match, extern_ctx);
208
- if (!matcher) {
209
- return NULL;
210
- }
211
- matcher->name = mongory_string_cpy(pool, "Gte");
212
- matcher->priority = 2.0;
213
- return matcher;
114
+ return mongory_matcher_named_compare_new(pool, condition, mongory_matcher_greater_than_or_equal_match, "Gte", 2.0,
115
+ extern_ctx);
214
116
  }
215
117
 
216
- /**
217
- * @brief Match function for "less than or equal" ($lte).
218
- * @param matcher The $lte matcher instance.
219
- * @param value The value to check.
220
- * @return True if `value` is <= `matcher->condition`, false otherwise or on
221
- * comparison failure.
222
- */
223
118
  static inline bool mongory_matcher_less_than_or_equal_match(mongory_matcher *matcher, mongory_value *value) {
224
- if (!mongory_value_is_orderable(value) || !mongory_value_is_orderable(matcher->condition) || !value->comp)
225
- return false;
226
- int result = value->comp(value, matcher->condition);
227
- if (result == mongory_value_compare_fail) {
228
- return false;
229
- }
230
- return result <= 0; // 0 or -1 indicates value <= condition.
119
+ int result;
120
+ return mongory_compare_orderable(matcher, value, &result) && result <= 0;
231
121
  }
232
122
 
233
123
  mongory_matcher *mongory_matcher_less_than_or_equal_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx) {
234
- mongory_matcher *matcher = mongory_matcher_compare_new(pool, condition, mongory_matcher_less_than_or_equal_match, extern_ctx);
235
- if (!matcher) {
236
- return NULL;
237
- }
238
- matcher->name = mongory_string_cpy(pool, "Lte");
239
- matcher->priority = 2.0;
240
- return matcher;
124
+ return mongory_matcher_named_compare_new(pool, condition, mongory_matcher_less_than_or_equal_match, "Lte", 2.0,
125
+ extern_ctx);
241
126
  }