cs431_homework/hello_server/
statistics.rs1use std::collections::HashMap;
4
5#[derive(Debug)]
7pub struct Report {
8 _id: usize,
9 key: Option<String>, }
11
12impl Report {
13 pub fn new(id: usize, key: Option<String>) -> Self {
15 Report { _id: id, key }
16 }
17}
18
19#[derive(Debug, Default)]
21pub struct Statistics {
22 hits: HashMap<Option<String>, usize>,
23}
24
25impl Statistics {
26 pub fn add_report(&mut self, report: Report) {
28 let hits = self.hits.entry(report.key).or_default();
29 *hits += 1;
30 }
31}