Skip to content

Commit

Permalink
Addressed comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Feb 14, 2021
1 parent 37ac558 commit d4608a9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 57 deletions.
File renamed without changes.
49 changes: 46 additions & 3 deletions rust/arrow/src/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,52 @@
//! This module contains two main structs: [Buffer] and [MutableBuffer]. A buffer represents
//! a contiguous memory region that can be shared via `offsets`.

mod immutable;
pub use immutable::*;
mod buffer;
pub use buffer::*;
mod mutable;
pub use mutable::*;
mod ops;
pub(super) use ops::*;
pub(crate) use ops::{buffer_bin_and, buffer_bin_or, buffer_unary_not};

use crate::error::{ArrowError, Result};
use std::ops::{BitAnd, BitOr, Not};

impl<'a, 'b> BitAnd<&'b Buffer> for &'a Buffer {
type Output = Result<Buffer>;

fn bitand(self, rhs: &'b Buffer) -> Result<Buffer> {
if self.len() != rhs.len() {
return Err(ArrowError::ComputeError(
"Buffers must be the same size to apply Bitwise AND.".to_string(),
));
}

let len_in_bits = self.len() * 8;
Ok(ops::buffer_bin_and(&self, 0, &rhs, 0, len_in_bits))
}
}

impl<'a, 'b> BitOr<&'b Buffer> for &'a Buffer {
type Output = Result<Buffer>;

fn bitor(self, rhs: &'b Buffer) -> Result<Buffer> {
if self.len() != rhs.len() {
return Err(ArrowError::ComputeError(
"Buffers must be the same size to apply Bitwise OR.".to_string(),
));
}

let len_in_bits = self.len() * 8;

Ok(ops::buffer_bin_or(&self, 0, &rhs, 0, len_in_bits))
}
}

impl Not for &Buffer {
type Output = Buffer;

fn not(self) -> Buffer {
let len_in_bits = self.len() * 8;
ops::buffer_unary_not(&self, 0, len_in_bits)
}
}
65 changes: 11 additions & 54 deletions rust/arrow/src/buffer/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ use crate::util::bit_util;
#[cfg(feature = "simd")]
use packed_simd::u8x64;

use std::ops::{BitAnd, BitOr, Not};

