pub mod compressible;
pub mod compressible_reader;
pub mod hash_map;
pub use compressible::*;
pub use compressible_reader::*;
pub use hash_map::*;
use building_blocks_core::prelude::*;
use auto_impl::auto_impl;
use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Deserialize, Hash, Eq, PartialEq, Serialize)]
pub struct ChunkKey<N> {
pub minimum: PointN<N>,
pub lod: u8,
}
pub type ChunkKey2 = ChunkKey<[i32; 2]>;
pub type ChunkKey3 = ChunkKey<[i32; 3]>;
impl<N> ChunkKey<N> {
pub fn new(lod: u8, chunk_minimum: PointN<N>) -> Self {
Self {
lod,
minimum: chunk_minimum,
}
}
}
#[auto_impl(&, &mut)]
pub trait ChunkReadStorage<N, Ch> {
fn get(&self, key: ChunkKey<N>) -> Option<&Ch>;
}
#[auto_impl(&mut)]
pub trait ChunkWriteStorage<N, Ch> {
fn get_mut(&mut self, key: ChunkKey<N>) -> Option<&mut Ch>;
fn get_mut_or_insert_with(
&mut self,
key: ChunkKey<N>,
create_chunk: impl FnOnce() -> Ch,
) -> &mut Ch;
fn replace(&mut self, key: ChunkKey<N>, chunk: Ch) -> Option<Ch>;
fn write(&mut self, key: ChunkKey<N>, chunk: Ch);
fn delete(&mut self, key: ChunkKey<N>);
fn pop(&mut self, key: ChunkKey<N>) -> Option<Ch>;
}
#[auto_impl(&, &mut)]
pub trait IterChunkKeys<'a, N>
where
ChunkKey<N>: 'a,
{
type Iter: Iterator<Item = &'a ChunkKey<N>>;
fn chunk_keys(&'a self) -> Self::Iter;
}