use super::constants::MAX_SMALL_ALLOCATION;

pub const NUM_SIZE_CLASSES: usize = 25;

pub const CLASS_TO_SIZE: [usize; NUM_SIZE_CLASSES] = [
    16, 16, 32, 48, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 448, 512, 640, 768, 896,
    1024, 2048, 4096, 8192, 16384,
];

#[inline(always)]
pub const fn byte_size_for_class(class: u8) -> usize {
    CLASS_TO_SIZE[class as usize]
}

#[inline(always)]
pub const fn size_class_for(size: usize) -> Option<u8> {
    if size <= 16 {
        Some(1)
    } else if size <= 32 {
        Some(2)
    } else if size <= 48 {
        Some(3)
    } else if size <= 64 {
        Some(4)
    } else if size <= 80 {
        Some(5)
    } else if size <= 96 {
        Some(6)
    } else if size <= 112 {
        Some(7)
    } else if size <= 128 {
        Some(8)
    } else if size <= 160 {
        Some(9)
    } else if size <= 192 {
        Some(10)
    } else if size <= 224 {
        Some(11)
    } else if size <= 256 {
        Some(12)
    } else if size <= 320 {
        Some(13)
    } else if size <= 384 {
        Some(14)
    } else if size <= 448 {
        Some(15)
    } else if size <= 512 {
        Some(16)
    } else if size <= 640 {
        Some(17)
    } else if size <= 768 {
        Some(18)
    } else if size <= 896 {
        Some(19)
    } else if size <= 1024 {
        Some(20)
    } else if size <= 2048 {
        Some(21)
    } else if size <= 4096 {
        Some(22)
    } else if size <= 8192 {
        Some(23)
    } else if size <= 16384 {
        Some(24)
    } else {
        None
    }
}

#[inline(always)]
pub const fn is_small_allocation(size: usize) -> bool {
    size <= MAX_SMALL_ALLOCATION
}
