#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "std")]
extern crate elastic_array;
#[cfg(feature = "std")]
extern crate core;
#[cfg(feature = "std")]
use elastic_array::ElasticArray128;
#[cfg(feature = "std")]
use std::collections::HashMap;
use core::{fmt::Debug, hash::Hash};
pub trait Hasher: Sync + Send {
type Out: AsRef<[u8]> + AsMut<[u8]> + Default + Debug + PartialEq + Eq + Hash + Send + Sync + Clone + Copy;
type StdHasher: Sync + Send + Default + core::hash::Hasher;
const LENGTH: usize;
fn hash(x: &[u8]) -> Self::Out;
}
#[cfg(feature = "std")]
pub type DBValue = ElasticArray128<u8>;
#[cfg(feature = "std")]
pub trait HashDB<H: Hasher>: Send + Sync + AsHashDB<H> {
fn keys(&self) -> HashMap<H::Out, i32>;
fn get(&self, key: &H::Out) -> Option<DBValue>;
fn contains(&self, key: &H::Out) -> bool;
fn insert(&mut self, value: &[u8]) -> H::Out;
fn emplace(&mut self, key: H::Out, value: DBValue);
fn remove(&mut self, key: &H::Out);
}
#[cfg(feature = "std")]
pub trait AsHashDB<H: Hasher> {
fn as_hashdb(&self) -> &HashDB<H>;
fn as_hashdb_mut(&mut self) -> &mut HashDB<H>;
}
#[cfg(feature = "std")]
impl<'a, H: Hasher> AsHashDB<H> for &'a mut HashDB<H> {
fn as_hashdb(&self) -> &HashDB<H> { &**self }
fn as_hashdb_mut(&mut self) -> &mut HashDB<H> { &mut **self }
}