Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove some more usage of num_shards() #10291

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading