//! Node storage with memory-mapped files

use super::data_structures::NodeRec;
use anyhow::Result;

/// Node storage manager
pub struct NodeStore {
    // TODO: Implement memory-mapped file storage
    nodes: Vec<NodeRec>,
}

impl NodeStore {
    pub fn new() -> Self {
        Self { nodes: Vec::new() }
    }

    pub fn insert(&mut self, node: NodeRec) -> Result<u64> {
        let id = self.nodes.len() as u64;
        self.nodes.push(node);
        Ok(id)
    }

    pub fn get(&self, id: u64) -> Option<&NodeRec> {
        self.nodes.get(id as usize)
    }

    pub fn node_count(&self) -> usize {
        self.nodes.len()
    }
}

impl Default for NodeStore {
    fn default() -> Self {
        Self::new()
    }
}
