use crate::range::Range;
use ckey::CKey;
use std::fmt::Formatter;
#[derive(Debug, PartialEq, Eq)]
pub struct Node {
pub key: CKey,
next_key: Option<CKey>,
prev_key: Option<CKey>,
}
impl Node {
pub fn new_rand() -> Node {
Self::new_with_key(CKey::new_rand())
}
pub fn new_test(v: f64) -> Node {
Self::new_with_key(CKey::from(v))
}
fn new_with_key(key: CKey) -> Node {
Node {
key,
next_key: None,
prev_key: None,
}
}
pub fn range(&self) -> Range {
Range::new(self.prev_key.unwrap_or(self.key), self.key)
}
}
impl std::fmt::Display for Node {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{{\"key\":{}}}", self.key)
}
}