Build a cache from a list of changelist entries. This is used to seed the cache from a full changelist download (e.g., on the first sync).
(entries: &[ChangelistEntry])
| 149 | /// This is used to seed the cache from a full changelist download |
| 150 | /// (e.g., on the first sync). |
| 151 | pub fn from_changelist(entries: &[ChangelistEntry]) -> Self { |
| 152 | let mut cache = Self::empty(); |
| 153 | for entry in entries { |
| 154 | let node = entry.to_node(); |
| 155 | cache.entries.insert(entry.sequence, node); |
| 156 | cache.last_sequence = Some(entry.sequence); |
| 157 | cache.last_state = Some(entry.merkle.clone()); |
| 158 | } |
| 159 | cache |
| 160 | } |
| 161 | |
| 162 | /// Get the cached node at a given sequence number. |
| 163 | pub fn get(&self, sequence: u64) -> Option<&Node> { |