Repository: qdrant/qdrant
File: lib/collection/src/shards/shard_holder/shard_mapping.rs (Rust)

Code before:
                    .map(|shard_id| (*shard_id, shard_key.clone()))
            })
            .collect()
    }

    /// Return all shard IDs from the mappings
    pub fn shard_ids(&self) -> Vec<ShardId> {
        let ids = self.iter_shard_ids().collect::<Vec<_>>();

        debug_assert!(
            ids.iter().all_unique(),
            "shard mapping contains duplicate shard IDs",
        );

        ids
    }

    /// Iterate over all shard IDs from the mappings
    pub fn iter_shard_ids(&self) -> impl Iterator<Item = ShardId> {
        self.shard_key_to_shard_ids
            .values()
            .flat_map(|shard_ids| shard_ids.iter().copied())
    }

    pub fn iter_shard_keys(&self) -> impl Iterator<Item = &ShardKey> {
        self.shard_key_to_shard_ids.keys()
    }

    /// Get the shard key for a given shard ID
    ///
    /// `None` is returned if the shard ID has no key, or if the shard ID is unknown
    pub fn shard_key(&self, shard_id: ShardId) -> Option<ShardKey> {
        self.shard_key_to_shard_ids
            .iter()
            .find(|(_, shard_ids)| shard_ids.contains(&shard_id))
            .map(|(key, _)| key.clone())
    }
}

impl From<SerdeHelper> for ShardKeyMapping {
    fn from(helper: SerdeHelper) -> Self {
        let mut was_old_format = false;

        let shard_key_to_shard_ids = match helper {
            SerdeHelper::New(key_ids_pairs) => key_ids_pairs
                .into_iter()
                .map(KeyIdsPair::into_parts)
                .collect(),

            SerdeHelper::Old(key_ids_map) => {
                was_old_format = true;

Review comment (suggestion):
Function name is clear, but just for consistency
```suggestion
    /// Iterate over all shard keys
    pub fn iter_shard_keys(&self) -> impl Iterator<Item = &ShardKey> {
```

Code after:
                    .map(|shard_id| (*shard_id, shard_key.clone()))
            })
            .collect()
    }

    /// Return all shard IDs from the mappings
    pub fn shard_ids(&self) -> Vec<ShardId> {
        let ids = self.iter_shard_ids().collect::<Vec<_>>();

        debug_assert!(
            ids.iter().all_unique(),
            "shard mapping contains duplicate shard IDs",
        );

        ids
    }

    /// Iterate over all shard IDs from the mappings
    pub fn iter_shard_ids(&self) -> impl Iterator<Item = ShardId> {
        self.shard_key_to_shard_ids
            .values()
            .flat_map(|shard_ids| shard_ids.iter().copied())
    }

    /// Iterate over all shard keys
    pub fn iter_shard_keys(&self) -> impl Iterator<Item = &ShardKey> {
        self.shard_key_to_shard_ids.keys()
    }

    /// Get the shard key for a given shard ID
    ///
    /// `None` is returned if the shard ID has no key, or if the shard ID is unknown
    pub fn shard_key(&self, shard_id: ShardId) -> Option<ShardKey> {
        self.shard_key_to_shard_ids
            .iter()
            .find(|(_, shard_ids)| shard_ids.contains(&shard_id))
            .map(|(key, _)| key.clone())
    }
}

impl From<SerdeHelper> for ShardKeyMapping {
    fn from(helper: SerdeHelper) -> Self {
        let mut was_old_format = false;

        let shard_key_to_shard_ids = match helper {
            SerdeHelper::New(key_ids_pairs) => key_ids_pairs
                .into_iter()
                .map(KeyIdsPair::into_parts)
                .collect(),

            SerdeHelper::Old(key_ids_map) => {