Skip to content

Conversation

@TiteTia
Copy link
Owner

@TiteTia TiteTia commented Jan 26, 2024

Implement codes following Assignment 1 requirements.

@TiteTia TiteTia requested a review from 186shades January 29, 2024 05:09
#[derive(Debug)]
pub struct ClanSystem {
// TODO: add necessary fields
pub clans: Vec<Clan>,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would using a std::collections::HashMap be better than Vec<Clan> here as clan ids are unique anyway?

*/
pub fn get_clan_member_names(&self, clan_id: &str) -> Vec<String> {
unimplemented!();
if let Some(clan) = self.clans.iter().find(|c| c.id == clan_id) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could using the hashmap help increase efficiency here as we might not have to iter through the whole list explicitely?

*/
pub fn get_clan_member_count(&self, clan_id: &str) -> usize {
unimplemented!();
if let Some(clan) = self.clans.iter().find(|c| c.id == clan_id) {
Copy link

@186shades 186shades Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hashmap could help improve brevity and efficiency here as well I think.

}

pub fn add_member_to_clan(&mut self, clan_id: &str, crab_name: &str) {
if let Some(clan) = self.clans.iter_mut().find(|c| c.id == clan_id) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also maybe make this implemetation succint & efficient by use of hashmap and functions available for hashmap?

.max_by_key(|clan| clan.members.len())
.map(|clan| clan.id.clone())
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add comment over this function to explain what it does to increase readability?

fn get_crab_speed_by_name(&self, crab_name: &str) -> Result<u32, String> {
for crab in self.crabs() {
if crab.name() == crab_name {
return Ok(crab.speed());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the keyword return here for consistency in coding style?

}
}

fn calculate_average_speed(&self, clan_id: &str) -> Result<u32, String> {
Copy link

@186shades 186shades Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job of breaking a big function into smaller logical functions! Could we add comment over this function to explain what it does to increase readability?

}
}

fn get_crab_speed_by_name(&self, crab_name: &str) -> Result<u32, String> {
Copy link

@186shades 186shades Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job of breaking a big function into smaller logical functions! Could we add comment over this function to explain what it does to increase readability?


#[derive(Debug)]
pub struct Beach {
// TODO: Declare the fields of the Beach struct here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove the TODO: statements here if they are no longer needed?

}

fn calculate_average_speed(&self, clan_id: &str) -> Result<u32, String> {
let clan_system = self.get_clan_system(); // Assuming you have a method to get the clan system

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this comment as we do have a method to get clan system in the code?

@186shades
Copy link

Overall LGTM, also all given test cases passed when I checked. Please have a look at the comments and let me know what you think!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants