mongory 2.1.1-x86_64-linux → 2.2.0-x86_64-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,193 +0,0 @@
1
- /**
2
- * @file base_matcher.c
3
- * @brief Implements the base matcher constructor and related utility functions.
4
- * This is an internal implementation file for the matcher module.
5
- */
6
- #include "base_matcher.h"
7
- #include "../foundations/string_buffer.h"
8
- #include <errno.h> // For errno, ERANGE
9
- #include <limits.h> // For INT_MIN, INT_MAX
10
- #include <mongory-core.h> // General include, for mongory_matcher types
11
- #include <stdbool.h>
12
- #include <stdio.h> // For printf
13
- #include <stdlib.h> // For strtol
14
- #include "matcher_explainable.h"
15
- #include "matcher_traversable.h"
16
- #include "../foundations/utils.h"
17
-
18
- #if defined(_MSC_VER)
19
- # define MONGORY_THREAD_LOCAL __declspec(thread)
20
- #else
21
- # define MONGORY_THREAD_LOCAL __thread
22
- #endif
23
-
24
- static MONGORY_THREAD_LOCAL mongory_compile_budget mongory_tls_compile_budget = {0};
25
-
26
- mongory_compile_budget mongory_compile_budget_begin(void) {
27
- mongory_compile_budget saved = mongory_tls_compile_budget;
28
- mongory_tls_compile_budget.active = true;
29
- mongory_tls_compile_budget.depth = 0;
30
- mongory_tls_compile_budget.nodes = 0;
31
- mongory_tls_compile_budget.max_depth = mongory_max_depth_get();
32
- mongory_tls_compile_budget.max_nodes = mongory_max_nodes_get();
33
- return saved;
34
- }
35
-
36
- void mongory_compile_budget_end(mongory_compile_budget saved) {
37
- mongory_tls_compile_budget = saved;
38
- }
39
-
40
- bool mongory_compile_budget_enter_depth(mongory_memory_pool *pool) {
41
- if (!mongory_tls_compile_budget.active) {
42
- return true;
43
- }
44
- mongory_tls_compile_budget.depth++;
45
- if (mongory_tls_compile_budget.max_depth > 0 &&
46
- mongory_tls_compile_budget.depth > mongory_tls_compile_budget.max_depth) {
47
- mongory_tls_compile_budget.depth--;
48
- if (pool && pool->error == NULL) {
49
- pool->error = &MONGORY_DEPTH_LIMIT_ERROR;
50
- }
51
- return false;
52
- }
53
- return true;
54
- }
55
-
56
- void mongory_compile_budget_leave_depth(void) {
57
- if (mongory_tls_compile_budget.active && mongory_tls_compile_budget.depth > 0) {
58
- mongory_tls_compile_budget.depth--;
59
- }
60
- }
61
-
62
- bool mongory_compile_budget_count_node(mongory_memory_pool *pool) {
63
- if (!mongory_tls_compile_budget.active) {
64
- return true;
65
- }
66
- mongory_tls_compile_budget.nodes++;
67
- if (mongory_tls_compile_budget.max_nodes > 0 &&
68
- mongory_tls_compile_budget.nodes > mongory_tls_compile_budget.max_nodes) {
69
- if (pool && pool->error == NULL) {
70
- pool->error = &MONGORY_NODE_LIMIT_ERROR;
71
- }
72
- return false;
73
- }
74
- return true;
75
- }
76
-
77
- /**
78
- * @brief Allocates and initializes common fields of a `mongory_matcher`.
79
- *
80
- * This function serves as a common initializer for all specific matcher types.
81
- * It allocates memory for the `mongory_matcher` structure itself from the
82
- * provided `pool`, sets the `pool` and `condition` members.
83
- * The `matcher->match` function pointer specific to the matcher type must be
84
- * set by the caller. `original_match` and `trace` in the context are set to
85
- * NULL.
86
- *
87
- * @param pool The memory pool to use for allocation. Must be non-NULL and
88
- * valid.
89
- * @param condition The condition value for this matcher.
90
- * @return mongory_matcher* Pointer to the newly allocated and partially
91
- * initialized matcher, or NULL if allocation fails.
92
- */
93
- mongory_matcher *mongory_matcher_base_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx) {
94
- if (!pool || !pool->alloc) {
95
- return NULL; // Invalid memory pool.
96
- }
97
- if (!mongory_compile_budget_count_node(pool)) {
98
- return NULL;
99
- }
100
- mongory_matcher *matcher = MG_ALLOC_PTR(pool, mongory_matcher);
101
- if (matcher == NULL) {
102
- // Allocation failed, pool->alloc might set pool->error.
103
- pool->error = &MONGORY_ALLOC_ERROR;
104
- return NULL;
105
- }
106
-
107
- // Initialize common fields
108
- matcher->original_match = NULL;
109
- matcher->sub_count = 0;
110
- matcher->pool = pool;
111
- matcher->condition = condition;
112
- matcher->name = NULL; // Name is not set by base_new.
113
- matcher->match = NULL; // Specific match function must be set by derived type.
114
- matcher->explain = mongory_matcher_base_explain; // Specific explain function must be set by derived type.
115
- matcher->traverse = mongory_matcher_leaf_traverse;
116
- matcher->trace_stack = NULL;
117
- matcher->trace_level = 0;
118
- matcher->extern_ctx = extern_ctx; // Set the external context.
119
- matcher->priority = 1.0; // Set the priority to 1.0.
120
- matcher->parent = NULL; // Attached later when wrapped by a parent.
121
- return matcher;
122
- }
123
-
124
- /**
125
- * @brief The match function for a matcher that always returns true.
126
- * @param matcher Unused.
127
- * @param value Unused.
128
- * @return Always true.
129
- */
130
- static inline bool mongory_matcher_always_true_match(mongory_matcher *matcher, mongory_value *value) {
131
- (void)matcher; // Mark as unused to prevent compiler warnings.
132
- (void)value; // Mark as unused.
133
- return true; // This matcher always indicates a match.
134
- }
135
-
136
- /**
137
- * @brief Creates a matcher instance that will always evaluate to true.
138
- * Useful as a placeholder or for default cases.
139
- * @param pool Memory pool for allocation.
140
- * @param condition Condition (typically ignored by this matcher).
141
- * @return A new `mongory_matcher` or NULL on failure.
142
- */
143
- mongory_matcher *mongory_matcher_always_true_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx) {
144
- mongory_matcher *matcher = mongory_matcher_base_new(pool, condition, extern_ctx);
145
- if (!matcher) {
146
- return NULL;
147
- }
148
- matcher->match = mongory_matcher_always_true_match;
149
- matcher->original_match = mongory_matcher_always_true_match;
150
- matcher->name = mongory_string_cpy(pool, "Always True");
151
- if (!matcher->name) {
152
- return NULL;
153
- }
154
- matcher->explain = mongory_matcher_base_explain;
155
- // Optionally set original_match as well if it's a strict policy
156
- // matcher->context.original_match = mongory_matcher_always_true_match;
157
- return matcher;
158
- }
159
-
160
- /**
161
- * @brief The match function for a matcher that always returns false.
162
- * @param matcher Unused.
163
- * @param value Unused.
164
- * @return Always false.
165
- */
166
- static inline bool mongory_matcher_always_false_match(mongory_matcher *matcher, mongory_value *value) {
167
- (void)matcher; // Mark as unused.
168
- (void)value; // Mark as unused.
169
- return false; // This matcher never indicates a match.
170
- }
171
-
172
- /**
173
- * @brief Creates a matcher instance that will always evaluate to false.
174
- * Useful for conditions that should never match.
175
- * @param pool Memory pool for allocation.
176
- * @param condition Condition (typically ignored by this matcher).
177
- * @return A new `mongory_matcher` or NULL on failure.
178
- */
179
- mongory_matcher *mongory_matcher_always_false_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx) {
180
- mongory_matcher *matcher = mongory_matcher_base_new(pool, condition, extern_ctx);
181
- if (!matcher) {
182
- return NULL;
183
- }
184
- matcher->match = mongory_matcher_always_false_match;
185
- matcher->original_match = mongory_matcher_always_false_match;
186
- matcher->name = mongory_string_cpy(pool, "Always False");
187
- if (!matcher->name) {
188
- return NULL;
189
- }
190
- matcher->explain = mongory_matcher_base_explain;
191
- // matcher->context.original_match = mongory_matcher_always_false_match;
192
- return matcher;
193
- }
@@ -1,117 +0,0 @@
1
- #ifndef MONGORY_MATCHER_BASE_H
2
- #define MONGORY_MATCHER_BASE_H
3
-
4
- /**
5
- * @file base_matcher.h
6
- * @brief Defines the base matcher constructor and utility functions for
7
- * matchers. This is an internal header for the matcher module.
8
- *
9
- * This includes a constructor for the fundamental `mongory_matcher` structure,
10
- * constructors for trivial matchers (always true/false), and a utility
11
- * for parsing integers from strings.
12
- */
13
-
14
- #include "mongory-core/foundations/array.h" // For mongory_array (context trace)
15
- #include "mongory-core/foundations/memory_pool.h"
16
- #include "mongory-core/foundations/value.h"
17
- #include "mongory-core/matchers/matcher.h" // For mongory_matcher structure
18
- #include "matcher_explainable.h"
19
- #include "matcher_traversable.h"
20
- #include <stdbool.h>
21
-
22
- /**
23
- * @brief Function pointer type for a matcher's core matching logic.
24
- *
25
- * @param matcher A pointer to the `mongory_matcher` instance itself.
26
- * @param value A pointer to the `mongory_value` to be evaluated against the
27
- * matcher's condition.
28
- * @return bool True if the `value` matches the condition, false otherwise.
29
- */
30
- typedef bool (*mongory_matcher_match_func)(mongory_matcher *matcher, mongory_value *value);
31
-
32
- /**
33
- * @struct mongory_matcher
34
- * @brief Represents a generic matcher in the Mongory system.
35
- *
36
- * Each matcher has a name (optional, for identification), a condition value
37
- * that defines its criteria, a function pointer to its matching logic,
38
- * a memory pool for its allocations, and a context.
39
- */
40
- struct mongory_matcher {
41
- char *name; /**< Optional name for the matcher (e.g., "$eq").
42
- String is typically allocated from the pool. */
43
- mongory_value *condition; /**< The condition (a `mongory_value`) that this
44
- matcher evaluates against. */
45
- mongory_matcher_match_func match; /**< Function pointer to the specific matching
46
- logic for this matcher type. */
47
- mongory_memory_pool *pool; /**< The memory pool used for allocations related
48
- to this matcher instance. */
49
- mongory_matcher_traverse_func explain; /**< Function pointer to the explanation
50
- logic for this matcher type. */
51
- mongory_matcher_match_func original_match; /**< Stores the original match function, potentially for
52
- restoration or delegation. */
53
- size_t sub_count; /**< The number of sub-matchers. */
54
- mongory_matcher_traverse_func traverse; /**< Function pointer to the traversal logic for this matcher type. */
55
- mongory_array *trace_stack; /**< The trace stack for this matcher. */
56
- int trace_level; /**< The trace level for this matcher. */
57
- double priority; /**< The priority for this matcher. */
58
- mongory_matcher *parent; /**< Enclosing parent matcher for dynamic priority updates. */
59
- void *extern_ctx; /**< External context for the matcher. */
60
- };
61
-
62
- /**
63
- * @brief Creates a new base `mongory_matcher` instance and initializes its
64
- * common fields.
65
- *
66
- * This function allocates a `mongory_matcher` structure from the provided pool
67
- * and sets its `pool` and `condition` fields. The `match` function and other
68
- * specific fields must be set by the caller or derived matcher constructors.
69
- * The context's original_match and trace are initialized to NULL.
70
- *
71
- * @param pool The memory pool to use for allocating the matcher.
72
- * @param condition The `mongory_value` representing the condition for this
73
- * matcher.
74
- * @return mongory_matcher* A pointer to the newly allocated base matcher, or
75
- * NULL on allocation failure.
76
- */
77
- mongory_matcher *mongory_matcher_base_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx);
78
-
79
- /**
80
- * @brief Creates a new matcher that always evaluates to true.
81
- *
82
- * @param pool The memory pool for allocation.
83
- * @param condition The condition value (often unused by this matcher but stored
84
- * for consistency).
85
- * @return mongory_matcher* A pointer to the "always true" matcher, or NULL on
86
- * failure.
87
- */
88
- mongory_matcher *mongory_matcher_always_true_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx);
89
-
90
- /**
91
- * @brief Creates a new matcher that always evaluates to false.
92
- *
93
- * @param pool The memory pool for allocation.
94
- * @param condition The condition value (often unused by this matcher but stored
95
- * for consistency).
96
- * @return mongory_matcher* A pointer to the "always false" matcher, or NULL on
97
- * failure.
98
- */
99
- mongory_matcher *mongory_matcher_always_false_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx);
100
-
101
- void mongory_matcher_enable_trace_at(mongory_matcher *matcher, mongory_array *trace_stack, int level);
102
-
103
- typedef struct mongory_compile_budget {
104
- bool active;
105
- size_t depth;
106
- size_t nodes;
107
- size_t max_depth;
108
- size_t max_nodes;
109
- } mongory_compile_budget;
110
-
111
- mongory_compile_budget mongory_compile_budget_begin(void);
112
- void mongory_compile_budget_end(mongory_compile_budget saved);
113
- bool mongory_compile_budget_enter_depth(mongory_memory_pool *pool);
114
- void mongory_compile_budget_leave_depth(void);
115
- bool mongory_compile_budget_count_node(mongory_memory_pool *pool);
116
-
117
- #endif /* MONGORY_MATCHER_BASE_H */
@@ -1,241 +0,0 @@
1
- /**
2
- * @file compare_matcher.c
3
- * @brief Implements comparison matchers like `$eq`, `$gt`, `$lt`, etc.
4
- *
5
- * This file follows a factory pattern. A generic private constructor,
6
- * `mongory_matcher_compare_new`, is used to create a base matcher.
7
- * Each specific comparison operator (e.g., `$eq`, `$gt`) has its own public
8
- * constructor (e.g., `mongory_matcher_equal_new`) that provides a specialized
9
- * matching function to the generic constructor.
10
- */
11
- #include "compare_matcher.h"
12
- #include "base_matcher.h" // For mongory_matcher_base_new
13
- #include <mongory-core.h> // For mongory_value, mongory_matcher types
14
- #include "../foundations/utils.h"
15
-
16
- /**
17
- * @brief Generic constructor for comparison matchers.
18
- *
19
- * Initializes a base matcher and sets its `match` function and
20
- * `original_match` context field to the provided `match_func`.
21
- *
22
- * @param pool The memory pool for allocation.
23
- * @param condition The `mongory_value` to be stored as the comparison target.
24
- * @param match_func The specific comparison logic function (e.g., for equality,
25
- * greater than).
26
- * @return mongory_matcher* A pointer to the newly created comparison matcher,
27
- * or NULL on failure.
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;
38
- }
39
-
40
- // ============================================================================
41
- // 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
- // ============================================================================
47
-
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
- 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
63
- int result = value->comp(value, matcher->condition);
64
- if (result == 0) {
65
- return true; // 0 indicates equality.
66
- }
67
- if (value->type == MONGORY_TYPE_ARRAY && value->data.a) {
68
- mongory_array *arr = value->data.a;
69
- for (size_t i = 0; i < arr->count; i++) {
70
- mongory_value *elem = arr->get(arr, i);
71
- if (elem && elem->comp && elem->comp(elem, matcher->condition) == 0) {
72
- return true;
73
- }
74
- }
75
- }
76
- return false;
77
- }
78
-
79
- 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;
87
- }
88
-
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
- 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;
118
- }
119
-
120
- 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;
128
- }
129
-
130
- static inline bool mongory_value_is_orderable(const mongory_value *value) {
131
- return value != NULL &&
132
- (value->type == MONGORY_TYPE_INT || value->type == MONGORY_TYPE_DOUBLE || value->type == MONGORY_TYPE_STRING);
133
- }
134
-
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)
144
- return false;
145
- int result = value->comp(value, matcher->condition);
146
- if (result == mongory_value_compare_fail) {
147
- return false;
148
- }
149
- return result == 1; // 1 indicates value > condition.
150
- }
151
-
152
- 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;
160
- }
161
-
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
- 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.
177
- }
178
-
179
- 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;
187
- }
188
-
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
- 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.
204
- }
205
-
206
- 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;
214
- }
215
-
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
- 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.
231
- }
232
-
233
- 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;
241
- }
@@ -1,83 +0,0 @@
1
- #ifndef MONGORY_MATCHER_COMPARE_H
2
- #define MONGORY_MATCHER_COMPARE_H
3
-
4
- /**
5
- * @file compare_matcher.h
6
- * @brief Defines constructors for comparison matchers (e.g., equality, greater
7
- * than). This is an internal header for the matcher module.
8
- *
9
- * These matchers compare an input `mongory_value` against a `condition` value
10
- * stored within the matcher, using the `comp` function of the input value.
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
- #include <stdbool.h>
18
-
19
- /** @name Comparison Matcher Constructors
20
- * Functions to create instances of various comparison matchers.
21
- * Each takes a memory pool and a condition value.
22
- * @{
23
- */
24
-
25
- /**
26
- * @brief Creates an "equal" ($eq) matcher.
27
- * Matches if the input value is equal to the matcher's condition value.
28
- * @param pool Memory pool for allocation.
29
- * @param condition The `mongory_value` to compare against.
30
- * @return A new `$eq` matcher, or NULL on failure.
31
- */
32
- mongory_matcher *mongory_matcher_equal_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx);
33
-
34
- /**
35
- * @brief Creates a "not equal" ($ne) matcher.
36
- * Matches if the input value is not equal to the matcher's condition value.
37
- * Also matches if the types are incompatible for comparison.
38
- * @param pool Memory pool for allocation.
39
- * @param condition The `mongory_value` to compare against.
40
- * @return A new `$ne` matcher, or NULL on failure.
41
- */
42
- mongory_matcher *mongory_matcher_not_equal_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx);
43
-
44
- /**
45
- * @brief Creates a "greater than" ($gt) matcher.
46
- * Matches if the input value is greater than the matcher's condition value.
47
- * @param pool Memory pool for allocation.
48
- * @param condition The `mongory_value` to compare against.
49
- * @return A new `$gt` matcher, or NULL on failure.
50
- */
51
- mongory_matcher *mongory_matcher_greater_than_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx);
52
-
53
- /**
54
- * @brief Creates a "less than" ($lt) matcher.
55
- * Matches if the input value is less than the matcher's condition value.
56
- * @param pool Memory pool for allocation.
57
- * @param condition The `mongory_value` to compare against.
58
- * @return A new `$lt` matcher, or NULL on failure.
59
- */
60
- mongory_matcher *mongory_matcher_less_than_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx);
61
-
62
- /**
63
- * @brief Creates a "greater than or equal" ($gte) matcher.
64
- * Matches if the input value is greater than or equal to the matcher's
65
- * condition value.
66
- * @param pool Memory pool for allocation.
67
- * @param condition The `mongory_value` to compare against.
68
- * @return A new `$gte` matcher, or NULL on failure.
69
- */
70
- mongory_matcher *mongory_matcher_greater_than_or_equal_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx);
71
-
72
- /**
73
- * @brief Creates a "less than or equal" ($lte) matcher.
74
- * Matches if the input value is less than or equal to the matcher's condition
75
- * value.
76
- * @param pool Memory pool for allocation.
77
- * @param condition The `mongory_value` to compare against.
78
- * @return A new `$lte` matcher, or NULL on failure.
79
- */
80
- mongory_matcher *mongory_matcher_less_than_or_equal_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx);
81
- /** @} */
82
-
83
- #endif /* MONGORY_MATCHER_COMPARE_H */