pub struct FilterNode {
pub op: Option<String>,
pub key: Option<String>,
pub cmp: Option<String>,
pub val: Option<String>,
pub vals: Vec<String>,
pub nodes: Vec<FilterNode>,
/* private fields */
}Expand description
A filter node that can be a leaf (comparison) or a branch (logical operation).
This structure is designed to be serialized/deserialized from JSON and can be constructed programmatically using the builder pattern.
Design goals:
- Zero allocations during evaluation
- Easy serialization to/from JSON
- Programmatic construction via builder
- Tree structure for complex filters
Performance optimizations:
- HashSet cache for IN/NIN operators with many values (O(1) lookup)
- Arc-wrapped HashSet shared across clones (zero-copy for socket subscriptions)
Fields§
§op: Option<String>Logical operator for branch nodes: “and”, “or”, “not” If None or empty, this is a leaf node (comparison)
key: Option<String>Key for comparison (leaf nodes only)
cmp: Option<String>Comparison operator for leaf nodes “eq”, “neq”, “in”, “nin”, “ex”, “nex”, “sw”, “ew”, “ct”, “gt”, “gte”, “lt”, “lte”
val: Option<String>Single value for most comparisons
vals: Vec<String>Multiple values for set operations (in, nin)
nodes: Vec<FilterNode>Child nodes for logical operations
Implementations§
Source§impl FilterNode
impl FilterNode
Sourcepub fn new_comparison(key: String, cmp: CompareOp, val: String) -> Self
pub fn new_comparison(key: String, cmp: CompareOp, val: String) -> Self
Creates a new leaf node with a comparison operation.
Sourcepub fn new_set_comparison(
key: String,
cmp: CompareOp,
vals: Vec<String>,
) -> Self
pub fn new_set_comparison( key: String, cmp: CompareOp, vals: Vec<String>, ) -> Self
Creates a new leaf node with a set comparison operation (in/nin).
Sourcepub fn new_existence(key: String, cmp: CompareOp) -> Self
pub fn new_existence(key: String, cmp: CompareOp) -> Self
Creates a new leaf node with an existence check.
Sourcepub fn new_logical(op: LogicalOp, nodes: Vec<FilterNode>) -> Self
pub fn new_logical(op: LogicalOp, nodes: Vec<FilterNode>) -> Self
Creates a new branch node with a logical operation.
Sourcepub fn is_sorted(&self) -> bool
pub fn is_sorted(&self) -> bool
Returns true if the vals vector is sorted and ready for binary search.
Sourcepub fn optimize(&mut self)
pub fn optimize(&mut self)
Optimizes the filter node by sorting vectors for binary search. This avoids the overhead of building HashSets (allocations) while still providing O(log n) lookup performance.
Sourcepub fn logical_op(&self) -> Option<LogicalOp>
pub fn logical_op(&self) -> Option<LogicalOp>
Returns the logical operator if this is a branch node.
Sourcepub fn compare_op(&self) -> CompareOp
pub fn compare_op(&self) -> CompareOp
Returns the comparison operator if this is a leaf node.
Sourcepub fn nodes(&self) -> &[FilterNode]
pub fn nodes(&self) -> &[FilterNode]
Returns the child nodes for logical operations.
Trait Implementations§
Source§impl Clone for FilterNode
impl Clone for FilterNode
Source§fn clone(&self) -> FilterNode
fn clone(&self) -> FilterNode
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more