//! [TSM.ID].[11031972] — Platform X Ecosystem
//! xcu-memory-pool — Zero-Copy Slab Memory Allocator
#![deny(warnings)]
#![allow(dead_code)]

pub mod pool;
pub mod allocator;

#[derive(Debug)]
pub enum PoolError {
    OutOfMemory,
    InvalidBlockSize,
    DoubleFree,
    InvalidPointer,
    PoolExhausted,
}

impl std::fmt::Display for PoolError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::OutOfMemory => write!(f, "Out of memory"),
            Self::InvalidBlockSize => write!(f, "Invalid block size"),
            Self::DoubleFree => write!(f, "Double free detected"),
            Self::InvalidPointer => write!(f, "Invalid pointer"),
            Self::PoolExhausted => write!(f, "Pool exhausted"),
        }
    }
}
impl std::error::Error for PoolError {}
pub type Result<T> = std::result::Result<T, PoolError>;

pub struct PoolConfig {
    pub block_size: usize,
    pub num_blocks: usize,
    pub alignment: usize,
}

impl Default for PoolConfig {
    fn default() -> Self {
        Self { block_size: 4096, num_blocks: 256, alignment: 8 }
    }
}

pub struct PoolStats {
    pub total_blocks: usize,
    pub used_blocks: usize,
    pub free_blocks: usize,
    pub total_bytes: usize,
    pub used_bytes: usize,
    pub peak_usage: usize,
    pub alloc_count: u64,
    pub free_count: u64,
}