#[cfg(feature = "avx512")]
use crate::arch::avx512::*;
use crate::error::{ArrowError, Result};
use crate::util::bit_util::ceil;
#[cfg(any(feature = "simd", feature = "avx512"))]
use std::borrow::BorrowMut;
Expand All @@ -37,7 +34,7 @@ use super::{Buffer, MutableBuffer};
/// Contrary to the non-simd version `bitwise_bin_op_helper`, the offset and length is specified in bytes
/// and this version does not support operations starting at arbitrary bit offsets.
#[cfg(simd)]
pub fn bitwise_bin_op_simd_helper<F_SIMD, F_SCALAR>(
fn bitwise_bin_op_simd_helper<F_SIMD, F_SCALAR>(
left: &Buffer,
left_offset: usize,
right: &Buffer,
Expand Down Expand Up @@ -86,7 +83,7 @@ where
/// Contrary to the non-simd version `bitwise_unary_op_helper`, the offset and length is specified in bytes
/// and this version does not support operations starting at arbitrary bit offsets.
#[cfg(simd)]
pub fn bitwise_unary_op_simd_helper<F_SIMD, F_SCALAR>(
fn bitwise_unary_op_simd_helper<F_SIMD, F_SCALAR>(
left: &Buffer,
left_offset: usize,
len: usize,
Expand Down Expand Up @@ -125,7 +122,7 @@ where

/// Apply a bitwise operation `op` to two inputs and return the result as a Buffer.
/// The inputs are treated as bitmaps, meaning that offsets and length are specified in number of bits.
pub fn bitwise_bin_op_helper<F>(
fn bitwise_bin_op_helper<F>(
left: &Buffer,
left_offset_in_bits: usize,
right: &Buffer,
Expand Down Expand Up @@ -157,7 +154,7 @@ where

/// Apply a bitwise operation `op` to one input and return the result as a Buffer.
/// The input is treated as a bitmap, meaning that offset and length are specified in number of bits.
pub fn bitwise_unary_op_helper<F>(
pub(super) fn bitwise_unary_op_helper<F>(
left: &Buffer,
offset_in_bits: usize,
len_in_bits: usize,
Expand Down Expand Up @@ -189,7 +186,7 @@ where
}

#[cfg(all(target_arch = "x86_64", feature = "avx512"))]
pub fn buffer_bin_and(
pub(crate) fn buffer_bin_and(
left: &Buffer,
left_offset_in_bits: usize,
right: &Buffer,
Expand Down Expand Up @@ -247,7 +244,7 @@ pub fn buffer_bin_and(
}

#[cfg(all(feature = "simd", not(feature = "avx512")))]
pub fn buffer_bin_and(
pub(crate) fn buffer_bin_and(
left: &Buffer,
left_offset_in_bits: usize,
right: &Buffer,
Expand Down Expand Up @@ -282,7 +279,7 @@ pub fn buffer_bin_and(
// Note: do not target specific features like x86 without considering
// other targets like wasm32, as those would fail to build
#[cfg(all(not(any(feature = "simd", feature = "avx512"))))]
pub fn buffer_bin_and(
pub(crate) fn buffer_bin_and(
left: &Buffer,
left_offset_in_bits: usize,
right: &Buffer,
Expand All @@ -300,7 +297,7 @@ pub fn buffer_bin_and(
}

#[cfg(all(target_arch = "x86_64", feature = "avx512"))]
pub fn buffer_bin_or(
pub(crate) fn buffer_bin_or(
left: &Buffer,
left_offset_in_bits: usize,
right: &Buffer,
Expand Down Expand Up @@ -358,7 +355,7 @@ pub fn buffer_bin_or(
}

#[cfg(all(feature = "simd", not(feature = "avx512")))]
pub fn buffer_bin_or(
pub(crate) fn buffer_bin_or(
left: &Buffer,
left_offset_in_bits: usize,
right: &Buffer,
Expand Down Expand Up @@ -391,7 +388,7 @@ pub fn buffer_bin_or(
}

#[cfg(all(not(any(feature = "simd", feature = "avx512"))))]
pub fn buffer_bin_or(
pub(crate) fn buffer_bin_or(
left: &Buffer,
left_offset_in_bits: usize,
right: &Buffer,
Expand All @@ -408,7 +405,7 @@ pub fn buffer_bin_or(
)
}

pub fn buffer_unary_not(
pub(crate) fn buffer_unary_not(
left: &Buffer,
offset_in_bits: usize,
len_in_bits: usize,
Expand All @@ -430,43 +427,3 @@ pub fn buffer_unary_not(
bitwise_unary_op_helper(&left, offset_in_bits, len_in_bits, |a| !a)
}
}

impl<'a, 'b> BitAnd<&'b Buffer> for &'a Buffer {
type Output = Result<Buffer>;

fn bitand(self, rhs: &'b Buffer) -> Result<Buffer> {
if self.len() != rhs.len() {
return Err(ArrowError::ComputeError(
"Buffers must be the same size to apply Bitwise AND.".to_string(),
));
}

let len_in_bits = self.len() * 8;
Ok(buffer_bin_and(&self, 0, &rhs, 0, len_in_bits))
}
}

impl<'a, 'b> BitOr<&'b Buffer> for &'a Buffer {
type Output = Result<Buffer>;

fn bitor(self, rhs: &'b Buffer) -> Result<Buffer> {
if self.len() != rhs.len() {
return Err(ArrowError::ComputeError(
"Buffers must be the same size to apply Bitwise OR.".to_string(),
));
}

let len_in_bits = self.len() * 8;

Ok(buffer_bin_or(&self, 0, &rhs, 0, len_in_bits))
}
}

impl Not for &Buffer {
type Output = Buffer;

fn not(self) -> Buffer {
let len_in_bits = self.len() * 8;
buffer_unary_not(&self, 0, len_in_bits)
}
}

0 comments on commit d4608a9

Please sign in to comment.