Skip to main content

simd_kernels/
operators.rs

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