Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
b41sh committed Nov 9, 2023
1 parent d95bd1b commit 976ada2
Show file tree
Hide file tree
Showing 34 changed files with 169 additions and 30 deletions.
8 changes: 7 additions & 1 deletion src/array/binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ impl<O: Offset> BinaryArray<O> {
self.offsets.len_proxy()
}

/// Returns `true` if the array has a length of 0.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// Returns the element at index `i`
/// # Panics
/// iff `i >= self.len()`
Expand Down Expand Up @@ -212,7 +218,7 @@ impl<O: Offset> BinaryArray<O> {
pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) {
self.validity.as_mut().and_then(|bitmap| {
bitmap.slice_unchecked(offset, length);
(bitmap.unset_bits() > 0).then(|| bitmap)
(bitmap.unset_bits() > 0).then_some(bitmap)
});
self.offsets.slice_unchecked(offset, length + 1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/array/binary/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<O: Offset> MutableBinaryArray<O> {
let value = self.values.pop()?;
self.validity
.as_mut()
.map(|x| x.pop()?.then(|| ()))
.map(|x| x.pop()?.then_some(()))
.unwrap_or_else(|| Some(()))
.map(|_| value)
}
Expand Down
8 changes: 7 additions & 1 deletion src/array/binary/mutable_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ impl<O: Offset> MutableBinaryValuesArray<O> {
self.offsets.len_proxy()
}

/// Returns `true` if the array has a length of 0.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// Pushes a new item to the array.
/// # Panic
/// This operation panics iff the length of all values (in bytes) exceeds `O` maximum value.
Expand All @@ -143,7 +149,7 @@ impl<O: Offset> MutableBinaryValuesArray<O> {
/// Pop the last entry from [`MutableBinaryValuesArray`].
/// This function returns `None` iff this array is empty.
pub fn pop(&mut self) -> Option<Vec<u8>> {
if self.len() == 0 {
if self.is_empty() {
return None;
}
self.offsets.pop()?;
Expand Down
2 changes: 1 addition & 1 deletion src/array/boolean/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl IntoIterator for BooleanArray {
let (_, values, validity) = self.into_inner();
let values = values.into_iter();
let validity =
validity.and_then(|validity| (validity.unset_bits() > 0).then(|| validity.into_iter()));
validity.and_then(|validity| (validity.unset_bits() > 0).then_some(validity.into_iter()));
ZipValidity::new(values, validity)
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/array/boolean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ impl BooleanArray {
self.values.len()
}

/// Returns `true` if the array has a length of 0.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// The values [`Bitmap`].
/// Values on null slots are undetermined (they can be anything).
#[inline]
Expand Down Expand Up @@ -181,7 +187,7 @@ impl BooleanArray {
pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) {
self.validity.as_mut().and_then(|bitmap| {
bitmap.slice_unchecked(offset, length);
(bitmap.unset_bits() > 0).then(|| bitmap)
(bitmap.unset_bits() > 0).then_some(bitmap)
});
self.values.slice_unchecked(offset, length);
}
Expand Down
2 changes: 1 addition & 1 deletion src/array/boolean/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl MutableBooleanArray {
let value = self.values.pop()?;
self.validity
.as_mut()
.map(|x| x.pop()?.then(|| value))
.map(|x| x.pop()?.then_some(value))
.unwrap_or_else(|| Some(value))
}

Expand Down
7 changes: 7 additions & 0 deletions src/array/dictionary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ impl<K: DictionaryKey> DictionaryArray<K> {
/// # Panics
///
/// This function panics if the `values` array
#[allow(clippy::type_complexity)]
pub fn iter_typed<V: DictValue>(
&self,
) -> Result<ZipValidity<V::IterValue<'_>, DictionaryValuesIterTyped<K, V>, BitmapIter>, Error>
Expand Down Expand Up @@ -335,6 +336,12 @@ impl<K: DictionaryKey> DictionaryArray<K> {
self.keys.len()
}

/// Returns `true` if the array has a length of 0.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// The optional validity. Equivalent to `self.keys().validity()`.
#[inline]
pub fn validity(&self) -> Option<&Bitmap> {
Expand Down
8 changes: 7 additions & 1 deletion src/array/fixed_size_binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl FixedSizeBinaryArray {
pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) {
self.validity.as_mut().and_then(|bitmap| {
bitmap.slice_unchecked(offset, length);
(bitmap.unset_bits() > 0).then(|| bitmap)
(bitmap.unset_bits() > 0).then_some(bitmap)
});
self.values
.slice_unchecked(offset * self.size, length * self.size);
Expand All @@ -129,6 +129,12 @@ impl FixedSizeBinaryArray {
self.values.len() / self.size
}

/// Returns `true` if the array has a length of 0.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// The optional validity.
#[inline]
pub fn validity(&self) -> Option<&Bitmap> {
Expand Down
8 changes: 7 additions & 1 deletion src/array/fixed_size_binary/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ impl MutableFixedSizeBinaryArray {
self.values.len() / self.size
}

/// Returns `true` if the array has a length of 0.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// Pop the last entry from [`MutableFixedSizeBinaryArray`].
/// This function returns `None` iff this array is empty
pub fn pop(&mut self) -> Option<Vec<u8>> {
Expand All @@ -159,7 +165,7 @@ impl MutableFixedSizeBinaryArray {
let value = self.values.split_off(value_start);
self.validity
.as_mut()
.map(|x| x.pop()?.then(|| ()))
.map(|x| x.pop()?.then_some(()))
.unwrap_or_else(|| Some(()))
.map(|_| value)
}
Expand Down
8 changes: 7 additions & 1 deletion src/array/fixed_size_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl FixedSizeListArray {
pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) {
self.validity.as_mut().and_then(|bitmap| {
bitmap.slice_unchecked(offset, length);
(bitmap.unset_bits() > 0).then(|| bitmap)
(bitmap.unset_bits() > 0).then_some(bitmap)
});
self.values
.slice_unchecked(offset * self.size, length * self.size);
Expand All @@ -142,6 +142,12 @@ impl FixedSizeListArray {
self.values.len() / self.size
}

/// Returns `true` if the array has a length of 0.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// The optional validity.
#[inline]
pub fn validity(&self) -> Option<&Bitmap> {
Expand Down
6 changes: 6 additions & 0 deletions src/array/fixed_size_list/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ impl<M: MutableArray> MutableFixedSizeListArray<M> {
self.values.len() / self.size
}

/// Returns `true` if the array has a length of 0.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// The inner values
pub fn values(&self) -> &M {
&self.values
Expand Down
2 changes: 2 additions & 0 deletions src/array/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use super::Array;
/// Returns a function that writes the value of the element of `array`
/// at position `index` to a [`Write`],
/// writing `null` in the null slots.
#[allow(clippy::type_complexity)]
pub fn get_value_display<'a, F: Write + 'a>(
array: &'a dyn Array,
null: &'static str,
Expand Down Expand Up @@ -101,6 +102,7 @@ pub fn get_value_display<'a, F: Write + 'a>(

/// Returns a function that writes the element of `array`
/// at position `index` to a [`Write`], writing `null` to the null slots.
#[allow(clippy::type_complexity)]
pub fn get_display<'a, F: Write + 'a>(
array: &'a dyn Array,
null: &'static str,
Expand Down
5 changes: 5 additions & 0 deletions src/array/growable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ pub trait Growable<'a> {
/// The current length of the [`Growable`].
fn len(&self) -> usize;

/// Returns `true` if the length of the [`Growable`] is 0.
fn is_empty(&self) -> bool {
self.len() == 0
}

/// Converts this [`Growable`] to an [`Arc<dyn Array>`], thereby finishing the mutation.
/// Self will be empty after such operation.
fn as_arc(&mut self) -> Arc<dyn Array> {
Expand Down
8 changes: 7 additions & 1 deletion src/array/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<O: Offset> ListArray<O> {
pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) {
self.validity.as_mut().and_then(|bitmap| {
bitmap.slice_unchecked(offset, length);
(bitmap.unset_bits() > 0).then(|| bitmap)
(bitmap.unset_bits() > 0).then_some(bitmap)
});
self.offsets.slice_unchecked(offset, length + 1);
}
Expand All @@ -143,6 +143,12 @@ impl<O: Offset> ListArray<O> {
self.offsets.len_proxy()
}

/// Returns `true` if the array has a length of 0.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// Returns the element at index `i`
/// # Panic
/// Panics iff `i >= self.len()`
Expand Down
6 changes: 6 additions & 0 deletions src/array/list/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ impl<O: Offset, M: MutableArray> MutableListArray<O, M> {
self.offsets.len_proxy()
}

/// Returns `true` if the array has a length of 0.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// The values
pub fn mut_values(&mut self) -> &mut M {
&mut self.values
Expand Down
8 changes: 7 additions & 1 deletion src/array/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl MapArray {
pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) {
self.validity.as_mut().and_then(|bitmap| {
bitmap.slice_unchecked(offset, length);
(bitmap.unset_bits() > 0).then(|| bitmap)
(bitmap.unset_bits() > 0).then_some(bitmap)
});
self.offsets.slice_unchecked(offset, length + 1);
}
Expand Down Expand Up @@ -159,6 +159,12 @@ impl MapArray {
self.offsets.len_proxy()
}

/// Returns `true` if the array has a length of 0.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// returns the offsets
#[inline]
pub fn offsets(&self) -> &OffsetsBuffer<i32> {
Expand Down
1 change: 1 addition & 0 deletions src/array/primitive/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ macro_rules! dyn_primitive {
}};
}

#[allow(clippy::type_complexity)]
pub fn get_write_value<'a, T: NativeType, F: Write>(
array: &'a PrimitiveArray<T>,
) -> Box<dyn Fn(&mut F, usize) -> Result + 'a> {
Expand Down
2 changes: 1 addition & 1 deletion src/array/primitive/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl<T: NativeType> IntoIterator for PrimitiveArray<T> {
let (_, values, validity) = self.into_inner();
let values = values.into_iter();
let validity =
validity.and_then(|validity| (validity.unset_bits() > 0).then(|| validity.into_iter()));
validity.and_then(|validity| (validity.unset_bits() > 0).then_some(validity.into_iter()));
ZipValidity::new(values, validity)
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/array/primitive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ impl<T: NativeType> PrimitiveArray<T> {
self.values.len()
}

/// Returns `true` if the array has a length of 0.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// The values [`Buffer`].
/// Values on null slots are undetermined (they can be anything).
#[inline]
Expand Down Expand Up @@ -232,7 +238,7 @@ impl<T: NativeType> PrimitiveArray<T> {
pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) {
self.validity.as_mut().and_then(|bitmap| {
bitmap.slice_unchecked(offset, length);
(bitmap.unset_bits() > 0).then(|| bitmap)
(bitmap.unset_bits() > 0).then_some(bitmap)
});
self.values.slice_unchecked(offset, length);
}
Expand Down
2 changes: 1 addition & 1 deletion src/array/primitive/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl<T: NativeType> MutablePrimitiveArray<T> {
let value = self.values.pop()?;
self.validity
.as_mut()
.map(|x| x.pop()?.then(|| value))
.map(|x| x.pop()?.then_some(value))
.unwrap_or_else(|| Some(value))
}

Expand Down
2 changes: 1 addition & 1 deletion src/array/specification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub(crate) fn try_check_utf8<O: Offset, C: OffsetsContainer<O>>(
.enumerate()
.skip(1)
.rev()
.find_map(|(i, offset)| (offset.to_usize() < values.len()).then(|| i));
.find_map(|(i, offset)| (offset.to_usize() < values.len()).then_some(i));

let last = if let Some(last) = last {
// following the example: last = 1 (offset = 5)
Expand Down
2 changes: 1 addition & 1 deletion src/array/struct_/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl StructArray {
pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) {
self.validity.as_mut().and_then(|bitmap| {
bitmap.slice_unchecked(offset, length);
(bitmap.unset_bits() > 0).then(|| bitmap)
(bitmap.unset_bits() > 0).then_some(bitmap)
});
self.values
.iter_mut()
Expand Down
6 changes: 6 additions & 0 deletions src/array/union/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ impl UnionArray {
self.types.len()
}

/// Returns `true` if the array has a length of 0.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// The optional offsets.
pub fn offsets(&self) -> Option<&Buffer<i32>> {
self.offsets.as_ref()
Expand Down
8 changes: 7 additions & 1 deletion src/array/utf8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ impl<O: Offset> Utf8Array<O> {
self.offsets.len_proxy()
}

/// Returns `true` if the array has a length of 0.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// Returns the value of the element at index `i`, ignoring the array's validity.
/// # Panic
/// This function panics iff `i >= self.len`.
Expand Down Expand Up @@ -231,7 +237,7 @@ impl<O: Offset> Utf8Array<O> {
pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) {
self.validity.as_mut().and_then(|bitmap| {
bitmap.slice_unchecked(offset, length);
(bitmap.unset_bits() > 0).then(|| bitmap)
(bitmap.unset_bits() > 0).then_some(bitmap)
});
self.offsets.slice_unchecked(offset, length + 1);
}
Expand Down
Loading

0 comments on commit 976ada2

Please sign in to comment.