global: snapshot

This commit is contained in:
nym21
2025-05-18 17:28:09 +02:00
parent c2a77072d2
commit 411c5e4c4d
27 changed files with 378 additions and 329 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ pub trait AnyVec: Send + Sync {
self.len() == 0
}
fn modified_time(&self) -> Result<Duration>;
fn index_type_to_string(&self) -> &str;
fn index_type_to_string(&self) -> String;
}
pub trait AnyIterableVec<I, T>: AnyVec {
+17 -3
View File
@@ -1,4 +1,8 @@
use std::{fmt::Debug, ops::Add};
use std::{
fmt::Debug,
ops::Add,
path::{Path, PathBuf},
};
use crate::{Error, Result};
@@ -20,8 +24,14 @@ where
{
fn unwrap_to_usize(self) -> usize;
fn to_usize(self) -> Result<usize>;
fn to_string<'a>() -> &'a str;
fn to_string() -> String;
fn decremented(self) -> Option<Self>;
fn to_folder_name(value_name: &str) -> String {
format!("{}_to_{value_name}", Self::to_string().to_lowercase())
}
fn path(path: &Path, value_name: &str) -> PathBuf {
path.join(Self::to_folder_name(value_name))
}
}
impl<I> StoredIndex for I
@@ -51,8 +61,12 @@ where
}
#[inline]
fn to_string<'a>() -> &'a str {
fn to_string() -> String {
std::any::type_name::<I>()
.split("::")
.last()
.unwrap()
.to_lowercase()
}
#[inline]
+1 -1
View File
@@ -79,7 +79,7 @@ pub trait VecIterator<'a>: BaseVecIterator<Item = (Self::I, Value<'a, Self::T>)>
self.next().map(|(i, v)| (i, Value::Owned(v.into_inner())))
}
fn index_type_to_string(&self) -> &str {
fn index_type_to_string(&self) -> String {
Self::I::to_string()
}
}
+1 -1
View File
@@ -357,7 +357,7 @@ where
}
#[inline]
fn index_type_to_string(&self) -> &str {
fn index_type_to_string(&self) -> String {
I::to_string()
}
}
+15 -16
View File
@@ -84,21 +84,20 @@ where
pub fn forced_import_or_init_from_1(
mode: Computation,
path: &Path,
name: &str,
value_name: &str,
version: Version,
compressed: Compressed,
source: BoxedAnyIterableVec<S1I, S1T>,
compute: ComputeFrom1<I, T, S1I, S1T>,
) -> Result<Self> {
let full_path = path.join(name);
Ok(match mode {
Computation::Eager => Self::Eager {
vec: EagerVec::forced_import(&full_path, version, compressed)?,
vec: EagerVec::forced_import(path, value_name, version, compressed)?,
deps: Dependencies::From1(source, compute),
},
Computation::Lazy => {
let _ = fs::remove_dir_all(full_path);
Self::LazyFrom1(LazyVecFrom1::init(name, version, source, compute))
let _ = fs::remove_dir_all(I::path(path, value_name));
Self::LazyFrom1(LazyVecFrom1::init(value_name, version, source, compute))
}
})
}
@@ -107,22 +106,23 @@ where
pub fn forced_import_or_init_from_2(
mode: Computation,
path: &Path,
name: &str,
value_name: &str,
version: Version,
compressed: Compressed,
source1: BoxedAnyIterableVec<S1I, S1T>,
source2: BoxedAnyIterableVec<S2I, S2T>,
compute: ComputeFrom2<I, T, S1I, S1T, S2I, S2T>,
) -> Result<Self> {
let full_path = path.join(name);
Ok(match mode {
Computation::Eager => Self::Eager {
vec: EagerVec::forced_import(&full_path, version, compressed)?,
vec: EagerVec::forced_import(path, value_name, version, compressed)?,
deps: Dependencies::From2((source1, source2), compute),
},
Computation::Lazy => {
let _ = fs::remove_dir_all(full_path);
Self::LazyFrom2(LazyVecFrom2::init(name, version, source1, source2, compute))
let _ = fs::remove_dir_all(I::path(path, value_name));
Self::LazyFrom2(LazyVecFrom2::init(
value_name, version, source1, source2, compute,
))
}
})
}
@@ -131,7 +131,7 @@ where
pub fn forced_import_or_init_from_3(
mode: Computation,
path: &Path,
name: &str,
value_name: &str,
version: Version,
compressed: Compressed,
source1: BoxedAnyIterableVec<S1I, S1T>,
@@ -139,16 +139,15 @@ where
source3: BoxedAnyIterableVec<S3I, S3T>,
compute: ComputeFrom3<I, T, S1I, S1T, S2I, S2T, S3I, S3T>,
) -> Result<Self> {
let full_path = path.join(name);
Ok(match mode {
Computation::Eager => Self::Eager {
vec: EagerVec::forced_import(&full_path, version, compressed)?,
vec: EagerVec::forced_import(path, value_name, version, compressed)?,
deps: Dependencies::From3((source1, source2, source3), compute),
},
Computation::Lazy => {
let _ = fs::remove_dir_all(full_path);
let _ = fs::remove_dir_all(I::path(path, value_name));
Self::LazyFrom3(LazyVecFrom3::init(
name, version, source1, source2, source3, compute,
value_name, version, source1, source2, source3, compute,
))
}
})
@@ -228,7 +227,7 @@ where
}
}
fn index_type_to_string(&self) -> &str {
fn index_type_to_string(&self) -> String {
I::to_string()
}
+8 -3
View File
@@ -38,8 +38,13 @@ where
{
const SIZE_OF: usize = size_of::<T>();
pub fn forced_import(path: &Path, version: Version, compressed: Compressed) -> Result<Self> {
let inner = StoredVec::forced_import(path, version, compressed)?;
pub fn forced_import(
path: &Path,
value_name: &str,
version: Version,
compressed: Compressed,
) -> Result<Self> {
let inner = StoredVec::forced_import(path, value_name, version, compressed)?;
Ok(Self {
computed_version: None,
@@ -937,7 +942,7 @@ where
}
#[inline]
fn index_type_to_string(&self) -> &str {
fn index_type_to_string(&self) -> String {
I::to_string()
}
}
+11 -4
View File
@@ -26,10 +26,17 @@ where
I: StoredIndex,
T: StoredType,
{
pub fn forced_import(path: &Path, version: Version, compressed: Compressed) -> Result<Self> {
pub fn forced_import(
path: &Path,
value_name: &str,
version: Version,
compressed: Compressed,
) -> Result<Self> {
let inner = StoredVec::forced_import(path, value_name, version, compressed)?;
Ok(Self {
height: Height::try_from(Self::path_height_(path).as_path()).ok(),
inner: StoredVec::forced_import(path, version, compressed)?,
height: Height::try_from(Self::path_height_(inner.path()).as_path()).ok(),
inner,
})
}
@@ -117,7 +124,7 @@ where
}
#[inline]
fn index_type_to_string(&self) -> &str {
fn index_type_to_string(&self) -> String {
I::to_string()
}
}
+3 -3
View File
@@ -26,7 +26,7 @@ where
S1T: StoredType,
{
pub fn init(
name: &str,
value_name: &str,
version: Version,
source: BoxedAnyIterableVec<S1I, S1T>,
compute: ComputeFrom1<I, T, S1I, S1T>,
@@ -36,7 +36,7 @@ where
}
Self {
name: name.to_owned(),
name: I::to_folder_name(value_name),
version,
source,
compute,
@@ -129,7 +129,7 @@ where
self.name.clone()
}
fn index_type_to_string(&self) -> &str {
fn index_type_to_string(&self) -> String {
I::to_string()
}
+3 -3
View File
@@ -31,7 +31,7 @@ where
S2T: StoredType,
{
pub fn init(
name: &str,
value_name: &str,
version: Version,
source1: BoxedAnyIterableVec<S1I, S1T>,
source2: BoxedAnyIterableVec<S2I, S2T>,
@@ -50,7 +50,7 @@ where
}
Self {
name: name.to_string(),
name: I::to_folder_name(value_name),
version,
source1,
source2,
@@ -163,7 +163,7 @@ where
self.name.clone()
}
fn index_type_to_string(&self) -> &str {
fn index_type_to_string(&self) -> String {
I::to_string()
}
+3 -3
View File
@@ -35,7 +35,7 @@ where
S3T: StoredType,
{
pub fn init(
name: &str,
value_name: &str,
version: Version,
source1: BoxedAnyIterableVec<S1I, S1T>,
source2: BoxedAnyIterableVec<S2I, S2T>,
@@ -56,7 +56,7 @@ where
}
Self {
name: name.to_string(),
name: I::to_folder_name(value_name),
version,
source1,
source2,
@@ -192,7 +192,7 @@ where
self.name.clone()
}
fn index_type_to_string(&self) -> &str {
fn index_type_to_string(&self) -> String {
I::to_string()
}
+1 -1
View File
@@ -191,7 +191,7 @@ where
}
#[inline]
fn index_type_to_string(&self) -> &str {
fn index_type_to_string(&self) -> String {
I::to_string()
}
}
+10 -4
View File
@@ -21,13 +21,19 @@ where
I: StoredIndex,
T: StoredType,
{
pub fn forced_import(path: &Path, version: Version, compressed: Compressed) -> Result<Self> {
pub fn forced_import(
path: &Path,
value_name: &str,
version: Version,
compressed: Compressed,
) -> Result<Self> {
let path = I::path(path, value_name);
if *compressed {
Ok(Self::Compressed(CompressedVec::forced_import(
path, version,
&path, version,
)?))
} else {
Ok(Self::Raw(RawVec::forced_import(path, version)?))
Ok(Self::Raw(RawVec::forced_import(&path, version)?))
}
}
}
@@ -113,7 +119,7 @@ where
}
#[inline]
fn index_type_to_string(&self) -> &str {
fn index_type_to_string(&self) -> String {
I::to_string()
}