use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Sub, SubAssign};
use crate::{BitField, RangeIterator};
impl BitOr<&BitField> for &BitField {
type Output = BitField;
#[inline]
fn bitor(self, rhs: &BitField) -> Self::Output {
if self.is_trivially_empty() {
rhs.clone()
} else if rhs.is_trivially_empty() {
self.clone()
} else {
BitField::from_ranges(self.ranges().union(rhs.ranges()))
}
}
}
impl BitOr<BitField> for BitField {
type Output = BitField;
#[inline]
fn bitor(self, rhs: BitField) -> Self::Output {
if self.is_trivially_empty() {
rhs
} else if rhs.is_trivially_empty() {
self
} else {
BitField::from_ranges(self.ranges().union(rhs.ranges()))
}
}
}
impl BitOr<BitField> for &BitField {
type Output = BitField;
#[inline]
fn bitor(self, rhs: BitField) -> Self::Output {
if self.is_trivially_empty() {
rhs
} else if rhs.is_trivially_empty() {
self.clone()
} else {
BitField::from_ranges(self.ranges().union(rhs.ranges()))
}
}
}
impl BitOr<&BitField> for BitField {
type Output = BitField;
#[inline]
fn bitor(self, rhs: &BitField) -> Self::Output {
rhs | self
}
}
impl BitOrAssign<&BitField> for BitField {
#[inline]
fn bitor_assign(&mut self, rhs: &BitField) {
*self = std::mem::take(self) | rhs;
}
}
impl BitOrAssign<BitField> for BitField {
#[inline]
fn bitor_assign(&mut self, rhs: BitField) {
*self = std::mem::take(self) | rhs;
}
}
impl BitAnd<&BitField> for &BitField {
type Output = BitField;
#[inline]
fn bitand(self, rhs: &BitField) -> Self::Output {
if self.is_trivially_empty() || rhs.is_trivially_empty() {
BitField::new()
} else {
BitField::from_ranges(self.ranges().intersection(rhs.ranges()))
}
}
}
impl BitAnd<BitField> for BitField {
type Output = BitField;
#[inline]
fn bitand(self, rhs: BitField) -> Self::Output {
&self & &rhs
}
}
impl BitAnd<BitField> for &BitField {
type Output = BitField;
#[inline]
fn bitand(self, rhs: BitField) -> Self::Output {
self & &rhs
}
}
impl BitAnd<&BitField> for BitField {
type Output = BitField;
#[inline]
fn bitand(self, rhs: &BitField) -> Self::Output {
&self & rhs
}
}
impl BitAndAssign<&BitField> for BitField {
#[inline]
fn bitand_assign(&mut self, rhs: &BitField) {
*self = &*self & rhs;
}
}
impl BitAndAssign<BitField> for BitField {
#[inline]
fn bitand_assign(&mut self, rhs: BitField) {
*self = &*self & &rhs;
}
}
impl Sub<&BitField> for &BitField {
type Output = BitField;
#[inline]
fn sub(self, rhs: &BitField) -> Self::Output {
if self.is_trivially_empty() || rhs.is_trivially_empty() {
self.clone()
} else {
BitField::from_ranges(self.ranges().difference(rhs.ranges()))
}
}
}
impl Sub<BitField> for BitField {
type Output = BitField;
#[inline]
fn sub(self, rhs: BitField) -> Self::Output {
self - &rhs
}
}
impl Sub<&BitField> for BitField {
type Output = BitField;
#[inline]
fn sub(self, rhs: &BitField) -> Self::Output {
if self.is_trivially_empty() || rhs.is_trivially_empty() {
self
} else {
BitField::from_ranges(self.ranges().difference(rhs.ranges()))
}
}
}
impl Sub<BitField> for &BitField {
type Output = BitField;
#[inline]
fn sub(self, rhs: BitField) -> Self::Output {
self - &rhs
}
}
impl SubAssign<&BitField> for BitField {
#[inline]
fn sub_assign(&mut self, rhs: &BitField) {
*self = std::mem::take(self) - rhs;
}
}
impl SubAssign<BitField> for BitField {
#[inline]
fn sub_assign(&mut self, rhs: BitField) {
*self = std::mem::take(self) - rhs;
}
}
impl BitXor<&BitField> for &BitField {
type Output = BitField;
#[inline]
fn bitxor(self, rhs: &BitField) -> Self::Output {
if self.is_trivially_empty() {
rhs.clone()
} else if rhs.is_trivially_empty() {
self.clone()
} else {
BitField::from_ranges(self.ranges().symmetric_difference(rhs.ranges()))
}
}
}
impl BitXor<BitField> for BitField {
type Output = BitField;
#[inline]
fn bitxor(self, rhs: BitField) -> Self::Output {
if self.is_trivially_empty() {
rhs
} else if rhs.is_trivially_empty() {
self
} else {
BitField::from_ranges(self.ranges().symmetric_difference(rhs.ranges()))
}
}
}
impl BitXor<BitField> for &BitField {
type Output = BitField;
#[inline]
fn bitxor(self, rhs: BitField) -> Self::Output {
if self.is_trivially_empty() {
rhs
} else if rhs.is_trivially_empty() {
self.clone()
} else {
BitField::from_ranges(self.ranges().symmetric_difference(rhs.ranges()))
}
}
}
impl BitXor<&BitField> for BitField {
type Output = BitField;
#[inline]
fn bitxor(self, rhs: &BitField) -> Self::Output {
rhs ^ self
}
}
impl BitXorAssign<&BitField> for BitField {
#[inline]
fn bitxor_assign(&mut self, rhs: &BitField) {
*self = std::mem::take(self) ^ rhs;
}
}
impl BitXorAssign<BitField> for BitField {
#[inline]
fn bitxor_assign(&mut self, rhs: BitField) {
*self = std::mem::take(self) ^ rhs;
}
}