Skip to content

Commit

Permalink
Rename CopyIter to PushIter (#50)
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Hoffmann <[email protected]>
  • Loading branch information
antiguru authored Jul 2, 2024
1 parent bc4b8e9 commit 484b57e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
28 changes: 14 additions & 14 deletions src/impls/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};

use crate::impls::deduplicate::ConsecutiveOffsetPairs;
use crate::impls::offsets::{OffsetContainer, OffsetOptimized};
use crate::{CopyIter, IntoOwned};
use crate::{IntoOwned, PushIter};
use crate::{OwnedRegion, Push, Region};

/// A region that can store a variable number of elements per row.
Expand Down Expand Up @@ -388,7 +388,7 @@ where
.iter()
.zip(&mut self.inner)
.map(|(value, region)| region.push(value));
self.indices.push(CopyIter(iter))
self.indices.push(PushIter(iter))
}
}

Expand All @@ -407,7 +407,7 @@ where
.iter()
.zip(&mut self.inner)
.map(|(value, region)| region.push(value));
self.indices.push(CopyIter(iter))
self.indices.push(PushIter(iter))
}
}

Expand All @@ -426,7 +426,7 @@ where
.into_iter()
.zip(&mut self.inner)
.map(|(value, region)| region.push(value));
self.indices.push(CopyIter(iter))
self.indices.push(PushIter(iter))
}
}

Expand All @@ -445,7 +445,7 @@ where
.iter()
.zip(&mut self.inner)
.map(|(value, region)| region.push(value));
self.indices.push(CopyIter(iter))
self.indices.push(PushIter(iter))
}
}

Expand All @@ -464,7 +464,7 @@ where
.into_iter()
.zip(&mut self.inner)
.map(|(value, region)| region.push(value));
self.indices.push(CopyIter(iter))
self.indices.push(PushIter(iter))
}
}

Expand All @@ -483,34 +483,34 @@ where
.iter()
.zip(&mut self.inner)
.map(|(value, region)| region.push(value));
self.indices.push(CopyIter(iter))
self.indices.push(PushIter(iter))
}
}

