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