Sha256: aa1fdadd31b43295b49c6d0d31dedf6ef2834a771b530b62e1f15cc15b5aa391
Contents?: true
Size: 661 Bytes
Versions: 157
Compression:
Stored size: 661 Bytes
Contents
use std::collections::HashMap; pub struct School { grades: HashMap<u32, Vec<String>> } impl School { pub fn new() -> School { School { grades: HashMap::new() } } pub fn add(&mut self, grade: u32, student: &str) { let entry = self.grades.entry(grade).or_insert(Vec::new()); entry.push(student.to_string()); entry.sort(); } pub fn grades(&self) -> Vec<u32> { let mut s = self.grades.keys().cloned().collect::<Vec<u32>>(); s.sort(); s } pub fn grade(&self, grade: u32) -> Option<Vec<String>> { self.grades.get(&grade).map(|v| v.iter().cloned().collect()) } }
Version data entries
157 entries across 157 versions & 1 rubygems