Rename cur_hashes to num_hashes

This commit is contained in:
Greg Fitzgerald 2018-08-09 08:31:00 -06:00
parent 8ca514a5ca
commit ca7d4c42dd
3 changed files with 13 additions and 13 deletions

View File

@ -856,11 +856,11 @@ mod tests {
fn create_sample_block(mint: &Mint, length: usize) -> impl Iterator<Item = Entry> { fn create_sample_block(mint: &Mint, length: usize) -> impl Iterator<Item = Entry> {
let mut entries = Vec::with_capacity(length); let mut entries = Vec::with_capacity(length);
let mut hash = mint.last_id(); let mut hash = mint.last_id();
let mut cur_hashes = 0; let mut num_hashes = 0;
for _ in 0..length { for _ in 0..length {
let keypair = KeyPair::new(); let keypair = KeyPair::new();
let tx = Transaction::new(&mint.keypair(), keypair.pubkey(), 1, hash); let tx = Transaction::new(&mint.keypair(), keypair.pubkey(), 1, hash);
let entry = Entry::new_mut(&mut hash, &mut cur_hashes, vec![tx], false); let entry = Entry::new_mut(&mut hash, &mut num_hashes, vec![tx], false);
entries.push(entry); entries.push(entry);
} }
entries.into_iter() entries.into_iter()

View File

@ -54,11 +54,11 @@ impl Entry {
/// Creates the next Entry `num_hashes` after `start_hash`. /// Creates the next Entry `num_hashes` after `start_hash`.
pub fn new( pub fn new(
start_hash: &Hash, start_hash: &Hash,
cur_hashes: u64, num_hashes: u64,
transactions: Vec<Transaction>, transactions: Vec<Transaction>,
has_more: bool, has_more: bool,
) -> Self { ) -> Self {
let num_hashes = cur_hashes + if transactions.is_empty() { 0 } else { 1 }; let num_hashes = num_hashes + if transactions.is_empty() { 0 } else { 1 };
let id = next_hash(start_hash, 0, &transactions); let id = next_hash(start_hash, 0, &transactions);
let entry = Entry { let entry = Entry {
num_hashes, num_hashes,
@ -123,13 +123,13 @@ impl Entry {
/// Creates the next Tick Entry `num_hashes` after `start_hash`. /// Creates the next Tick Entry `num_hashes` after `start_hash`.
pub fn new_mut( pub fn new_mut(
start_hash: &mut Hash, start_hash: &mut Hash,
cur_hashes: &mut u64, num_hashes: &mut u64,
transactions: Vec<Transaction>, transactions: Vec<Transaction>,
has_more: bool, has_more: bool,
) -> Self { ) -> Self {
let entry = Self::new(start_hash, *cur_hashes, transactions, has_more); let entry = Self::new(start_hash, *num_hashes, transactions, has_more);
*start_hash = entry.id; *start_hash = entry.id;
*cur_hashes = 0; *num_hashes = 0;
assert!(serialized_size(&entry).unwrap() <= BLOB_DATA_SIZE as u64); assert!(serialized_size(&entry).unwrap() <= BLOB_DATA_SIZE as u64);
entry entry
} }

View File

@ -427,16 +427,16 @@ pub fn reconstruct_entries_from_blobs(blobs: VecDeque<SharedBlob>) -> Result<Vec
} }
/// Creates the next entries for given transactions, outputs /// Creates the next entries for given transactions, outputs
/// updates start_hash to id of last Entry, sets cur_hashes to 0 /// updates start_hash to id of last Entry, sets num_hashes to 0
pub fn next_entries_mut( pub fn next_entries_mut(
start_hash: &mut Hash, start_hash: &mut Hash,
cur_hashes: &mut u64, num_hashes: &mut u64,
transactions: Vec<Transaction>, transactions: Vec<Transaction>,
) -> Vec<Entry> { ) -> Vec<Entry> {
// TODO: find a magic number that works better than | ? // TODO: find a magic number that works better than | ?
// V // V
if transactions.is_empty() || transactions.len() == 1 { if transactions.is_empty() || transactions.len() == 1 {
vec![Entry::new_mut(start_hash, cur_hashes, transactions, false)] vec![Entry::new_mut(start_hash, num_hashes, transactions, false)]
} else { } else {
let mut start = 0; let mut start = 0;
let mut entries = Vec::new(); let mut entries = Vec::new();
@ -478,7 +478,7 @@ pub fn next_entries_mut(
} }
entries.push(Entry::new_mut( entries.push(Entry::new_mut(
start_hash, start_hash,
cur_hashes, num_hashes,
transactions[start..chunk_end].to_vec(), transactions[start..chunk_end].to_vec(),
transactions.len() - chunk_end > 0, transactions.len() - chunk_end > 0,
)); ));
@ -492,11 +492,11 @@ pub fn next_entries_mut(
/// Creates the next Entries for given transactions /// Creates the next Entries for given transactions
pub fn next_entries( pub fn next_entries(
start_hash: &Hash, start_hash: &Hash,
cur_hashes: u64, num_hashes: u64,
transactions: Vec<Transaction>, transactions: Vec<Transaction>,
) -> Vec<Entry> { ) -> Vec<Entry> {
let mut id = *start_hash; let mut id = *start_hash;
let mut num_hashes = cur_hashes; let mut num_hashes = num_hashes;
next_entries_mut(&mut id, &mut num_hashes, transactions) next_entries_mut(&mut id, &mut num_hashes, transactions)
} }