1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
mod bitfield;
mod error;
mod hamt;
mod hash;
mod hash_algorithm;
mod hash_bits;
mod node;
mod pointer;
pub use self::error::Error;
pub use self::hamt::Hamt;
pub use self::hash::*;
pub use self::hash_algorithm::*;
use serde::{Deserialize, Serialize};
use std::borrow::Borrow;
use std::hash::Hasher;
use std::ops::Deref;
const MAX_ARRAY_WIDTH: usize = 3;
const DEFAULT_BIT_WIDTH: u32 = 8;
type HashedKey = [u8; 32];
#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct KeyValuePair<K, V>(K, V);
impl<K, V> KeyValuePair<K, V> {
pub fn key(&self) -> &K {
&self.0
}
pub fn value(&self) -> &V {
&self.1
}
}
impl<K, V> KeyValuePair<K, V> {
pub fn new(key: K, value: V) -> Self {
KeyValuePair(key, value)
}
}
#[derive(Eq, PartialOrd, Clone, Debug, Serialize, Deserialize)]
#[serde(transparent)]
pub struct BytesKey(#[serde(with = "serde_bytes")] pub Vec<u8>);
impl PartialEq for BytesKey {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl Hash for BytesKey {
fn hash<H: Hasher>(&self, state: &mut H) {
state.write(&self.0);
}
}
impl Borrow<[u8]> for BytesKey {
fn borrow(&self) -> &[u8] {
&self.0
}
}
impl Borrow<Vec<u8>> for BytesKey {
fn borrow(&self) -> &Vec<u8> {
&self.0
}
}
impl Deref for BytesKey {
type Target = Vec<u8>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl From<Vec<u8>> for BytesKey {
fn from(bz: Vec<u8>) -> Self {
BytesKey(bz)
}
}
impl From<&[u8]> for BytesKey {
fn from(s: &[u8]) -> Self {
Self(s.to_vec())
}
}
impl From<&str> for BytesKey {
fn from(s: &str) -> Self {
Self::from(s.as_bytes())
}
}