Created
February 1, 2016 21:07
-
-
Save gavofyork/a3b30ada373bddc14d45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub struct StandardMap { | |
min_key: usize, | |
journal_key: usize, | |
count: usize, | |
} | |
impl StandardMap { | |
fn random_bytes(min_count: usize, journal_count: usize, seed: &mut H256) -> Vec<u8> { | |
assert!(min_count + journal_count <= 32); | |
*seed = seed.sha3(); | |
let r = min_count + (seed.bytes()[31] as usize % (journal_count + 1)); | |
seed.bytes()[0..r].to_vec() | |
} | |
pub fn make(&self) -> Vec<(Bytes, Bytes)> { | |
let low = b"abcdef"; | |
let mid = b"@QWERTYUIOPASDFGHJKLZXCVBNM[/]^_"; | |
let mut d: Vec<(Bytes, Bytes)> = Vec::new(); | |
let mut seed = H256::new(); | |
for _ in 0..self.count { | |
let k = Alphabet::All => Self::random_bytes(self.min_key, self.journal_key, &mut seed), | |
let v = k.clone(); | |
d.push((k, v)) | |
} | |
d | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment