mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-14 21:58:36 -07:00
computer: lazy part 2
This commit is contained in:
@@ -111,31 +111,25 @@ impl Vecs {
|
|||||||
.add_total(),
|
.add_total(),
|
||||||
)?,
|
)?,
|
||||||
inputindex_to_value: LazyVec::init(
|
inputindex_to_value: LazyVec::init(
|
||||||
// &path.join("inputindex_to_value"),
|
|
||||||
Version::ZERO,
|
Version::ZERO,
|
||||||
indexer.vecs().outputindex_to_value.vec().clone(),
|
indexer.vecs().outputindex_to_value.vec().clone(),
|
||||||
indexer.vecs().inputindex_to_outputindex.vec().clone(),
|
indexer.vecs().inputindex_to_outputindex.vec().clone(),
|
||||||
|index, outputindex_to_value_iter, inputindex_to_outputindex_iter| {
|
|index, outputindex_to_value_iter, inputindex_to_outputindex_iter| {
|
||||||
// outputindex_to_value_iter.get(i)
|
inputindex_to_outputindex_iter.next_at(index).map(
|
||||||
// inputindex_to_outputindex_iter.get
|
|(inputindex, outputindex)| {
|
||||||
// let mut outputindex_to_value_iter = indexer.vecs().outputindex_to_value.iter();
|
let outputindex = outputindex.into_inner();
|
||||||
// self.inputindex_to_value.compute_transform(
|
if outputindex == OutputIndex::COINBASE {
|
||||||
// starting_indexes.inputindex,
|
Sats::ZERO
|
||||||
// indexer.vecs().inputindex_to_outputindex.vec(),
|
} else if let Some((_, value)) =
|
||||||
// |(inputindex, outputindex, ..)| {
|
outputindex_to_value_iter.next_at(outputindex.unwrap_to_usize())
|
||||||
// let value = if outputindex == OutputIndex::COINBASE {
|
{
|
||||||
// Sats::ZERO
|
value.into_inner()
|
||||||
// } else if let Some(value) = outputindex_to_value_iter.get(outputindex) {
|
} else {
|
||||||
// value.into_inner()
|
dbg!(inputindex, outputindex);
|
||||||
// } else {
|
panic!()
|
||||||
// dbg!(inputindex, outputindex);
|
}
|
||||||
// panic!()
|
},
|
||||||
// };
|
)
|
||||||
// (inputindex, value)
|
|
||||||
// },
|
|
||||||
// exit,
|
|
||||||
// )?;
|
|
||||||
Some(Sats::ZERO)
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
indexes_to_tx_v1: ComputedVecsFromHeight::forced_import(
|
indexes_to_tx_v1: ComputedVecsFromHeight::forced_import(
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use brk_vec::{StoredIndex, StoredType, StoredVec, StoredVecIterator, Value, Version};
|
use brk_vec::{
|
||||||
|
BaseVecIterator, StoredIndex, StoredType, StoredVec, StoredVecIterator, Value, Version,
|
||||||
|
};
|
||||||
|
|
||||||
// LazyVec owns SourceVecs
|
// LazyVec owns SourceVecs
|
||||||
//
|
//
|
||||||
@@ -29,8 +31,8 @@ where
|
|||||||
source2: StoredVec<S2I, S2T>,
|
source2: StoredVec<S2I, S2T>,
|
||||||
compute: for<'a> fn(
|
compute: for<'a> fn(
|
||||||
usize,
|
usize,
|
||||||
&mut (dyn Iterator<Item = (S1I, Value<'a, S1T>)>),
|
&mut dyn BaseVecIterator<Item = (S1I, Value<'a, S1T>)>,
|
||||||
&mut (dyn Iterator<Item = (S2I, Value<'a, S2T>)>),
|
&mut dyn BaseVecIterator<Item = (S2I, Value<'a, S2T>)>,
|
||||||
) -> Option<T>,
|
) -> Option<T>,
|
||||||
phantom: PhantomData<I>,
|
phantom: PhantomData<I>,
|
||||||
}
|
}
|
||||||
@@ -50,8 +52,8 @@ where
|
|||||||
source2: StoredVec<S2I, S2T>,
|
source2: StoredVec<S2I, S2T>,
|
||||||
compute: for<'a> fn(
|
compute: for<'a> fn(
|
||||||
usize,
|
usize,
|
||||||
&mut (dyn Iterator<Item = (S1I, Value<'a, S1T>)>),
|
&mut dyn BaseVecIterator<Item = (S1I, Value<'a, S1T>)>,
|
||||||
&mut (dyn Iterator<Item = (S2I, Value<'a, S2T>)>),
|
&mut dyn BaseVecIterator<Item = (S2I, Value<'a, S2T>)>,
|
||||||
) -> Option<T>,
|
) -> Option<T>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@@ -119,30 +121,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl<'a, I, T, S1I, S1T, S2I, S2T> VecIterator<'a> for LazyVecIterator<'a, I, T, S1I, S1T, S2I, S2T>
|
|
||||||
// where
|
|
||||||
// I: StoredIndex,
|
|
||||||
// T: StoredType,
|
|
||||||
// S1I: StoredIndex,
|
|
||||||
// S1T: StoredType,
|
|
||||||
// S2I: StoredIndex,
|
|
||||||
// S2T: StoredType,
|
|
||||||
// {
|
|
||||||
// type I = I;
|
|
||||||
// type T = T;
|
|
||||||
|
|
||||||
// #[inline]
|
|
||||||
// fn mut_index(&mut self) -> &mut usize {
|
|
||||||
// &mut self.index
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #[inline]
|
|
||||||
// fn len(&self) -> usize {
|
|
||||||
// todo!();
|
|
||||||
// // self.vec.len()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
impl<'a, I, T, S1I, S1T, S2I, S2T> Iterator for LazyVecIterator<'a, I, T, S1I, S1T, S2I, S2T>
|
impl<'a, I, T, S1I, S1T, S2I, S2T> Iterator for LazyVecIterator<'a, I, T, S1I, S1T, S2I, S2T>
|
||||||
where
|
where
|
||||||
I: StoredIndex,
|
I: StoredIndex,
|
||||||
@@ -166,19 +144,27 @@ where
|
|||||||
}
|
}
|
||||||
opt
|
opt
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// fn last(mut self) -> Option<Self::Item>
|
impl<I, T, S1I, S1T, S2I, S2T> BaseVecIterator for LazyVecIterator<'_, I, T, S1I, S1T, S2I, S2T>
|
||||||
// where
|
where
|
||||||
// Self: Sized,
|
I: StoredIndex,
|
||||||
// {
|
T: StoredType,
|
||||||
// let len = self.vec.len();
|
S1I: StoredIndex,
|
||||||
// if len == 0 {
|
S1T: StoredType,
|
||||||
// return None;
|
S2I: StoredIndex,
|
||||||
// }
|
S2T: StoredType,
|
||||||
// let i = len - 1;
|
{
|
||||||
// self.get_(i)
|
#[inline]
|
||||||
// .map(|v| (I::from(i), Value::Owned(v.into_inner())))
|
fn mut_index(&mut self) -> &mut usize {
|
||||||
// }
|
&mut self.index
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn len(&self) -> usize {
|
||||||
|
todo!();
|
||||||
|
// self.vec.len()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, I, T, S1I, S1T, S2I, S2T> IntoIterator for &'a LazyVec<I, T, S1I, S1T, S2I, S2T>
|
impl<'a, I, T, S1I, S1T, S2I, S2T> IntoIterator for &'a LazyVec<I, T, S1I, S1T, S2I, S2T>
|
||||||
|
|||||||
@@ -218,31 +218,6 @@ where
|
|||||||
Compressed(CompressedVecIterator<'a, I, T>),
|
Compressed(CompressedVecIterator<'a, I, T>),
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl<I, T> StoredVecIterator<'_, I, T>
|
|
||||||
// impl<'a, I, T> VecIterator<'a> for StoredVecIterator<'a, I, T>
|
|
||||||
// where
|
|
||||||
// I: StoredIndex,
|
|
||||||
// T: StoredType,
|
|
||||||
// {
|
|
||||||
// type I = I;
|
|
||||||
// type T = T;
|
|
||||||
|
|
||||||
// #[inline]
|
|
||||||
// fn mut_index(&mut self) -> &mut usize {
|
|
||||||
// match self {
|
|
||||||
// Self::Compressed(iter) => iter.mut_index(),
|
|
||||||
// Self::Raw(iter) => iter.mut_index(),
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn len(&self) -> usize {
|
|
||||||
// match self {
|
|
||||||
// Self::Compressed(i) => i.len(),
|
|
||||||
// Self::Raw(i) => i.len(),
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
impl<'a, I, T> Iterator for StoredVecIterator<'a, I, T>
|
impl<'a, I, T> Iterator for StoredVecIterator<'a, I, T>
|
||||||
where
|
where
|
||||||
I: StoredIndex,
|
I: StoredIndex,
|
||||||
@@ -257,6 +232,27 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<I, T> BaseVecIterator for StoredVecIterator<'_, I, T>
|
||||||
|
where
|
||||||
|
I: StoredIndex,
|
||||||
|
T: StoredType,
|
||||||
|
{
|
||||||
|
#[inline]
|
||||||
|
fn mut_index(&mut self) -> &mut usize {
|
||||||
|
match self {
|
||||||
|
Self::Compressed(iter) => iter.mut_index(),
|
||||||
|
Self::Raw(iter) => iter.mut_index(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn len(&self) -> usize {
|
||||||
|
match self {
|
||||||
|
Self::Compressed(i) => i.len(),
|
||||||
|
Self::Raw(i) => i.len(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, I, T> IntoIterator for &'a StoredVec<I, T>
|
impl<'a, I, T> IntoIterator for &'a StoredVec<I, T>
|
||||||
where
|
where
|
||||||
I: StoredIndex,
|
I: StoredIndex,
|
||||||
|
|||||||
@@ -1,83 +1,49 @@
|
|||||||
|
use std::iter::Skip;
|
||||||
|
|
||||||
use crate::Value;
|
use crate::Value;
|
||||||
|
|
||||||
use super::{StoredIndex, StoredType};
|
use super::{StoredIndex, StoredType};
|
||||||
|
|
||||||
// pub trait BaseVecIterator: Iterator {
|
pub trait BaseVecIterator: Iterator {
|
||||||
// fn mut_index(&mut self) -> &mut usize;
|
|
||||||
|
|
||||||
// fn len(&self) -> usize;
|
|
||||||
|
|
||||||
// fn is_empty(&self) -> bool {
|
|
||||||
// self.len() == 0
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #[inline]
|
|
||||||
// fn set_(&mut self, i: usize) -> &mut Self {
|
|
||||||
// *self.mut_index() = i;
|
|
||||||
// self
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn skip(self, _: usize) -> std::iter::Skip<Self>
|
|
||||||
// where
|
|
||||||
// Self: Sized,
|
|
||||||
// {
|
|
||||||
// todo!("")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
pub trait VecIterator<'a>: Iterator<Item = (Self::I, Value<'a, Self::T>)> + 'a {
|
|
||||||
type I: StoredIndex;
|
|
||||||
type T: StoredType;
|
|
||||||
|
|
||||||
fn mut_index(&mut self) -> &mut usize;
|
fn mut_index(&mut self) -> &mut usize;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn set_(&mut self, i: usize) {
|
||||||
|
*self.mut_index() = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn next_at(&mut self, i: usize) -> Option<Self::Item> {
|
||||||
|
self.set_(i);
|
||||||
|
self.next()
|
||||||
|
}
|
||||||
|
|
||||||
fn len(&self) -> usize;
|
fn len(&self) -> usize;
|
||||||
|
|
||||||
fn is_empty(&self) -> bool {
|
fn is_empty(&self) -> bool {
|
||||||
self.len() == 0
|
self.len() == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
fn skip(self, _: usize) -> Skip<Self>
|
||||||
fn set_(&mut self, i: usize) -> &mut Self {
|
|
||||||
*self.mut_index() = i;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
fn skip(self, _: usize) -> std::iter::Skip<Self>
|
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
todo!("")
|
todo!("")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// fn set(&mut self, i: Self::I) -> &mut Self;
|
pub trait VecIterator<'a>: BaseVecIterator<Item = (Self::I, Value<'a, Self::T>)> + 'a {
|
||||||
|
type I: StoredIndex;
|
||||||
|
type T: StoredType;
|
||||||
|
|
||||||
// fn get_(&mut self, i: usize) -> Option<Value<'a, Self::T>>;
|
|
||||||
|
|
||||||
// fn get(&mut self, i: Self::I) -> Option<Value<'a, Self::T>>;
|
|
||||||
|
|
||||||
// fn unwrap_get_inner(&mut self, i: Self::I) -> Self::T;
|
|
||||||
|
|
||||||
// fn get_inner(&mut self, i: Self::I) -> Option<Self::T>;
|
|
||||||
|
|
||||||
// fn last(self) -> Option<Self::Item>;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl<'a, I, T, Iter> VecIterator<'a, I, T> for Iter
|
|
||||||
// where
|
|
||||||
// I: StoredIndex,
|
|
||||||
// T: StoredType + 'a,
|
|
||||||
// Iter: Iterator<Item = (I, Value<'a, T>)> + BaseVecIterator,
|
|
||||||
// {
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn set(&mut self, i: Self::I) -> &mut Self {
|
fn set(&mut self, i: Self::I) {
|
||||||
self.set_(i.unwrap_to_usize())
|
self.set_(i.unwrap_to_usize())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_(&mut self, i: usize) -> Option<Value<'a, Self::T>> {
|
fn get_(&mut self, i: usize) -> Option<Value<'a, Self::T>> {
|
||||||
self.set_(i);
|
self.next_at(i).map(|(_, v)| v)
|
||||||
self.next().map(|(_, v)| v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -111,19 +77,10 @@ pub trait VecIterator<'a>: Iterator<Item = (Self::I, Value<'a, Self::T>)> + 'a {
|
|||||||
|
|
||||||
impl<'a, I, T, Iter> VecIterator<'a> for Iter
|
impl<'a, I, T, Iter> VecIterator<'a> for Iter
|
||||||
where
|
where
|
||||||
Iter: Iterator<Item = (I, Value<'a, T>)> + 'a,
|
Iter: BaseVecIterator<Item = (I, Value<'a, T>)> + 'a,
|
||||||
I: StoredIndex,
|
I: StoredIndex,
|
||||||
T: StoredType + 'a,
|
T: StoredType + 'a,
|
||||||
{
|
{
|
||||||
type I = I;
|
type I = I;
|
||||||
type T = T;
|
type T = T;
|
||||||
|
|
||||||
fn len(&self) -> usize {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn mut_index(&mut self) -> &mut usize {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// pub trait VecIterator<'a>: Iterator<Item = (Self::I, Value<'a, Self::T>)> + 'a {
|
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ use rayon::prelude::*;
|
|||||||
use zstd::DEFAULT_COMPRESSION_LEVEL;
|
use zstd::DEFAULT_COMPRESSION_LEVEL;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
CompressedPageMetadata, CompressedPagesMetadata, DynamicVec, Error, GenericVec, RawVec, Result,
|
BaseVecIterator, CompressedPageMetadata, CompressedPagesMetadata, DynamicVec, Error,
|
||||||
StoredIndex, StoredType, UnsafeSlice, Value, VecIterator, Version,
|
GenericVec, RawVec, Result, StoredIndex, StoredType, UnsafeSlice, Value, Version,
|
||||||
};
|
};
|
||||||
|
|
||||||
const ONE_KIB: usize = 1024;
|
const ONE_KIB: usize = 1024;
|
||||||
@@ -392,24 +392,21 @@ where
|
|||||||
const PER_PAGE: usize = MAX_PAGE_SIZE / Self::SIZE_OF_T;
|
const PER_PAGE: usize = MAX_PAGE_SIZE / Self::SIZE_OF_T;
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl<'a, I, T> VecIterator<'a> for CompressedVecIterator<'a, I, T>
|
impl<I, T> BaseVecIterator for CompressedVecIterator<'_, I, T>
|
||||||
// where
|
where
|
||||||
// I: StoredIndex,
|
I: StoredIndex,
|
||||||
// T: StoredType,
|
T: StoredType,
|
||||||
// {
|
{
|
||||||
// type I = I;
|
#[inline]
|
||||||
// type T = T;
|
fn mut_index(&mut self) -> &mut usize {
|
||||||
|
&mut self.index
|
||||||
|
}
|
||||||
|
|
||||||
// #[inline]
|
#[inline]
|
||||||
// fn mut_index(&mut self) -> &mut usize {
|
fn len(&self) -> usize {
|
||||||
// &mut self.index
|
self.vec.len()
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
// #[inline]
|
|
||||||
// fn len(&self) -> usize {
|
|
||||||
// self.vec.len()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
impl<'a, I, T> Iterator for CompressedVecIterator<'a, I, T>
|
impl<'a, I, T> Iterator for CompressedVecIterator<'a, I, T>
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ use memmap2::Mmap;
|
|||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
DynamicVec, Error, GenericVec, Result, StoredIndex, StoredType, UnsafeSlice, Value,
|
BaseVecIterator, DynamicVec, Error, GenericVec, Result, StoredIndex, StoredType, UnsafeSlice,
|
||||||
VecIterator, Version,
|
Value, Version,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -217,24 +217,21 @@ pub struct RawVecIterator<'a, I, T> {
|
|||||||
index: usize,
|
index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl<'a, I, T> VecIterator<'a> for RawVecIterator<'a, I, T>
|
impl<I, T> BaseVecIterator for RawVecIterator<'_, I, T>
|
||||||
// where
|
where
|
||||||
// I: StoredIndex,
|
I: StoredIndex,
|
||||||
// T: StoredType,
|
T: StoredType,
|
||||||
// {
|
{
|
||||||
// type I = I;
|
#[inline]
|
||||||
// type T = T;
|
fn mut_index(&mut self) -> &mut usize {
|
||||||
|
&mut self.index
|
||||||
|
}
|
||||||
|
|
||||||
// #[inline]
|
#[inline]
|
||||||
// fn mut_index(&mut self) -> &mut usize {
|
fn len(&self) -> usize {
|
||||||
// &mut self.index
|
self.vec.len()
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
// #[inline]
|
|
||||||
// fn len(&self) -> usize {
|
|
||||||
// self.vec.len()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
impl<'a, I, T> Iterator for RawVecIterator<'a, I, T>
|
impl<'a, I, T> Iterator for RawVecIterator<'a, I, T>
|
||||||
where
|
where
|
||||||
|
|||||||
Reference in New Issue
Block a user