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

Method access

publication/code/chapter10/lru.rs:117–121  ·  view source on GitHub ↗

获取某个 key 的值,移除原来位置的值并在头部加入

(&mut self, key: &K)

Source from the content-addressed store, hash-verified

115
116 // 获取某个 key 的值,移除原来位置的值并在头部加入
117 fn access(&mut self, key: &K) {
118 let i = *self.map.get(key).unwrap();
119 self.remove_from_list(i);
120 self.head = Some(i);
121 }
122
123 fn remove_from_list(&mut self, i: usize) {
124 let (prev, next) = {

Callers 3

insertMethod · 0.45
getMethod · 0.45
get_mutMethod · 0.45

Calls 2

getMethod · 0.45
remove_from_listMethod · 0.45

Tested by

no test coverage detected