use std::collections::btree_map::BTreeMap;
type ID = usize;
type Binary = Vec<u8>;
const NIL: ID = 0;
pub trait Builder {
fn new() -> Self;
fn from_raw(raw: Binary) -> Self;
fn to_raw(&self) -> Binary;
}
pub struct Node<T> where T: Builder + Clone {
key: T,
now: ID,
parent: ID,
next: ID,
}
impl<T> Builder for Node<T> where T: Builder + Clone {
fn new() -> Self {
Self {
key: T::new(),
now: NIL,
parent: NIL,
next: NIL,
}
}
fn from_raw(raw: Binary) -> Self {unimplemented!()}
fn to_raw(&self) -> Binary {unimplemented!()}
}
pub type Tree<T> = Vec<Node<T>>;
trait DynamicTree<T> where T: Builder + Clone {
fn new() -> Self;
fn from_raw(raw: Binary) -> Self;
fn to_raw(&self) -> Binary;
fn add(&mut self) -> &mut Node<T>;
}
impl<T> DynamicTree<T> for Tree<T> where T: Builder + Clone {
fn new() -> Self {
Self::new()
}
fn from_raw(raw: Binary) -> Self {
unimplemented!()
}
fn to_raw(&self) -> Binary {
unimplemented!()
}
fn add(&mut self) -> &mut Node<T> {
let node: Node<T> = Node::new();
self.push(node);
unimplemented!()
}
}