Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,26 @@ jobs:
command: fmt
args: --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
components: clippy
- name: Clippy check
uses: actions-rs/cargo@v1
with:
command: clippy
# add --all-targets to include tests
args: --all-features --workspace -- -D warnings
# clippy:
# name: Clippy
# runs-on: ubuntu-latest
# needs: test
# steps:
# - name: Checkout repository
# uses: actions/checkout@v2
# - name: Install Rust toolchain
# uses: actions-rs/toolchain@v1
# with:
# toolchain: stable
# profile: minimal
# override: true
# components: clippy
# - name: Clippy check
# uses: actions-rs/cargo@v1
# with:
# command: clippy
# # add --all-targets to include tests
# args: --all-features --workspace -- -D warnings

docs:
name: Docs
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "im-lists"
version = "0.11.4"
version = "0.12.0"
authors = ["mattwparas <matthewparas2020@u.northwestern.edu>"]
edition = "2021"
readme = "README.md"
Expand All @@ -15,6 +15,7 @@ categories = ["data-structures"]
[dependencies]
smallvec = { version = "1.10.0" }
generic_singleton = "0.5.1"
allocator-api2 = "0.2.4"

[dev-dependencies]
criterion = "0.3.5"
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pub mod handler;
pub mod list;
pub mod shared;
mod shared_vector;
pub(crate) mod unrolled;

/// Construct a [`List`](crate::list::List) from a sequence of elements
Expand Down
104 changes: 47 additions & 57 deletions src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ use crate::{
pub struct GenericList<
T: Clone + 'static,
P: PointerFamily = RcPointer,
const N: usize = 256,
const G: usize = 1,
const N: u32 = 256,
const G: u32 = 1,
D: DropHandler<Self> = DefaultDropHandler,
>(UnrolledList<T, P, N, G>, PhantomData<D>);

Expand All @@ -74,20 +74,20 @@ pub type VList<T> = GenericList<T, RcPointer, 2, 2>;
pub struct RawCell<
T: Clone + 'static,
P: PointerFamily,
const N: usize,
const G: usize,
const N: u32,
const G: u32,
D: DropHandler<GenericList<T, P, N, G, D>>,
>(*const UnrolledCell<T, P, N, G>, PhantomData<D>);

impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<Self>> Clone
impl<T: Clone, P: PointerFamily, const N: u32, const G: u32, D: DropHandler<Self>> Clone
for GenericList<T, P, N, G, D>
{
fn clone(&self) -> Self {
Self(self.0.clone(), PhantomData)
}
}

impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<Self>>
impl<T: Clone, P: PointerFamily, const N: u32, const G: u32, D: DropHandler<Self>>
GenericList<T, P, N, G, D>
{
/// Construct an empty list.
Expand All @@ -114,7 +114,7 @@ impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<

#[doc(hidden)]
pub fn index(&self) -> usize {
self.0.index()
self.0.index() as _
}

#[doc(hidden)]
Expand Down Expand Up @@ -145,12 +145,12 @@ impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<
#[doc(hidden)]
pub fn elements_as_ptr_usize(&self) -> usize {
// Overflow is fine - this should give us a unique value?
self.0.elements_as_ptr_usize() + self.0.index()
self.0.elements_as_ptr_usize() + self.0.index() as usize
}

#[doc(hidden)]
pub fn identity_tuple(&self) -> (usize, usize) {
(self.0.elements_as_ptr_usize(), self.0.index())
(self.0.elements_as_ptr_usize(), self.0.index() as _)
}

// Check the next pointer. If the next pointer is the same,
Expand Down Expand Up @@ -593,15 +593,15 @@ impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<
}
}

impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<Self>> Default
impl<T: Clone, P: PointerFamily, const N: u32, const G: u32, D: DropHandler<Self>> Default
for GenericList<T, P, N, G, D>
{
fn default() -> Self {
Self::new()
}
}

impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<Self>> Extend<T>
impl<T: Clone, P: PointerFamily, const N: u32, const G: u32, D: DropHandler<Self>> Extend<T>
for GenericList<T, P, N, G, D>
{
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
Expand All @@ -610,23 +610,23 @@ impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<
}

// and we'll implement FromIterator
impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<Self>>
FromIterator<T> for GenericList<T, P, N, G, D>
impl<T: Clone, P: PointerFamily, const N: u32, const G: u32, D: DropHandler<Self>> FromIterator<T>
for GenericList<T, P, N, G, D>
{
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
GenericList(iter.into_iter().collect(), PhantomData)
}
}

impl<'a, T: 'a + Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<Self>>
impl<'a, T: 'a + Clone, P: PointerFamily, const N: u32, const G: u32, D: DropHandler<Self>>
FromIterator<&'a T> for GenericList<T, P, N, G, D>
{
fn from_iter<I: IntoIterator<Item = &'a T>>(iter: I) -> Self {
GenericList(iter.into_iter().cloned().collect(), PhantomData)
}
}

impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<Self>>
impl<T: Clone, P: PointerFamily, const N: u32, const G: u32, D: DropHandler<Self>>
FromIterator<GenericList<T, P, N, G, D>> for GenericList<T, P, N, G, D>
{
fn from_iter<I: IntoIterator<Item = GenericList<T, P, N, G, D>>>(iter: I) -> Self {
Expand All @@ -639,7 +639,7 @@ impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<
}
}

impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<Self>> From<Vec<T>>
impl<T: Clone, P: PointerFamily, const N: u32, const G: u32, D: DropHandler<Self>> From<Vec<T>>
for GenericList<T, P, N, G, D>
{
fn from(vec: Vec<T>) -> Self {
Expand All @@ -650,8 +650,8 @@ impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<
impl<
T: Clone + std::fmt::Debug,
P: PointerFamily,
const N: usize,
const G: usize,
const N: u32,
const G: u32,
D: DropHandler<Self>,
> std::fmt::Debug for GenericList<T, P, N, G, D>
{
Expand All @@ -665,17 +665,17 @@ pub struct Iter<
'a,
T: Clone + 'static,
P: PointerFamily,
const N: usize,
const G: usize,
const N: u32,
const G: u32,
D: DropHandler<GenericList<T, P, N, G, D>>,
>(IterWrapper<'a, T, P, N, G>, PhantomData<D>);

impl<
'a,
T: Clone + 'static,
P: PointerFamily,
const N: usize,
const G: usize,
const N: u32,
const G: u32,
D: DropHandler<GenericList<T, P, N, G, D>>,
> Iterator for Iter<'a, T, P, N, G, D>
{
Expand Down Expand Up @@ -705,8 +705,8 @@ impl<
'a,
T: Clone,
P: PointerFamily,
const N: usize,
const G: usize,
const N: u32,
const G: u32,
D: DropHandler<GenericList<T, P, N, G, D>>,
> IntoIterator for &'a GenericList<T, P, N, G, D>
{
Expand All @@ -723,16 +723,16 @@ impl<
pub struct ConsumingIter<
T: Clone + 'static,
P: PointerFamily,
const N: usize,
const G: usize,
const N: u32,
const G: u32,
D: DropHandler<GenericList<T, P, N, G, D>>,
>(ConsumingWrapper<T, P, N, G>, PhantomData<D>);

impl<
T: Clone,
P: PointerFamily,
const N: usize,
const G: usize,
const N: u32,
const G: u32,
D: DropHandler<GenericList<T, P, N, G, D>>,
> Iterator for ConsumingIter<T, P, N, G, D>
{
Expand All @@ -758,7 +758,7 @@ impl<
}
}

impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<Self>> IntoIterator
impl<T: Clone, P: PointerFamily, const N: u32, const G: u32, D: DropHandler<Self>> IntoIterator
for GenericList<T, P, N, G, D>
{
type Item = T;
Expand All @@ -774,8 +774,8 @@ impl<
'a,
T: 'a + Clone,
P: 'a + PointerFamily,
const N: usize,
const G: usize,
const N: u32,
const G: u32,
D: 'a + DropHandler<Self>,
> FromIterator<&'a GenericList<T, P, N, G, D>> for GenericList<T, P, N, G, D>
{
Expand All @@ -784,54 +784,44 @@ impl<
}
}

impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<Self>> From<&[T]>
impl<T: Clone, P: PointerFamily, const N: u32, const G: u32, D: DropHandler<Self>> From<&[T]>
for GenericList<T, P, N, G, D>
{
fn from(vec: &[T]) -> Self {
vec.iter().cloned().collect()
}
}

impl<
T: Clone + PartialEq,
P: PointerFamily,
const N: usize,
const G: usize,
D: DropHandler<Self>,
> PartialEq for GenericList<T, P, N, G, D>
impl<T: Clone + PartialEq, P: PointerFamily, const N: u32, const G: u32, D: DropHandler<Self>>
PartialEq for GenericList<T, P, N, G, D>
{
fn eq(&self, other: &Self) -> bool {
self.iter().eq(other.iter())
}
}

impl<T: Clone + Eq, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<Self>> Eq
impl<T: Clone + Eq, P: PointerFamily, const N: u32, const G: u32, D: DropHandler<Self>> Eq
for GenericList<T, P, N, G, D>
{
}

impl<
T: Clone + PartialOrd,
P: PointerFamily,
const N: usize,
const G: usize,
D: DropHandler<Self>,
> PartialOrd for GenericList<T, P, N, G, D>
impl<T: Clone + PartialOrd, P: PointerFamily, const N: u32, const G: u32, D: DropHandler<Self>>
PartialOrd for GenericList<T, P, N, G, D>
{
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.iter().partial_cmp(other.iter())
}
}

impl<T: Clone + Ord, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<Self>> Ord
impl<T: Clone + Ord, P: PointerFamily, const N: u32, const G: u32, D: DropHandler<Self>> Ord
for GenericList<T, P, N, G, D>
{
fn cmp(&self, other: &Self) -> Ordering {
self.iter().cmp(other.iter())
}
}

impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<Self>> std::ops::Add
impl<T: Clone, P: PointerFamily, const N: u32, const G: u32, D: DropHandler<Self>> std::ops::Add
for GenericList<T, P, N, G, D>
{
type Output = GenericList<T, P, N, G, D>;
Expand All @@ -845,8 +835,8 @@ impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<
impl<
T: Clone,
P: PointerFamily,
const N: usize,
const G: usize,
const N: u32,
const G: u32,
D: DropHandler<GenericList<T, P, N, G, D>>,
> std::ops::Add for &GenericList<T, P, N, G, D>
{
Expand All @@ -858,8 +848,8 @@ impl<
}
}

impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<Self>>
std::iter::Sum for GenericList<T, P, N, G, D>
impl<T: Clone, P: PointerFamily, const N: u32, const G: u32, D: DropHandler<Self>> std::iter::Sum
for GenericList<T, P, N, G, D>
{
fn sum<I>(it: I) -> Self
where
Expand All @@ -872,8 +862,8 @@ impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<
impl<
T: Clone + std::hash::Hash,
P: PointerFamily,
const N: usize,
const G: usize,
const N: u32,
const G: u32,
D: DropHandler<Self>,
> std::hash::Hash for GenericList<T, P, N, G, D>
{
Expand All @@ -884,7 +874,7 @@ impl<
}
}

impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<Self>>
impl<T: Clone, P: PointerFamily, const N: u32, const G: u32, D: DropHandler<Self>>
std::ops::Index<usize> for GenericList<T, P, N, G, D>
{
type Output = T;
Expand All @@ -904,7 +894,7 @@ impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<
}
}

impl<T: Clone, P: PointerFamily, const N: usize, const G: usize, D: DropHandler<Self>> Drop
impl<T: Clone, P: PointerFamily, const N: u32, const G: u32, D: DropHandler<Self>> Drop
for GenericList<T, P, N, G, D>
{
fn drop(&mut self) {
Expand Down
Loading