//! 内存域范围定义

/// 最大支持 4 个内存域
pub const NR_MEMS: usize = 4;

/// 内存域定义
pub struct MemDefine {
    mems: [(usize, usize); NR_MEMS],
    nr_mems: usize,
}

impl MemDefine {
    /// 创建内存域定义
    pub const fn create(mems: [(usize, usize); NR_MEMS], nr_mems: usize) -> Self {
        Self { mems, nr_mems }
    }

    /// 获取内存域
    ///
    /// 返回 (起始地址, 大小)`(start, size)`
    #[inline(always)]
    pub fn mem(&self, index: usize) -> (usize, usize) {
        if index >= self.nr_mems { (0, 0) } else { self.mems[index] }
    }

    /// 获取最大内存索引
    #[inline(always)]
    pub fn nr_mems(&self) -> usize {
        self.nr_mems
    }
}
