vortex_compute/logical/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4//! Logical boolean functions.
5//!
6//! This module provides logical operations for boolean scalars, vectors, and datums:
7//!
8//! - **Simple operations** (`binary`): AND, OR, AND NOT. These propagate nulls.
9//! - **Kleene operations** (`kleene`): AND KLEENE, OR KLEENE. These use Kleene three-valued
10//!   logic where `false AND null = false` and `true OR null = true`.
11//! - **Unary operations** (`not`): NOT.
12
13// TODO: We want to add these logical traits on the owned versions of the operands so that we can do
14// in-place operatinos.
15
16mod binary;
17mod kleene;
18mod not;
19
20pub use binary::And;
21pub use binary::AndNot;
22pub use binary::LogicalBinaryOp;
23pub use binary::Or;
24pub use kleene::KleeneAnd;
25pub use kleene::KleeneBinaryOp;
26pub use kleene::KleeneOr;
27
28/// `(Bool, Bool) -> Bool` compute function.
29pub trait LogicalOp<Op, Rhs = Self> {
30    /// The resulting type after performing the logical operation.
31    type Output;
32
33    /// Perform a logical operation between two values.
34    fn op(self, other: Rhs) -> Self::Output;
35}
36
37/// Trait for performing logical AND operations.
38pub trait LogicalAnd<Rhs = Self> {
39    /// The resulting type after performing the logical AND operation.
40    type Output;
41
42    /// Perform a logical AND operation between two values.
43    fn and(self, other: Rhs) -> Self::Output;
44}
45
46/// Trait for performing logical AND KLEENE operations.
47pub trait LogicalAndKleene<Rhs = Self> {
48    /// The resulting type after performing the logical AND KLEENE operation.
49    type Output;
50
51    /// Perform a logical AND KLEENE operation between two values.
52    fn and_kleene(self, other: Rhs) -> Self::Output;
53}
54
55/// Trait for performing logical AND NOT operations.
56pub trait LogicalAndNot<Rhs = Self> {
57    /// The resulting type after performing the logical AND NOT operation.
58    type Output;
59
60    /// Perform a logical AND NOT operation between two values.
61    fn and_not(self, other: Rhs) -> Self::Output;
62}
63
64/// Trait for performing logical OR operations.
65pub trait LogicalOr<Rhs = Self> {
66    /// The resulting type after performing the logical OR operation.
67    type Output;
68
69    /// Perform a logical OR operation between two values.
70    fn or(self, other: Rhs) -> Self::Output;
71}
72
73/// Trait for performing logical OR KLEENE operations.
74pub trait LogicalOrKleene<Rhs = Self> {
75    /// The resulting type after performing the logical OR KLEENE operation.
76    type Output;
77
78    /// Perform a logical OR KLEENE operation between two values.
79    fn or_kleene(self, other: Rhs) -> Self::Output;
80}
81
82/// Trait for performing logical NOT operations.
83pub trait LogicalNot {
84    /// The resulting type after performing the logical NOT operation.
85    type Output;
86
87    /// Perform a logical NOT operation.
88    fn not(self) -> Self::Output;
89}