Debian Codegraph @

src/impls/create.rs

raw symbols SCIP
1 use crate::Counter;
2
3 use num_traits::Zero;
4
5 use std::collections::HashMap;
6 use std::hash::Hash;
7
8 impl<T, N> Counter<T, N>
9 where
10 T: Hash + Eq,
11 N: Zero,
12 {
13 /// Create a new, empty `Counter`
14 pub fn new() -> Self {
15 Counter {
16 map: HashMap::new(),
17 zero: N::zero(),
18 }
19 }
20
21 /// Create a new, empty `Counter` with the specified capacity.
22 ///
23 /// Note that `capacity` in this case indicates how many distinct items may be counted without reallocation.
24 /// It is not related to the total number of items which may be counted.
25 /// For example, `"aaa"` requires a capacity of 1. `"abc"` requires a capacity of 3.
26 pub fn with_capacity(capacity: usize) -> Self {
27 Counter {
28 map: HashMap::with_capacity(capacity),
29 zero: N::zero(),
30 }
31 }
32 }
33
34 impl<T, N> Default for Counter<T, N>
35 where
36 T: Hash + Eq,
37 N: Default,
38 {
39 fn default() -> Self {
40 Self {
41 map: HashMap::default(),
42 zero: N::default(),
43 }
44 }
45 }