Skip to content

Commit d4608a9

Browse files
Addressed comments.
1 parent 37ac558 commit d4608a9

File tree

3 files changed

+57
-57
lines changed

3 files changed

+57
-57
lines changed
File renamed without changes.

rust/arrow/src/buffer/mod.rs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,52 @@
1818
//! This module contains two main structs: [Buffer] and [MutableBuffer]. A buffer represents
1919
//! a contiguous memory region that can be shared via `offsets`.
2020
21-
mod immutable;
22-
pub use immutable::*;
21+
mod buffer;
22+
pub use buffer::*;
2323
mod mutable;
2424
pub use mutable::*;
2525
mod ops;
26-
pub(super) use ops::*;
26+
pub(crate) use ops::{buffer_bin_and, buffer_bin_or, buffer_unary_not};
27+
28+
use crate::error::{ArrowError, Result};
29+
use std::ops::{BitAnd, BitOr, Not};
30+
31+
impl<'a, 'b> BitAnd<&'b Buffer> for &'a Buffer {
32+
type Output = Result<Buffer>;
33+
34+
fn bitand(self, rhs: &'b Buffer) -> Result<Buffer> {
35+
if self.len() != rhs.len() {
36+
return Err(ArrowError::ComputeError(
37+
"Buffers must be the same size to apply Bitwise AND.".to_string(),
38+
));
39+
}
40+
41+
let len_in_bits = self.len() * 8;
42+
Ok(ops::buffer_bin_and(&self, 0, &rhs, 0, len_in_bits))
43+
}
44+
}
45+
46+
impl<'a, 'b> BitOr<&'b Buffer> for &'a Buffer {
47+
type Output = Result<Buffer>;
48+
49+
fn bitor(self, rhs: &'b Buffer) -> Result<Buffer> {
50+
if self.len() != rhs.len() {
51+
return Err(ArrowError::ComputeError(
52+
"Buffers must be the same size to apply Bitwise OR.".to_string(),
53+
));
54+
}
55+
56+
let len_in_bits = self.len() * 8;
57+
58+
Ok(ops::buffer_bin_or(&self, 0, &rhs, 0, len_in_bits))
59+
}
60+
}
61+
62+
impl Not for &Buffer {
63+
type Output = Buffer;
64+
65+
fn not(self) -> Buffer {
66+
let len_in_bits = self.len() * 8;
67+
ops::buffer_unary_not(&self, 0, len_in_bits)
68+
}
69+
}

rust/arrow/src/buffer/ops.rs

Lines changed: 11 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ use crate::util::bit_util;
2020
#[cfg(feature = "simd")]
2121
use packed_simd::u8x64;
2222

