-
Notifications
You must be signed in to change notification settings - Fork 0
Assignment1 implementation #1
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
base: main
Are you sure you want to change the base?
Conversation
| #[derive(Debug)] | ||
| pub struct ClanSystem { | ||
| // TODO: add necessary fields | ||
| pub clans: Vec<Clan>, |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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()) | ||
| } | ||
|
|
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
|
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! |
Implement codes following Assignment 1 requirements.