use vibesql_types::SqlValue;
use super::super::NULL_PAGE_ID;
use crate::page::PageId;
pub type Key = Vec<SqlValue>;
pub type RowId = usize;
#[derive(Debug, Clone)]
pub struct InternalNode {
pub page_id: PageId,
pub keys: Vec<Key>,
pub children: Vec<PageId>,
}
impl InternalNode {
pub fn new(page_id: PageId) -> Self {
InternalNode { page_id, keys: Vec::new(), children: Vec::new() }
}
#[allow(dead_code)]
pub fn is_full(&self, degree: usize) -> bool {
self.children.len() >= degree
}
}
#[derive(Debug, Clone)]
pub struct LeafNode {
pub page_id: PageId,
pub entries: Vec<(Key, Vec<RowId>)>,
pub next_leaf: PageId,
pub prev_leaf: PageId,
}
impl LeafNode {
pub fn new(page_id: PageId) -> Self {
LeafNode { page_id, entries: Vec::new(), next_leaf: NULL_PAGE_ID, prev_leaf: NULL_PAGE_ID }
}
#[allow(dead_code)]
pub fn is_full(&self, degree: usize) -> bool {
self.entries.len() >= degree
}
#[allow(dead_code)]
pub fn is_underfull(&self, degree: usize) -> bool {
self.entries.len() < degree / 2
}
}