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 {
|
pub struct Error(String);
|
||||||
left + right
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
pub struct VecDB;
|
||||||
mod tests {
|
pub struct Poseidon;
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
pub type DefaultDatabase = VecDB;
|
||||||
fn it_works() {
|
pub type DefaultHasher = Poseidon;
|
||||||
let result = add(2, 2);
|
|
||||||
assert_eq!(result, 4);
|
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