Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Hoffmann <[email protected]>
  • Loading branch information
antiguru committed May 30, 2024
1 parent 1f92fbc commit d5460fd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/impls/offsets.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Types to represent offsets.
use crate::impls::storage::Storage;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use crate::impls::storage::Storage;

/// A container to store offsets.
pub trait OffsetContainer<T>: Default + Extend<T> {
Expand Down Expand Up @@ -139,7 +139,7 @@ impl OffsetStride {
/// A list of unsigned integers that uses `u32` elements as long as they are small enough, and switches to `u64` once they are not.
#[derive(Eq, PartialEq, Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct OffsetList<S: Storage<u32> = Vec<u32>, L: Storage<u64>= Vec<u64>> {
pub struct OffsetList<S: Storage<u32> = Vec<u32>, L: Storage<u64> = Vec<u64>> {
/// Offsets that fit within a `u32`.
pub smol: S,
/// Offsets that either do not fit in a `u32`, or are inserted after some offset that did not fit.
Expand All @@ -166,10 +166,12 @@ impl<S: Storage<u32>, L: Storage<u64>> OffsetList<S, L> {
if let Ok(smol) = offset.try_into() {
self.smol.extend(std::iter::once(smol));
} else {
self.chonk.extend(std::iter::once(offset.try_into().unwrap()));
self.chonk
.extend(std::iter::once(offset.try_into().unwrap()));
}
} else {
self.chonk.extend(std::iter::once(offset.try_into().unwrap()));
self.chonk
.extend(std::iter::once(offset.try_into().unwrap()));
}
}

Expand All @@ -181,10 +183,10 @@ impl<S: Storage<u32>, L: Storage<u64>> OffsetList<S, L> {
#[must_use]
pub fn index(&self, index: usize) -> usize {
if index < self.smol.len() {
self.smol.index(index, index+1)[0].try_into().unwrap()
self.smol.index(index, index + 1)[0].try_into().unwrap()
} else {
let index = index - self.smol.len();
self.chonk.index(index, index+1)[0].try_into().unwrap()
self.chonk.index(index, index + 1)[0].try_into().unwrap()
}
}
/// The number of offsets in the list.
Expand Down Expand Up @@ -220,7 +222,7 @@ impl<S: Storage<u32>, L: Storage<u64>> OffsetList<S, L> {
/// a regular offset list.
#[derive(Eq, PartialEq, Default, Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct OffsetOptimized<S: Storage<u32> = Vec<u32>, L: Storage<u64>= Vec<u64>> {
pub struct OffsetOptimized<S: Storage<u32> = Vec<u32>, L: Storage<u64> = Vec<u64>> {
strided: OffsetStride,
spilled: OffsetList<S, L>,
}
Expand Down Expand Up @@ -310,8 +312,8 @@ impl<T: Copy> OffsetContainer<T> for Vec<T> {
#[cfg(test)]
mod tests {
use crate::impls::deduplicate::ConsecutiveOffsetPairs;
use crate::{Push, Region, SliceRegion, StringRegion};
use crate::impls::storage::Doubling;
use crate::{Push, Region, SliceRegion, StringRegion};

use super::*;

Expand Down
6 changes: 5 additions & 1 deletion src/impls/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ impl<T> Storage<T> for Doubling<T> {
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) -> usize {
let mut iter = iter.into_iter().peekable();
while iter.peek().is_some() {
if let Some(last) = self.inner.last_mut().filter(|last| last.len() < last.capacity()) {
if let Some(last) = self
.inner
.last_mut()
.filter(|last| last.len() < last.capacity())
{
Extend::extend(last, (&mut iter).take(last.capacity() - last.len()));
}
let (lo, hi) = iter.size_hint();
Expand Down

0 comments on commit d5460fd

Please sign in to comment.