impl<R, O, T, I> Push<CopyIter<I>> for ColumnsRegion<R, O>
impl<R, O, T, I> Push<PushIter<I>> for ColumnsRegion<R, O>
where
R: Region + Push<T>,
O: OffsetContainer<usize>,
I: IntoIterator<Item = T>,
I::IntoIter: ExactSizeIterator,
{
#[inline]
fn push(&mut self, item: CopyIter<I>) -> <ColumnsRegion<R, O> as Region>::Index {
fn push(&mut self, item: PushIter<I>) -> <ColumnsRegion<R, O> as Region>::Index {
let iter = item.0.into_iter().enumerate().map(|(index, value)| {
// Ensure all required regions exist.
if self.inner.len() <= index {
self.inner.push(R::default());
}
self.inner[index].push(value)
});
self.indices.push(CopyIter(iter))
self.indices.push(PushIter(iter))
}
}

#[cfg(test)]
mod tests {
use crate::impls::deduplicate::{CollapseSequence, ConsecutiveOffsetPairs};
use crate::{CopyIter, MirrorRegion, OwnedRegion, Push, Region, StringRegion};
use crate::{MirrorRegion, OwnedRegion, Push, PushIter, Region, StringRegion};

use super::*;

Expand Down Expand Up @@ -634,7 +634,7 @@ mod tests {
let mut indices = Vec::with_capacity(data.len());

for row in &data {
let index = r.push(CopyIter(row.iter()));
let index = r.push(PushIter(row.iter()));
indices.push(index);
}

Expand Down Expand Up @@ -716,7 +716,7 @@ mod tests {
let mut r = ColumnsRegion::<ConsecutiveOffsetPairs<StringRegion>>::default();

for row in &data {
let _ = r.push(CopyIter(row.iter()));
let _ = r.push(PushIter(row.iter()));
}

let (mut siz1, mut cap1) = (0, 0);
Expand All @@ -727,7 +727,7 @@ mod tests {

let mut r2 = ColumnsRegion::merge_regions(std::iter::once(&r));
for row in &data {
let _ = r2.push(CopyIter(row.iter()));
let _ = r2.push(PushIter(row.iter()));
}

let (mut siz2, mut cap2) = (0, 0);
Expand Down
22 changes: 11 additions & 11 deletions src/impls/slice_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::marker::PhantomData;
use serde::{Deserialize, Serialize};

use crate::impls::storage::{PushStorage, Storage};
use crate::{CopyIter, Push, Region, ReserveItems};
use crate::{Push, PushIter, Region, ReserveItems};

/// A container for owned types.
///
Expand Down Expand Up @@ -117,13 +117,13 @@ impl<T, S, const N: usize> Push<[T; N]> for OwnedRegion<T, S>
where
[T]: ToOwned,
S: Storage<T>
+ for<'a> PushStorage<CopyIter<[T; N]>>
+ for<'a> PushStorage<PushIter<[T; N]>>
+ std::ops::Index<std::ops::Range<usize>, Output = [T]>,
{
#[inline]
fn push(&mut self, item: [T; N]) -> <OwnedRegion<T> as Region>::Index {
let start = self.slices.len();
self.slices.push_storage(CopyIter(item));
self.slices.push_storage(PushIter(item));
(start, self.slices.len())
}
}
Expand Down Expand Up @@ -249,24 +249,24 @@ where
}
}

impl<T, S, I> Push<CopyIter<I>> for OwnedRegion<T, S>
impl<T, S, I> Push<PushIter<I>> for OwnedRegion<T, S>
where
I: IntoIterator<Item = T>,
<I as IntoIterator>::IntoIter: ExactSizeIterator,
T: Clone,
S: Storage<T>
+ PushStorage<CopyIter<I>>
+ PushStorage<PushIter<I>>
+ std::ops::Index<std::ops::Range<usize>, Output = [T]>,
{
#[inline]
fn push(&mut self, item: CopyIter<I>) -> <OwnedRegion<T, S> as Region>::Index {
fn push(&mut self, item: PushIter<I>) -> <OwnedRegion<T, S> as Region>::Index {
let start = self.slices.len();
self.slices.push_storage(item);
(start, self.slices.len())
}
}

impl<T, S, J> ReserveItems<CopyIter<J>> for OwnedRegion<T, S>
impl<T, S, J> ReserveItems<PushIter<J>> for OwnedRegion<T, S>
where
[T]: ToOwned,
S: Storage<T> + std::ops::Index<std::ops::Range<usize>, Output = [T]>,
Expand All @@ -275,7 +275,7 @@ where
#[inline]
fn reserve_items<I>(&mut self, items: I)
where
I: Iterator<Item = CopyIter<J>> + Clone,
I: Iterator<Item = PushIter<J>> + Clone,
{
self.slices
.reserve(items.flat_map(|i| i.0.into_iter()).count());
Expand All @@ -284,7 +284,7 @@ where

#[cfg(test)]
mod tests {
use crate::{CopyIter, Push, Region, ReserveItems};
use crate::{Push, PushIter, Region, ReserveItems};

use super::*;

Expand Down Expand Up @@ -318,8 +318,8 @@ mod tests {
fn test_copy_iter() {
let mut r = <OwnedRegion<u8>>::default();
let iter = [1; 4].into_iter();
r.reserve_items(std::iter::once(CopyIter(iter.clone())));
let index = r.push(CopyIter(iter));
r.reserve_items(std::iter::once(PushIter(iter.clone())));
let index = r.push(PushIter(iter));
assert_eq!([1, 1, 1, 1], r.index(index));
}
}
6 changes: 3 additions & 3 deletions src/impls/storage.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Storage abstractions to represent slices of data.
use crate::CopyIter;
use crate::PushIter;

/// Behavior to allocate storage.
///
Expand Down Expand Up @@ -105,9 +105,9 @@ impl<T: Clone> PushStorage<&[T]> for Vec<T> {
}
}

impl<I: IntoIterator<Item = T>, T> PushStorage<CopyIter<I>> for Vec<T> {
impl<I: IntoIterator<Item = T>, T> PushStorage<PushIter<I>> for Vec<T> {
#[inline]
fn push_storage(&mut self, item: CopyIter<I>) {
fn push_storage(&mut self, item: PushIter<I>) {
self.extend(item.0);
}
}
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,13 @@ impl<R: Clone, S: Clone> Clone for FlatStack<R, S> {
}
}

/// A type to wrap and copy iterators onto regions.
/// A type to wrap and push iterators into regions.
///
/// This only exists to avoid blanket implementations that might conflict with more specific
/// implementations offered by some regions.
#[repr(transparent)]
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd)]
pub struct CopyIter<I>(pub I);
pub struct PushIter<I>(pub I);

#[cfg(test)]
mod tests {
Expand Down

0 comments on commit 484b57e

Please sign in to comment.