lazy: done

This commit is contained in:
nym21
2025-05-08 11:15:47 +02:00
parent 3f62da879c
commit 96eeacbe2b
14 changed files with 690 additions and 371 deletions

View File

@@ -4,6 +4,7 @@ use super::{AnyIterableVec, AnyVec, StoredIndex, StoredType};
pub trait CollectableVec<I, T>: AnyVec + AnyIterableVec<I, T>
where
Self: Clone,
I: StoredIndex,
T: StoredType,
{
@@ -56,7 +57,7 @@ where
impl<I, T, V> CollectableVec<I, T> for V
where
V: AnyVec + AnyIterableVec<I, T>,
V: AnyVec + AnyIterableVec<I, T> + Clone,
I: StoredIndex,
T: StoredType,
{

View File

@@ -73,6 +73,10 @@ pub trait VecIterator<'a>: BaseVecIterator<Item = (Self::I, Value<'a, Self::T>)>
self.set_(i);
self.next().map(|(i, v)| (i, Value::Owned(v.into_inner())))
}
fn index_type_to_string(&self) -> &str {
Self::I::to_string()
}
}
impl<'a, I, T, Iter> VecIterator<'a> for Iter

View File

@@ -1,3 +1,4 @@
use core::panic;
use std::marker::PhantomData;
use crate::{
@@ -30,6 +31,10 @@ where
source: BoxedAnyIterableVec<S1I, S1T>,
compute: ComputeFrom1<I, T, S1I, S1T>,
) -> Self {
if source.index_type_to_string() != I::to_string() {
panic!("Should have same index");
}
Self {
name: name.to_owned(),
version,

View File

@@ -37,6 +37,18 @@ where
source2: BoxedAnyIterableVec<S2I, S2T>,
compute: ComputeFrom2<I, T, S1I, S1T, S2I, S2T>,
) -> Self {
if ([
source1.index_type_to_string(),
source2.index_type_to_string(),
])
.into_iter()
.filter(|t| *t == I::to_string())
.count()
== 0
{
panic!("At least one should have same index");
}
Self {
name: name.to_string(),
version,
@@ -98,7 +110,17 @@ where
#[inline]
fn len(&self) -> usize {
self.source1.len().min(self.source2.len())
let len1 = if self.source1.index_type_to_string() == I::to_string() {
self.source1.len()
} else {
usize::MAX
};
let len2 = if self.source2.index_type_to_string() == I::to_string() {
self.source2.len()
} else {
usize::MAX
};
len1.min(len2)
}
}
@@ -146,7 +168,17 @@ where
}
fn len(&self) -> usize {
self.source1.len().min(self.source2.len())
let len1 = if self.source1.index_type_to_string() == I::to_string() {
self.source1.len()
} else {
usize::MAX
};
let len2 = if self.source2.index_type_to_string() == I::to_string() {
self.source2.len()
} else {
usize::MAX
};
len1.min(len2)
}
fn modified_time(&self) -> Result<std::time::Duration> {

View File

@@ -42,6 +42,19 @@ where
source3: BoxedAnyIterableVec<S3I, S3T>,
compute: ComputeFrom3<I, T, S1I, S1T, S2I, S2T, S3I, S3T>,
) -> Self {
if ([
source1.index_type_to_string(),
source2.index_type_to_string(),
source3.index_type_to_string(),
])
.into_iter()
.filter(|t| *t == I::to_string())
.count()
== 0
{
panic!("At least one should have same index");
}
Self {
name: name.to_string(),
version,
@@ -115,10 +128,22 @@ where
#[inline]
fn len(&self) -> usize {
self.source1
.len()
.min(self.source2.len())
.min(self.source3.len())
let len1 = if self.source1.index_type_to_string() == I::to_string() {
self.source1.len()
} else {
usize::MAX
};
let len2 = if self.source2.index_type_to_string() == I::to_string() {
self.source2.len()
} else {
usize::MAX
};
let len3 = if self.source3.index_type_to_string() == I::to_string() {
self.source3.len()
} else {
usize::MAX
};
len1.min(len2).min(len3)
}
}
@@ -172,10 +197,22 @@ where
}
fn len(&self) -> usize {
self.source1
.len()
.min(self.source2.len())
.min(self.source3.len())
let len1 = if self.source1.index_type_to_string() == I::to_string() {
self.source1.len()
} else {
usize::MAX
};
let len2 = if self.source2.index_type_to_string() == I::to_string() {
self.source2.len()
} else {
usize::MAX
};
let len3 = if self.source3.index_type_to_string() == I::to_string() {
self.source3.len()
} else {
usize::MAX
};
len1.min(len2).min(len3)
}
fn modified_time(&self) -> Result<std::time::Duration> {