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

Method access

code/chapter09/lru.rs:109–113  ·  view source on GitHub ↗

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

(&mut self, key: &K)

Source from the content-addressed store, hash-verified

107
108 // 获取某个 key 的值,移除原来位置的值并在头部加入
109 fn access(&mut self, key: &K) {
110 let i = *self.map.get(key).unwrap();
111 self.remove_from_list(i);
112 self.head = Some(i);
113 }
114
115 fn remove_from_list(&mut self, i: usize) {
116 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