mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
make delta Materializeable, curretly it just passes read through
added tests and benchs for delta, delta has no overhead in performance
This commit is contained in:
parent
750048f26c
commit
e36b9d90db
@ -312,7 +312,7 @@ impl<'a, L: DetailStore<KEY = usize>> Materializeable for VecIter<'a, L> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
pub mod tests {
|
||||||
use crate::lodstore::data::*;
|
use crate::lodstore::data::*;
|
||||||
use test::Bencher;
|
use test::Bencher;
|
||||||
|
|
||||||
@ -328,7 +328,7 @@ mod tests {
|
|||||||
> ,() ,u16, 4
|
> ,() ,u16, 4
|
||||||
>;
|
>;
|
||||||
|
|
||||||
fn gen_simple_example() -> ExampleData {
|
pub fn gen_simple_example() -> ExampleData {
|
||||||
let mut detail_index = FxHashMap::default();
|
let mut detail_index = FxHashMap::default();
|
||||||
detail_index.insert(LodPos::xyz(0, 0, 0), ((), 0));
|
detail_index.insert(LodPos::xyz(0, 0, 0), ((), 0));
|
||||||
ExampleData {
|
ExampleData {
|
||||||
|
@ -73,7 +73,7 @@ impl<'a, C: DetailStore + EntryLayer<'a>, D: Delta + EntryLayer<'a>> DeltaWriter
|
|||||||
impl<'a, D: 'a + Delta, T: 'a, const L: u8> EntryLayer<'a> for VecNestDelta<D, T, { L }> {
|
impl<'a, D: 'a + Delta, T: 'a, const L: u8> EntryLayer<'a> for VecNestDelta<D, T, { L }> {
|
||||||
type TRAV = VecDataIter<'a, VecNestDelta<D, T, { L }>>;
|
type TRAV = VecDataIter<'a, VecNestDelta<D, T, { L }>>;
|
||||||
|
|
||||||
fn trav(&'a self, pos: LodPos) -> Self::TRAV {
|
fn trav(&'a self, _pos: LodPos) -> Self::TRAV {
|
||||||
VecDataIter { layer: &self }
|
VecDataIter { layer: &self }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,11 +107,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, DT: Traversable, CT: Traversable> Traversable for DataWriterIter<'a, DT, CT>
|
impl<'a, DT: Traversable, CT: Traversable> Traversable for DataWriterIter<'a, DT, CT> {
|
||||||
where
|
|
||||||
DT::TRAV_CHILD: Traversable,
|
|
||||||
CT::TRAV_CHILD: Traversable,
|
|
||||||
{
|
|
||||||
type TRAV_CHILD = DataWriterIter<'a, DT::TRAV_CHILD, CT::TRAV_CHILD>;
|
type TRAV_CHILD = DataWriterIter<'a, DT::TRAV_CHILD, CT::TRAV_CHILD>;
|
||||||
|
|
||||||
fn get(self) -> DataWriterIter<'a, DT::TRAV_CHILD, CT::TRAV_CHILD> {
|
fn get(self) -> DataWriterIter<'a, DT::TRAV_CHILD, CT::TRAV_CHILD> {
|
||||||
@ -122,15 +118,14 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
impl<'a, DT: Materializeable, CT: Materializeable> Materializeable
|
|
||||||
for DataWriterIter<DT, CT> {
|
|
||||||
type MAT_CHILD = &'a CT::MAT_CHILD;
|
|
||||||
|
|
||||||
fn mat(self) -> &'a CT::MAT_CHILD {
|
impl<'a, DT, CT: Materializeable> Materializeable for DataWriterIter<'a, DT, CT> {
|
||||||
|
type MAT_CHILD = CT::MAT_CHILD;
|
||||||
|
|
||||||
|
fn mat(self) -> CT::MAT_CHILD {
|
||||||
self.data_iter.mat()
|
self.data_iter.mat()
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
impl<T, const L: u8> Delta for VecDelta<T, { L }> {}
|
impl<T, const L: u8> Delta for VecDelta<T, { L }> {}
|
||||||
impl<C: Delta, T, const L: u8> Delta for VecNestDelta<C, T, { L }> {}
|
impl<C: Delta, T, const L: u8> Delta for VecNestDelta<C, T, { L }> {}
|
||||||
@ -139,22 +134,12 @@ impl<C: Delta, T, const L: u8> Delta for VecNestDelta<C, T, { L }> {}
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use crate::lodstore::data::tests::gen_simple_example;
|
||||||
|
use crate::lodstore::data::tests::ExampleData;
|
||||||
use crate::lodstore::data::*;
|
use crate::lodstore::data::*;
|
||||||
use crate::lodstore::delta::*;
|
use crate::lodstore::delta::*;
|
||||||
use test::Bencher;
|
use test::Bencher;
|
||||||
|
|
||||||
#[rustfmt::skip]
|
|
||||||
pub type ExampleData =
|
|
||||||
HashNestLayer<
|
|
||||||
VecNestLayer<
|
|
||||||
VecNestLayer<
|
|
||||||
VecLayer<
|
|
||||||
i8, 0
|
|
||||||
> ,Option<()>, u16, 2
|
|
||||||
> ,() , u32, 3
|
|
||||||
> ,() ,u16, 4
|
|
||||||
>;
|
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
pub type ExampleDelta =
|
pub type ExampleDelta =
|
||||||
VecNestDelta<
|
VecNestDelta<
|
||||||
@ -174,14 +159,44 @@ mod tests {
|
|||||||
{
|
{
|
||||||
let w = DeltaWriter::new(&mut d, &mut x);
|
let w = DeltaWriter::new(&mut d, &mut x);
|
||||||
let i = LodPos::xyz(0, 1, 2);
|
let i = LodPos::xyz(0, 1, 2);
|
||||||
|
if false {
|
||||||
if false {}
|
let y = w.trav(i);
|
||||||
|
let ttc = y.get().get().get();
|
||||||
|
let _tt = ttc.mat();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn access_first_element() {
|
fn access_first_element() {
|
||||||
let x = ExampleDelta::default();
|
let mut x = gen_simple_example();
|
||||||
let i = LodPos::xyz(0, 0, 0);
|
let mut d = ExampleDelta::default();
|
||||||
|
{
|
||||||
|
let w = DeltaWriter::new(&mut d, &mut x);
|
||||||
|
let i = LodPos::xyz(0, 0, 0);
|
||||||
|
assert_eq!(*w.trav(i).get().get().get().mat(), 7_i8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn bench_access_trav(b: &mut Bencher) {
|
||||||
|
let mut x = gen_simple_example();
|
||||||
|
let mut d = ExampleDelta::default();
|
||||||
|
{
|
||||||
|
let w = DeltaWriter::new(&mut d, &mut x);
|
||||||
|
let access = LodPos::xyz(0, 0, 0);
|
||||||
|
b.iter(|| w.trav(access));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn bench_access_3(b: &mut Bencher) {
|
||||||
|
let mut x = gen_simple_example();
|
||||||
|
let mut d = ExampleDelta::default();
|
||||||
|
{
|
||||||
|
let w = DeltaWriter::new(&mut d, &mut x);
|
||||||
|
let access = LodPos::xyz(0, 0, 0);
|
||||||
|
b.iter(|| w.trav(access).get().get().get().mat());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
use super::delta::Delta;
|
use super::delta::Delta;
|
||||||
use super::index::ToOptionUsize;
|
|
||||||
use fxhash::FxHashMap;
|
|
||||||
use std::{u16, u32};
|
|
||||||
use vek::*;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
traits:
|
traits:
|
||||||
|
Loading…
Reference in New Issue
Block a user