try to get the lifetime of EntryLayer to its function not to the EntryLayer, on and simplyfiy the DataWriterIter

This commit is contained in:
Marcel Märtens 2019-11-06 16:31:17 +01:00
parent ff0d44d015
commit 497b5528bf
5 changed files with 116 additions and 43 deletions

View File

@ -1,6 +1,7 @@
#![allow(incomplete_features)]
#![feature(const_generics, test)]
#![feature(associated_type_bounds)]
#![feature(generic_associated_types)]
extern crate serde_derive;
#[macro_use]

View File

@ -7,7 +7,6 @@ use super::entrylayer::EntryLayer;
use super::traversable::Traversable;
#[allow(unused_imports)]
use super::materializeable::Materializeable;
use std::marker::PhantomData;
/*
A LodDelta applies a change to a Lod
The rules for LodDeltas are strict in order to make them as simple as possible.
@ -34,7 +33,7 @@ pub struct VecNestDelta<D: DeltaStore, T, const L: u8> {
pub child: D,
}
pub struct DeltaWriter<'a, C: EntryLayer<'a> + DetailStore, D: EntryLayer<'a> + DeltaStore> {
pub struct DeltaWriter<'a, C: EntryLayer + DetailStore, D: EntryLayer + DeltaStore> {
pub delta: &'a mut D,
pub data: &'a mut C,
}
@ -47,15 +46,14 @@ pub struct VecDeltaIterMut<'a, D: DeltaStore> {
pub( super ) layer: &'a mut D,
}
pub struct DataWriterIter<'a, DT: 'a, CT: 'a> {
pub struct DataWriterIter<DT, CT> {
pub( super ) delta_iter: DT,
pub( super ) data_iter: CT,
pub( super ) _a: PhantomData<&'a ()>,
}
//#######################################################
impl<'a, C: DetailStore + EntryLayer<'a>, D: DeltaStore + EntryLayer<'a>> DeltaWriter<'a, C, D> {
impl<'a, C: DetailStore + EntryLayer, D: DeltaStore + EntryLayer> DeltaWriter<'a, C, D> {
pub fn new(delta: &'a mut D, data: &'a mut C) -> Self {
DeltaWriter { delta, data }
}
@ -77,7 +75,7 @@ impl<C: DeltaStore, T, const L: u8> DeltaStore for VecNestDelta<C, T, { L }> {
//#######################################################
#[cfg(test)]
mod tests {
mod stests {
use crate::lodstore::data::tests::gen_simple_example;
use crate::lodstore::data::tests::ExampleData;
use crate::lodstore::delta::*;
@ -189,8 +187,7 @@ mod tests {
let mut d = ExampleDelta::default();
{
let mut w = DeltaWriter::new(&mut d, &mut x);
let access = LodPos::xyz(0, 0, 0);
b.iter(|| w.trav_mut(access));
//b.iter(|| w.trav_mut(LodPos::xyz(0, 0, 0)));
}
}
@ -200,8 +197,75 @@ mod tests {
let mut d = ExampleDelta::default();
{
let mut w = DeltaWriter::new(&mut d, &mut x);
let access = LodPos::xyz(0, 0, 0);
b.iter(|| w.trav_mut(access).get().get().get().mat());
//b.iter(|| w.trav_mut(LodPos::xyz(0, 0, 0)).get().get().get().mat());
}
}
}
#[bench]
fn bench_iter_3(b: &mut Bencher) {
let mut x = gen_simple_example();
let mut d = ExampleDelta::default();
{
let mut w = DeltaWriter::new(&mut d, &mut x);
//b.iter(|| w.trav_mut(LodPos::xyz(0, 0, 0)).get().get().get());
w.trav_mut(LodPos::xyz(0, 0, 0));
w.trav_mut(LodPos::xyz(0, 0, 0));
}
}
fn ddd<'a,'b:'a, D>() {
}
#[bench]
fn bench_trav(b: &mut Bencher) {
let mut x = gen_simple_example();
let mut d = ExampleDelta::default();
{
let mut w = DeltaWriter::new(&mut d, &mut x);
//b.iter(|| {w.trav_mut_xxx(LodPos::xyz(0, 0, 0));});
}
}
/*
pub struct ThisWorks<'a> {
pub ddd: &'a mut u64,
}
impl<'a> ThisWorks<'a> {
fn reff<'b>(&'b mut self) -> &'b mut u64 {
self.ddd
}
}
pub struct ThisDoestn<'a> {
pub ddd: &'a mut u64,
}
impl<'a> ThisDoestn<'a> {
fn reff<'b>(&'b mut self) -> &'a mut u64 where 'a: 'b {
self.ddd
}
}
pub struct ThisDoestnNeither<'a> {
pub ddd: &'a mut u64,
}
impl<'a> ThisDoestnNeither<'a> {
fn reff<'b: 'a>(&'b mut self) -> &'a mut u64 {
self.ddd
}
}
#[bench]
fn bench_travss(b: &mut Bencher) {
let mut u: u64 = 1;
let mut d = ThisWorks{ddd: &mut u};
{
b.iter(|| *d.ddd = *d.ddd + 1_u64);
b.iter(|| {d.reff();});
d.reff();
d.reff();
}
}
*/
}

