bitart: Add reverse_bits unary operation
This commit is contained in:
@@ -56,10 +56,15 @@ impl fmt::Display for Variable {
|
|||||||
pub enum UnaryOperator {
|
pub enum UnaryOperator {
|
||||||
Negation,
|
Negation,
|
||||||
Complement,
|
Complement,
|
||||||
|
ReverseBits,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UnaryOperator {
|
impl UnaryOperator {
|
||||||
const VALUES: &[UnaryOperator] = &[UnaryOperator::Negation, UnaryOperator::Complement];
|
const VALUES: &[UnaryOperator] = &[
|
||||||
|
UnaryOperator::Negation,
|
||||||
|
UnaryOperator::Complement,
|
||||||
|
UnaryOperator::ReverseBits,
|
||||||
|
];
|
||||||
|
|
||||||
fn random<R: Rng>(rng: &mut R) -> UnaryOperator {
|
fn random<R: Rng>(rng: &mut R) -> UnaryOperator {
|
||||||
let values = Self::VALUES;
|
let values = Self::VALUES;
|
||||||
@@ -70,6 +75,7 @@ impl UnaryOperator {
|
|||||||
match self {
|
match self {
|
||||||
UnaryOperator::Negation => -operand,
|
UnaryOperator::Negation => -operand,
|
||||||
UnaryOperator::Complement => !operand,
|
UnaryOperator::Complement => !operand,
|
||||||
|
UnaryOperator::ReverseBits => operand.reverse_bits(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,8 +84,8 @@ impl fmt::Display for UnaryOperator {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
UnaryOperator::Negation => write!(f, "-"),
|
UnaryOperator::Negation => write!(f, "-"),
|
||||||
// We use C syntax for `Display`.
|
|
||||||
UnaryOperator::Complement => write!(f, "~"),
|
UnaryOperator::Complement => write!(f, "~"),
|
||||||
|
UnaryOperator::ReverseBits => write!(f, "r"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user