23-
use std::ops::{BitAnd, BitOr, Not};
24-
2523
#[cfg(feature = "avx512")]
2624
use crate::arch::avx512::*;
27-
use crate::error::{ArrowError, Result};
2825
use crate::util::bit_util::ceil;
2926
#[cfg(any(feature = "simd", feature = "avx512"))]
3027
use std::borrow::BorrowMut;
@@ -37,7 +34,7 @@ use super::{Buffer, MutableBuffer};
3734
/// Contrary to the non-simd version `bitwise_bin_op_helper`, the offset and length is specified in bytes
3835
/// and this version does not support operations starting at arbitrary bit offsets.
3936
#[cfg(simd)]
40-
pub fn bitwise_bin_op_simd_helper<F_SIMD, F_SCALAR>(
37+
fn bitwise_bin_op_simd_helper<F_SIMD, F_SCALAR>(
4138
left: &Buffer,
4239
left_offset: usize,
4340
right: &Buffer,
@@ -86,7 +83,7 @@ where
8683
/// Contrary to the non-simd version `bitwise_unary_op_helper`, the offset and length is specified in bytes
8784
/// and this version does not support operations starting at arbitrary bit offsets.
8885
#[cfg(simd)]
89-
pub fn bitwise_unary_op_simd_helper<F_SIMD, F_SCALAR>(
86+
fn bitwise_unary_op_simd_helper<F_SIMD, F_SCALAR>(
9087
left: &Buffer,
9188
left_offset: usize,
9289
len: usize,
@@ -125,7 +122,7 @@ where
125122

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

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

191188
#[cfg(all(target_arch = "x86_64", feature = "avx512"))]
192-
pub fn buffer_bin_and(
189+
pub(crate) fn buffer_bin_and(
193190
left: &Buffer,
194191
left_offset_in_bits: usize,
195192
right: &Buffer,
@@ -247,7 +244,7 @@ pub fn buffer_bin_and(
247244
}
248245

249246
#[cfg(all(feature = "simd", not(feature = "avx512")))]
250-
pub fn buffer_bin_and(
247+
pub(crate) fn buffer_bin_and(
251248
left: &Buffer,
252249
left_offset_in_bits: usize,
253250
right: &Buffer,
@@ -282,7 +279,7 @@ pub fn buffer_bin_and(
282279
// Note: do not target specific features like x86 without considering
283280
// other targets like wasm32, as those would fail to build
284281
#[cfg(all(not(any(feature = "simd", feature = "avx512"))))]
285-
pub fn buffer_bin_and(
282+
pub(crate) fn buffer_bin_and(
286283
left: &Buffer,
287284
left_offset_in_bits: usize,
288285
right: &Buffer,
@@ -300,7 +297,7 @@ pub fn buffer_bin_and(
300297
}
301298

302299
#[cfg(all(target_arch = "x86_64", feature = "avx512"))]
303-
pub fn buffer_bin_or(
300+
pub(crate) fn buffer_bin_or(
304301
left: &Buffer,
305302
left_offset_in_bits: usize,
306303
right: &Buffer,
@@ -358,7 +355,7 @@ pub fn buffer_bin_or(
358355
}
359356

360357
#[cfg(all(feature = "simd", not(feature = "avx512")))]
361-
pub fn buffer_bin_or(
358+
pub(crate) fn buffer_bin_or(
362359
left: &Buffer,
363360
left_offset_in_bits: usize,
364361
right: &Buffer,
@@ -391,7 +388,7 @@ pub fn buffer_bin_or(
391388
}
392389

393390
#[cfg(all(not(any(feature = "simd", feature = "avx512"))))]
394-
pub fn buffer_bin_or(
391+
pub(crate) fn buffer_bin_or(
395392
left: &Buffer,
396393
left_offset_in_bits: usize,
397394
right: &Buffer,
@@ -408,7 +405,7 @@ pub fn buffer_bin_or(
408405
)
409406
}
410407

411-
pub fn buffer_unary_not(
408+
pub(crate) fn buffer_unary_not(
412409
left: &Buffer,
413410
offset_in_bits: usize,
414411
len_in_bits: usize,
@@ -430,43 +427,3 @@ pub fn buffer_unary_not(
430427
bitwise_unary_op_helper(&left, offset_in_bits, len_in_bits, |a| !a)
431428
}
432429
}
433-
434-
impl<'a, 'b> BitAnd<&'b Buffer> for &'a Buffer {
435-
type Output = Result<Buffer>;
436-
437-
fn bitand(self, rhs: &'b Buffer) -> Result<Buffer> {
438-
if self.len() != rhs.len() {
439-
return Err(ArrowError::ComputeError(
440-
"Buffers must be the same size to apply Bitwise AND.".to_string(),
441-
));
442-
}
443-
444-
let len_in_bits = self.len() * 8;
445-
Ok(buffer_bin_and(&self, 0, &rhs, 0, len_in_bits))
446-
}
447-
}
448-
449-
impl<'a, 'b> BitOr<&'b Buffer> for &'a Buffer {
450-
type Output = Result<Buffer>;
451-
452-
fn bitor(self, rhs: &'b Buffer) -> Result<Buffer> {
453-
if self.len() != rhs.len() {
454-
return Err(ArrowError::ComputeError(
455-
"Buffers must be the same size to apply Bitwise OR.".to_string(),
456-
));
457-
}
458-
459-
let len_in_bits = self.len() * 8;
460-
461-
Ok(buffer_bin_or(&self, 0, &rhs, 0, len_in_bits))
462-
}
463-
}
464-
465-
impl Not for &Buffer {
466-
type Output = Buffer;
467-
468-
fn not(self) -> Buffer {
469-
let len_in_bits = self.len() * 8;
470-
buffer_unary_not(&self, 0, len_in_bits)
471-
}
472-
}

0 commit comments

Comments
 (0)