mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
experiment with simplified version to fix the get problem
This commit is contained in:
parent
40a20001d8
commit
1605fe202e
@ -50,12 +50,7 @@ pub trait Key {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait IndexStore {
|
pub trait IndexStore {
|
||||||
type KEY: Key;
|
fn load(&self, pos: LodPos) -> usize;
|
||||||
type INDEX: Copy;
|
|
||||||
const OWN_PER_PARENT: usize; // theoretically this can be auto calculated in a new trait, however rust ist detecting conflicting implementations
|
|
||||||
|
|
||||||
fn load(&self, key: Self::KEY) -> Self::INDEX;
|
|
||||||
fn store(&mut self, key: Self::KEY, index: Self::INDEX);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait DetailStore {
|
pub trait DetailStore {
|
||||||
@ -63,9 +58,9 @@ pub trait DetailStore {
|
|||||||
type DETAIL;
|
type DETAIL;
|
||||||
const LEVEL: u8;
|
const LEVEL: u8;
|
||||||
|
|
||||||
fn load(&self, key: Self::KEY) -> &Self::DETAIL;
|
DER RETURNWERT MUSS EIN EIGENER TYPE SEIN JE NACHDEM VEC ODER HASH
|
||||||
fn load_mut(&mut self, key: Self::KEY) -> &mut Self::DETAIL;
|
|
||||||
fn store(&mut self, key: Self::KEY, detail: Self::DETAIL);
|
fn load(&self, pos: LodPos) -> usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Nestable: DetailStore {
|
pub trait Nestable: DetailStore {
|
||||||
@ -90,74 +85,55 @@ pub struct LayerResult<'a, N: DetailStore> {
|
|||||||
key: N::KEY,
|
key: N::KEY,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Index for u16 {}
|
|
||||||
impl Index for u32 {}
|
|
||||||
impl Index for LodPos {}
|
|
||||||
|
|
||||||
|
|
||||||
//TODO: optimize this self away! vtable
|
|
||||||
//TODO: arrr and the clone
|
|
||||||
impl KeyConvertable<KEY=usize, INDEX=u16> {
|
|
||||||
fn uncompress(&self, index: &u16) -> usize { index.clone() as usize }
|
|
||||||
fn compress(&self, key: &usize) -> u16 { key.clone() as u16 }
|
|
||||||
}
|
|
||||||
impl KeyConvertable<KEY=usize, INDEX=u32> {
|
|
||||||
fn uncompress(&self, index: &u32) -> usize { index.clone() as usize }
|
|
||||||
fn compress(&self, key: &usize) -> u32 { key.clone() as u32 }
|
|
||||||
}
|
|
||||||
impl KeyConvertable<KEY=LodPos, INDEX=LodPos> {
|
|
||||||
fn uncompress(&self, index: &LodPos) -> LodPos { index.clone() }
|
|
||||||
fn compress(&self, key: &LodPos) -> LodPos { key.clone() }
|
|
||||||
}
|
|
||||||
|
|
||||||
//#######################################################
|
//#######################################################
|
||||||
|
|
||||||
pub struct VecVecLayer<T, PI: Copy, const L: u8> {
|
pub struct VecLayer<T, const L: u8> {
|
||||||
pub detail: Vec<T>,
|
pub detail: Vec<T>,
|
||||||
pub index: Vec<PI>,
|
|
||||||
}
|
}
|
||||||
pub struct VecHashLayer<T, PI: Copy, const L: u8> {
|
pub struct HashLayer<T, const L: u8> {
|
||||||
pub detail: Vec<T>,
|
|
||||||
pub index: HashMap<LodPos, PI>,
|
|
||||||
}
|
|
||||||
|
|
||||||
//T: own detail type
|
|
||||||
//PI: parents index type u16, u32
|
|
||||||
pub struct VecVecNestLayer<N: IndexStore + DetailStore, T, PI: Copy, const L: u8> {
|
|
||||||
pub detail: Vec<T>,
|
|
||||||
pub index: Vec<PI>,
|
|
||||||
pub nested: N,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct VecHashNestLayer<N: IndexStore + DetailStore, T, PI: Copy, const L: u8> {
|
|
||||||
pub detail: Vec<T>,
|
|
||||||
pub index: HashMap<LodPos, PI>,
|
|
||||||
pub nested: N,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct HashNoneNestLayer<N: IndexStore + DetailStore, T, const L: u8> {
|
|
||||||
pub detail: HashMap<LodPos, T>,
|
pub detail: HashMap<LodPos, T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct VecNestLayer<N: DetailStore, T, I: Copy, const L: u8> {
|
||||||
|
pub detail: Vec<T>,
|
||||||
|
pub index: Vec<I>,
|
||||||
|
pub nested: N,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct HashNestLayer<N: DetailStore, T, I: Copy, const L: u8> {
|
||||||
|
pub detail_index: HashMap<LodPos, (T, I)>,
|
||||||
pub nested: N,
|
pub nested: N,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
impl<T, PI: Copy, const L: u8> IndexStore for VecVecLayer<T, PI, { L }> {
|
impl<N: DetailStore, T, I: Copy, const L: u8> IndexStore for VecNestLayer<N, T, I, { L }> {
|
||||||
type KEY = usize; type INDEX=PI; const OWN_PER_PARENT: usize = 4096; //TODO: calculate these correctly
|
fn load(&self, pos: LodPos) -> usize {
|
||||||
fn load(&self, key: usize) -> PI { *self.index.get(key).unwrap() }
|
let adjusted_pos = pos;
|
||||||
fn store(&mut self, key: usize, index: PI) { self.index.insert(key, index); }
|
let pos_offset = 0;
|
||||||
|
let childs_per_own = 8;
|
||||||
|
let u1 = ( self.index[adjusted_pos * childs_per_own ) as usize + pos_offset;
|
||||||
|
return u1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
impl<N: IndexStore<KEY = usize> + DetailStore, T, PI: Copy, const L: u8> IndexStore for VecVecNestLayer<N, T, PI, { L }> {
|
impl<N: DetailStore, T, I: Copy, const L: u8> IndexStore for HashNestLayer<N, T, I, { L }> {
|
||||||
type KEY = usize; type INDEX=PI; const OWN_PER_PARENT: usize = 32768;
|
fn load(&self, pos: LodPos) -> usize {
|
||||||
fn load(&self, key: usize) -> PI { *self.index.get(key).unwrap() }
|
let adjusted_pos = pos;
|
||||||
fn store(&mut self, key: usize, index: PI) { self.index.insert(key, index); }
|
let pos_offset = 0;
|
||||||
|
let childs_per_own = 8;
|
||||||
|
let u1 = ( self.index[adjusted_pos * childs_per_own ) as usize + pos_offset;
|
||||||
|
return u1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
impl<T, PI: Copy, const L: u8> IndexStore for VecHashLayer<T, PI, { L }> {
|
impl<T, PI: Copy, const L: u8> IndexStore for HashNestLayer<T, PI, { L }> {
|
||||||
type KEY = LodPos; type INDEX=PI; const OWN_PER_PARENT: usize = 1337;
|
type KEY = LodPos; type INDEX=PI; const OWN_PER_PARENT: usize = 1337;
|
||||||
fn load(&self, key: LodPos) -> PI { *self.index.get(&key).unwrap() }
|
fn load(&self, key: LodPos) -> PI { *self.index.get(&key).unwrap() }
|
||||||
fn store(&mut self, key: LodPos, index: PI) { self.index.insert(key, index); }
|
fn store(&mut self, key: LodPos, index: PI) { self.index.insert(key, index); }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
impl<N: IndexStore<KEY = usize> + DetailStore, T, PI: Copy, const L: u8> IndexStore for VecHashNestLayer<N, T, PI, { L }> {
|
impl<N: IndexStore<KEY = usize> + DetailStore, T, PI: Copy, const L: u8> IndexStore for VecHashNestLayer<N, T, PI, { L }> {
|
||||||
type KEY = LodPos; type INDEX=PI; const OWN_PER_PARENT: usize = 4096;
|
type KEY = LodPos; type INDEX=PI; const OWN_PER_PARENT: usize = 4096;
|
||||||
@ -289,14 +265,14 @@ impl<'a, N: IndexStore + DetailStore> Materializeable<N::DETAIL> for LayerResult
|
|||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
pub type ExampleDelta =
|
pub type ExampleDelta =
|
||||||
HashNoneNestLayer<
|
HashNestLayer<
|
||||||
VecHashNestLayer<
|
VecNestLayer<
|
||||||
VecVecNestLayer<
|
VecNestLayer<
|
||||||
VecVecLayer<
|
VecLayer<
|
||||||
(), u16, 0
|
(), 0
|
||||||
> ,(), u32, 4
|
> ,(), u16, 4
|
||||||
> ,Option<()> , u16, 9
|
> ,Option<()> , u32, 9
|
||||||
> ,() , 13
|
> ,() ,u16. 13
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
|
||||||
@ -327,7 +303,7 @@ NEUE IDEE: IndexStore
|
|||||||
|
|
||||||
DirectHashLookup {
|
DirectHashLookup {
|
||||||
store() -> <empt<>
|
store() -> <empt<>
|
||||||
load(LodPos) -> LodPos
|
load(LodPos) -> LodAbs
|
||||||
}
|
}
|
||||||
|
|
||||||
NestedVecLokup {
|
NestedVecLokup {
|
||||||
|
Loading…
Reference in New Issue
Block a user