View File

@ -3,25 +3,24 @@ use super::lodpos::LodPos;
use super::data::{HashNestLayer, DetailStore, HashIter, HashIterMut};
use super::delta::{VecNestDelta, DeltaStore, VecDeltaIter, VecDeltaIterMut, DataWriterIter, DeltaWriter};
use super::traversable::Traversable;
use std::marker::PhantomData;
pub trait EntryLayer<'a> {
type TRAV: Traversable;
type TRAV_MUT: Traversable;
fn trav(&'a self, pos: LodPos) -> Self::TRAV;
fn trav_mut(&'a mut self, pos: LodPos) -> Self::TRAV_MUT;
pub trait EntryLayer {
type TRAV<'a>: Traversable;
type TRAV_MUT<'a>: Traversable;
fn trav<'a>(&'a self, pos: LodPos) -> Self::TRAV;
fn trav_mut<'a>(&'a mut self, pos: LodPos) -> Self::TRAV_MUT;
}
///////////////// data types
impl<'a, C: 'a + DetailStore, T: 'a, I: 'a + ToOptionUsize, const L: u8> EntryLayer<'a>
impl<C: DetailStore, T, I: ToOptionUsize, const L: u8> EntryLayer
for HashNestLayer<C, T, I, { L }>
{
type TRAV = HashIter<'a, HashNestLayer<C, T, I, { L }>>;
type TRAV_MUT = HashIterMut<'a, HashNestLayer<C, T, I, { L }>>;
type TRAV<'a> = HashIter<'a, HashNestLayer<C, T, I, { L }>>;
type TRAV_MUT<'a> = HashIterMut<'a, HashNestLayer<C, T, I, { L }>>;
//ERROR make the HashIter C: remove the &'a from HashIter coding and implement it here
fn trav(&'a self, pos: LodPos) -> Self::TRAV {
fn trav<'a>(&'a self, pos: LodPos) -> HashIter<'a, HashNestLayer<C, T, I, { L }>> {
HashIter {
layer: self,
wanted: pos,
@ -29,7 +28,7 @@ for HashNestLayer<C, T, I, { L }>
}
}
fn trav_mut(&'a mut self, pos: LodPos) -> Self::TRAV_MUT {
fn trav_mut<'a>(&'a mut self, pos: LodPos) -> Self::TRAV_MUT {
HashIterMut {
layer: self,
wanted: pos,
@ -40,40 +39,51 @@ for HashNestLayer<C, T, I, { L }>
///////////////// delta types
impl<'a, D: 'a + DeltaStore, T: 'a, const L: u8> EntryLayer<'a> for VecNestDelta<D, T, { L }> {
type TRAV = VecDeltaIter<'a, VecNestDelta<D, T, { L }>>;
type TRAV_MUT = VecDeltaIterMut<'a, VecNestDelta<D, T, { L }>>;
impl<D: DeltaStore, T, const L: u8> EntryLayer for VecNestDelta<D, T, { L }> {
type TRAV<'a> = VecDeltaIter<'a, VecNestDelta<D, T, { L }>>;
type TRAV_MUT<'a> = VecDeltaIterMut<'a, VecNestDelta<D, T, { L }>>;
fn trav(&'a self, _pos: LodPos) -> Self::TRAV {
fn trav<'a>(&'a self, _pos: LodPos) -> Self::TRAV {
VecDeltaIter { layer: self }
}
fn trav_mut(&'a mut self, _pos: LodPos) -> Self::TRAV_MUT {
fn trav_mut<'a>(&'a mut self, _pos: LodPos) -> Self::TRAV_MUT {
VecDeltaIterMut { layer: self }
}
}
impl<'a, C: DetailStore + EntryLayer<'a>, D: DeltaStore + EntryLayer<'a>> EntryLayer<'a>
for DeltaWriter<'a, C, D>
impl<C: DetailStore + EntryLayer, D: DeltaStore + EntryLayer> EntryLayer
for DeltaWriter<'_, C, D>
where
<<C as EntryLayer<'a>>::TRAV as Traversable>::TRAV_CHILD: Traversable,
<<D as EntryLayer<'a>>::TRAV as Traversable>::TRAV_CHILD: Traversable,
<<C as EntryLayer>::TRAV as Traversable>::TRAV_CHILD: Traversable,
<<D as EntryLayer>::TRAV as Traversable>::TRAV_CHILD: Traversable,
{
type TRAV = DataWriterIter<'a, D::TRAV, C::TRAV>;
type TRAV_MUT = DataWriterIter<'a, D::TRAV_MUT, C::TRAV_MUT>;
type TRAV<'a> = DataWriterIter<D::TRAV, C::TRAV>;
type TRAV_MUT<'a> = DataWriterIter<D::TRAV_MUT, C::TRAV_MUT>;
fn trav(&'a self, pos: LodPos) -> DataWriterIter<D::TRAV, C::TRAV> {
fn trav<'a>(&'a self, pos: LodPos) -> Self::TRAV {
DataWriterIter {
delta_iter: self.delta.trav(pos),
data_iter: self.data.trav(pos),
_a: PhantomData::<&'a ()>::default(),
}
}
fn trav_mut(&'a mut self, pos: LodPos) -> DataWriterIter<D::TRAV_MUT, C::TRAV_MUT> {
fn trav_mut<'a>(&'a mut self, pos: LodPos) -> Self::TRAV_MUT {
DataWriterIter {
delta_iter: self.delta.trav_mut(pos),
data_iter: self.data.trav_mut(pos),
}
}
}
impl<'a, C: DetailStore + EntryLayer, D: DeltaStore + EntryLayer> DeltaWriter<'a, C, D>
where
<<C as EntryLayer>::TRAV as Traversable>::TRAV_CHILD: Traversable,
<<D as EntryLayer>::TRAV as Traversable>::TRAV_CHILD: Traversable,
{
pub fn trav_mut_xxx(&mut self, pos: LodPos) -> DataWriterIter<D::TRAV_MUT, C::TRAV_MUT> {
DataWriterIter {
delta_iter: self.delta.trav_mut(pos),
data_iter: self.data.trav_mut(pos),
_a: PhantomData::<&'a ()>::default(),
}
}
}

View File

@ -71,7 +71,7 @@ impl<'a, L: DetailStore<KEY = usize>> Materializeable<'a> for VecIterMut<'a, L>
///////////////// delta types
impl<'a, DT: Deltalizeable, CT: Materializeable<'a>> Materializeable<'a> for DataWriterIter<'a, DT, CT> {
impl<'a, DT: Deltalizeable, CT: Materializeable<'a>> Materializeable<'a> for DataWriterIter<DT, CT> {
type MAT_CHILD = CT::MAT_CHILD;
fn mat(self) -> &'a CT::MAT_CHILD {

View File

@ -4,7 +4,6 @@ use super::data::{DetailStore, IndexStore, HashIter, VecIter, HashIterMut, VecIt
use super::delta::{DeltaStore, VecDeltaIter, VecDeltaIterMut, DataWriterIter};
#[allow(unused_imports)] //not unsued, cargo is just to stupud to detect that
use super::layer::{Layer, ParentLayer};
use std::marker::PhantomData;
pub trait Traversable {
type TRAV_CHILD;
@ -149,14 +148,13 @@ impl<'a, D: DeltaStore + ParentLayer> Traversable for VecDeltaIterMut<'a, D>
}
}
impl<'a, DT: Traversable, CT: Traversable> Traversable for DataWriterIter<'a, DT, CT> {
type TRAV_CHILD = DataWriterIter<'a, DT::TRAV_CHILD, CT::TRAV_CHILD>;
impl<DT: Traversable, CT: Traversable> Traversable for DataWriterIter<DT, CT> {
type TRAV_CHILD = DataWriterIter<DT::TRAV_CHILD, CT::TRAV_CHILD>;
fn get(self) -> DataWriterIter<'a, DT::TRAV_CHILD, CT::TRAV_CHILD> {
fn get(self) -> DataWriterIter<DT::TRAV_CHILD, CT::TRAV_CHILD> {
DataWriterIter {
delta_iter: self.delta_iter.get(),
data_iter: self.data_iter.get(),
_a: PhantomData::<&'a ()>::default(),
}
}
}