Update ShardAndCommittee per new spec

- `shard_id` -> `shard`
This commit is contained in:
Paul Hauner 2018-10-23 12:28:07 +02:00
parent 42e774cb48
commit 0536fb4a91
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
2 changed files with 9 additions and 9 deletions

View File

@ -1,6 +1,6 @@
#[derive(Clone, Debug, PartialEq)]
pub struct ShardAndCommittee {
pub shard_id: u16,
pub shard: u16,
pub committee: Vec<usize>
}
@ -9,7 +9,7 @@ impl ShardAndCommittee {
/// committee is an empty vector.
pub fn zero() -> Self {
Self {
shard_id: 0,
shard: 0,
committee: vec![],
}
}
@ -22,7 +22,7 @@ mod tests {
#[test]
fn test_shard_and_committee_zero() {
let s = ShardAndCommittee::zero();
assert_eq!(s.shard_id, 0);
assert_eq!(s.shard, 0);
assert_eq!(s.committee.len(), 0);
}
}

View File

@ -86,12 +86,12 @@ fn generate_cycle(
let cycle = validator_indices.honey_badger_split(cycle_length)
.enumerate()
.map(|(i, slot_indices)| {
let shard_id_start = crosslinking_shard_start + i * committees_per_slot / slots_per_committee;
let shard_start = crosslinking_shard_start + i * committees_per_slot / slots_per_committee;
slot_indices.honey_badger_split(committees_per_slot)
.enumerate()
.map(|(j, shard_indices)| {
ShardAndCommittee{
shard_id: ((shard_id_start + j) % shard_count) as u16,
shard: ((shard_start + j) % shard_count) as u16,
committee: shard_indices.to_vec(),
}
})
@ -141,8 +141,8 @@ mod tests {
slot.iter()
.enumerate()
.for_each(|(i, sac)| {
println!("#{:?}\tshard_id={}\tcommittee.len()={}",
&i, &sac.shard_id, &sac.committee.len())
println!("#{:?}\tshard={}\tcommittee.len()={}",
&i, &sac.shard, &sac.committee.len())
})
});
}
@ -167,7 +167,7 @@ mod tests {
let mut flattened = vec![];
for slot in cycle.iter() {
for sac in slot.iter() {
flattened.push(sac.shard_id as usize);
flattened.push(sac.shard as usize);
}
}
flattened.dedup();
@ -181,7 +181,7 @@ mod tests {
for slot in cycle.iter() {
let mut shards: Vec<usize> = vec![];
for sac in slot.iter() {
shards.push(sac.shard_id as usize);
shards.push(sac.shard as usize);
}
shards_in_slots.push(shards);
}