use std::sync::Arc;
use gen_core::NodeIntervalBlock;
use intervaltree::IntervalTree;
use crate::db::GraphConnection;
pub trait IntervalTreeSource {
type Error;
fn cached_interval_tree(&self) -> Option<&Arc<IntervalTree<i64, NodeIntervalBlock>>>;
fn set_cached_interval_tree(
&mut self,
interval_tree: Option<Arc<IntervalTree<i64, NodeIntervalBlock>>>,
);
fn load_interval_tree(
&self,
conn: &GraphConnection,
) -> Result<Arc<IntervalTree<i64, NodeIntervalBlock>>, Self::Error>;
fn intervaltree(
&self,
conn: &GraphConnection,
) -> Result<Arc<IntervalTree<i64, NodeIntervalBlock>>, Self::Error> {
if let Some(interval_tree) = self.cached_interval_tree() {
return Ok(Arc::clone(interval_tree));
}
self.load_interval_tree(conn)
}
}