simd_kernels/
operators.rs

1// Copyright Peter Bower 2025. All Rights Reserved.
2// Licensed under Mozilla Public License (MPL) 2.0.
3
4//! Contains basic numeric kernel operators for matching and routing purposes
5
6/// Arithmetic operators for numeric computations.
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum ArithmeticOperator {
9    /// Addition (`lhs + rhs`)
10    Add,
11    /// Subtraction (`lhs - rhs`)
12    Subtract,
13    /// Multiplication (`lhs * rhs`)
14    Multiply,
15    /// Division (`lhs / rhs`)
16    ///
17    /// For integers, division by zero panics in dense arrays and nullifies in masked arrays.
18    /// For floating-point, follows IEEE 754 (yields ±Inf or NaN).
19    Divide,
20    /// Modulus/remainder operation (`lhs % rhs`)
21    ///
22    /// Behaviour matches Rust's `%` operator. Division by zero handling follows same
23    /// rules as `Divide` operation.
24    Remainder,
25    /// Exponentiation (`lhs ^ rhs`)
26    ///
27    /// For integers, uses repeated multiplication. For floating-point, uses `pow()` function.
28    /// Negative exponents on integers may yield zero due to truncation.
29    Power,
30}
31
32/// Comparison operators for binary predicates.
33#[derive(Debug, Clone, Copy, PartialEq, Eq)]
34pub enum ComparisonOperator {
35    /// Equality comparison (`lhs == rhs`)
36    Equals,
37    /// Inequality comparison (`lhs != rhs`)
38    NotEquals,
39    /// Less-than comparison (`lhs < rhs`)
40    LessThan,
41    /// Less-than-or-equal comparison (`lhs <= rhs`)
42    LessThanOrEqualTo,
43    /// Greater-than comparison (`lhs > rhs`)
44    GreaterThan,
45    /// Greater-than-or-equal comparison (`lhs >= rhs`)
46    GreaterThanOrEqualTo,
47    /// Tests if value is null (`lhs IS NULL`)
48    ///
49    /// Always returns a valid boolean, never null.
50    IsNull,
51    /// Tests if value is not null (`lhs IS NOT NULL`)
52    ///
53    /// Always returns a valid boolean, never null.
54    IsNotNull,
55    /// Range membership test (`lhs BETWEEN min AND max`)
56    ///
57    /// Equivalent to `lhs >= min AND lhs <= max` with appropriate null handling.
58    Between,
59    /// Set membership test (`lhs IN (set)`)
60    ///
61    /// Returns true if lhs matches any value in the provided set.
62    In,
63    /// Set exclusion test (`lhs NOT IN (set)`)
64    ///
65    /// Returns true if lhs doesn't match any value in the provided set.
66    NotIn,
67}
68
69/// Logical/boolean operators for conditional expressions.
70#[derive(Debug, Clone, Copy, PartialEq, Eq)]
71pub enum LogicalOperator {
72    /// Logical AND (`lhs AND rhs`)
73    ///
74    /// Returns false if either operand is false, otherwise propagates nulls.
75    And,
76    /// Logical OR (`lhs OR rhs`)
77    ///
78    /// Returns true if either operand is true, otherwise propagates nulls.
79    Or,
80    /// Logical XOR (`lhs XOR rhs`)
81    ///
82    /// Returns true if operands differ, false if same, null if either is null.
83    Xor,
84}
85
86/// Unary operators for single-operand transformations.
87#[derive(Debug, Clone, Copy, PartialEq, Eq)]
88pub enum UnaryOperator {
89    /// Arithmetic negation (`-operand`)
90    ///
91    /// Negates numeric values. For unsigned integers, uses wrapping negation.
92    Negative,
93    /// Logical/bitwise NOT (`!operand` or `~operand`)
94    ///
95    /// For booleans: logical NOT. For integers: bitwise complement.
96    Not,
97    /// Unary plus (`+operand`)
98    ///
99    /// Identity operation that explicitly indicates positive values.
100    /// Primarily used for symmetry with negation operator.
101    Positive,
102}