mirror of https://github.com/vacp2p/pmtree.git
chore: add template for the project
This commit is contained in:
parent
5e618fb529
commit
fd89299abe
68
src/lib.rs
68
src/lib.rs
|
@ -1,14 +1,62 @@
|
|||
pub fn add(left: usize, right: usize) -> usize {
|
||||
left + right
|
||||
}
|
||||
pub struct Error(String);
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
pub struct VecDB;
|
||||
pub struct Poseidon;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
pub type DefaultDatabase = VecDB;
|
||||
pub type DefaultHasher = Poseidon;
|
||||
|
||||
impl Hasher for Poseidon {
|
||||
type Fr = i32;
|
||||
|
||||
fn hash(_input: &[i32]) -> i32 {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
impl Database for VecDB {
|
||||
fn new(dbpath: &str) -> Self {
|
||||
Self {}
|
||||
}
|
||||
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>> {
|
||||
Ok(Some(vec![]))
|
||||
}
|
||||
fn put(&mut self, key: &[u8]) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
fn delete(&mut self, key: &[u8]) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Hasher {
|
||||
type Fr: Copy + Eq + Default;
|
||||
|
||||
fn hash(input: &[Self::Fr]) -> Self::Fr;
|
||||
}
|
||||
|
||||
pub trait Database {
|
||||
fn new(dbpath: &str) -> Self;
|
||||
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>;
|
||||
fn put(&mut self, key: &[u8]) -> Result<()>;
|
||||
fn delete(&mut self, key: &[u8]) -> Result<()>;
|
||||
}
|
||||
|
||||
pub struct MerkleTree<D = DefaultDatabase, H = DefaultHasher>
|
||||
where
|
||||
D: Database,
|
||||
H: Hasher,
|
||||
{
|
||||
db: D,
|
||||
h: H,
|
||||
}
|
||||
|
||||
impl MerkleTree {}
|
||||
|
||||
impl<D, H> MerkleTree<D, H>
|
||||
where
|
||||
D: Database,
|
||||
H: Hasher,
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue