-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor scalars into unary_op, binary_op, and logic_op
Signed-off-by: Yuchen Liang <[email protected]>
- Loading branch information
Showing
26 changed files
with
452 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//! A scalar binary operator. | ||
use crate::{operators::scalar::ScalarOperator, values::OptdValue}; | ||
use serde::Deserialize; | ||
|
||
/// A scalar operator that performs a binary operation on two values. | ||
#[derive(Debug, Clone, PartialEq, Deserialize)] | ||
pub struct BinaryOp<Value, Scalar> { | ||
/// The kind of operator. | ||
pub kind: Value, | ||
/// The left operand. | ||
pub left: Scalar, | ||
/// The right operand. | ||
pub right: Scalar, | ||
} | ||
|
||
impl<Value, Scalar> BinaryOp<Value, Scalar> { | ||
/// Create a new addition operator. | ||
pub fn new(kind: Value, left: Scalar, right: Scalar) -> Self { | ||
Self { kind, left, right } | ||
} | ||
} | ||
|
||
/// Creates an addition scalar operator. | ||
pub fn add<Scalar>(left: Scalar, right: Scalar) -> ScalarOperator<OptdValue, Scalar> { | ||
ScalarOperator::BinaryOp(BinaryOp::new(OptdValue::String("add".into()), left, right)) | ||
} | ||
|
||
pub fn minus<Scalar>(left: Scalar, right: Scalar) -> ScalarOperator<OptdValue, Scalar> { | ||
ScalarOperator::BinaryOp(BinaryOp::new( | ||
OptdValue::String("minus".into()), | ||
left, | ||
right, | ||
)) | ||
} | ||
|
||
/// Creates an equality scalar operator. | ||
pub fn equal<Scalar>(left: Scalar, right: Scalar) -> ScalarOperator<OptdValue, Scalar> { | ||
ScalarOperator::BinaryOp(BinaryOp::new( | ||
OptdValue::String("equal".into()), | ||
left, | ||
right, | ||
)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//! A scalar logic operator. | ||
use serde::Deserialize; | ||
|
||
use crate::values::OptdValue; | ||
|
||
use super::ScalarOperator; | ||
|
||
/// A scalar operator that adds two values. | ||
#[derive(Debug, Clone, PartialEq, Deserialize)] | ||
pub struct LogicOp<Value, Scalar> { | ||
/// The kind of logic operator. | ||
pub kind: Value, | ||
/// The operands to the logic operator. | ||
pub children: Vec<Scalar>, | ||
} | ||
|
||
impl<Value, Scalar> LogicOp<Value, Scalar> { | ||
/// Create a new logic scalar operator. | ||
pub fn new(kind: Value, children: Vec<Scalar>) -> Self { | ||
Self { kind, children } | ||
} | ||
} | ||
|
||
/// Creates an `and` logic scalar operator. | ||
pub fn and<Scalar>(children: Vec<Scalar>) -> ScalarOperator<OptdValue, Scalar> { | ||
ScalarOperator::LogicOp(LogicOp::new(OptdValue::String("and".into()), children)) | ||
} | ||
|
||
/// Creates an `and` logic scalar operator. | ||
pub fn or<Scalar>(children: Vec<Scalar>) -> ScalarOperator<OptdValue, Scalar> { | ||
ScalarOperator::LogicOp(LogicOp::new(OptdValue::String("or".into()), children)) | ||
} |
Oops, something went wrong.