Skip to content

Commit

Permalink
refactor: remove some more usage of num_shards() (#10291)
Browse files Browse the repository at this point in the history
See #10237.
  • Loading branch information
akhi3030 authored Dec 4, 2023
1 parent 82544e1 commit 5ec1ae5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/primitives/src/shard_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ impl ShardLayout {

/// Returns shard uids for all shards in the shard layout
pub fn get_shard_uids(&self) -> Vec<ShardUId> {
(0..self.num_shards()).map(|x| ShardUId::from_shard_id_and_layout(x, self)).collect()
self.shard_ids()
.map(|shard_id| ShardUId::from_shard_id_and_layout(shard_id, self))
.collect()
}
}

Expand Down Expand Up @@ -302,7 +304,7 @@ impl ShardUId {

/// Constructs a shard uid from shard id and a shard layout
pub fn from_shard_id_and_layout(shard_id: ShardId, shard_layout: &ShardLayout) -> Self {
assert!(shard_id < shard_layout.num_shards());
assert!(shard_layout.shard_ids().any(|i| i == shard_id));
Self { shard_id: shard_id as u32, version: shard_layout.version() }
}

Expand Down Expand Up @@ -483,7 +485,7 @@ mod tests {
let num_shards = 4;
let shard_layout = ShardLayout::v0(num_shards, 0);
let mut shard_id_distribution: HashMap<_, _> =
(0..num_shards).map(|x| (x, 0)).into_iter().collect();
shard_layout.shard_ids().map(|shard_id| (shard_id, 0)).collect();
let mut rng = StdRng::from_seed([0; 32]);
for _i in 0..1000 {
let s: Vec<u8> = (&mut rng).sample_iter(&Alphanumeric).take(10).collect();
Expand Down

0 comments on commit 5ec1ae5

Please sign in to comment.