Move shuffling mod into state/transition

This commit is contained in:
Paul Hauner 2018-08-24 16:01:24 +10:00
parent 1a00f5b429
commit 6f08700ea0
4 changed files with 12 additions and 11 deletions

View File

@ -8,13 +8,12 @@ extern crate futures;
pub mod db;
pub mod client;
pub mod shuffling;
pub mod state;
pub mod sync;
pub mod utils;
pub mod config;
use std::path::PathBuf;
use std::path::PathBuf;
use slog::Drain;
use clap::{ Arg, App };
@ -59,9 +58,9 @@ fn main() {
return;
}
}
// Log configuration
info!(log, "";
info!(log, "";
"data_dir" => &config.data_dir.to_str(),
"port" => &config.p2p_listen_port);

View File

@ -9,3 +9,5 @@ pub enum TransitionError {
InvalidInput(String),
}

View File

@ -9,18 +9,18 @@ pub enum ShuffleErr {
ExceedsListLength,
}
/// Performs a deterministic, in-place shuffle of a vector of bytes.
/// Performs a deterministic, in-place shuffle of a vector of bytes.
/// The final order of the shuffle is determined by successive hashes
/// of the supplied `seed`.
pub fn shuffle(
seed: &[u8],
mut list: Vec<usize>)
mut list: Vec<usize>)
-> Result<Vec<usize>, ShuffleErr>
{
let mut rng = ShuffleRng::new(seed);
if list.len() > rng.rand_max as usize {
return Err(ShuffleErr::ExceedsListLength);
}
}
for i in 0..(list.len() - 1) {
let n = list.len() - i;
let j = rng.rand_range(n as u32) as usize + i;

View File

@ -94,22 +94,22 @@ mod tests {
&[0, 1, 1],
0);
assert_eq!(x, 257);
x = int_from_byte_slice(
&[1, 1, 1],
0);
assert_eq!(x, 65793);
x = int_from_byte_slice(
&[255, 1, 1],
0);
assert_eq!(x, 16711937);
x = int_from_byte_slice(
&[255, 255, 255],
0);
assert_eq!(x, 16777215);
x = int_from_byte_slice(
&[0x8f, 0xbb, 0xc7],
0);