MCPcopy Create free account
hub / github.com/QMHTMY/RustBook / new

Method new

publication/code/chapter06/hashmap.rs:12–22  ·  view source on GitHub ↗
(cap: usize)

Source from the content-addressed store, hash-verified

10
11impl<T: Clone + PartialEq + Default> HashMap<T> {
12 fn new(cap: usize) -> Self {
13 // 初始化 slot 和 data
14 let mut slot = Vec::with_capacity(cap);
15 let mut data = Vec::with_capacity(cap);
16 for _i in 0..cap{
17 slot.push(0);
18 data.push(Default::default());
19 }
20
21 HashMap { cap, slot, data }
22 }
23
24 fn len(&self) -> usize {
25 let mut len = 0;

Callers

nothing calls this directly

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected