Take the next cache slot, returning (index, is_first_use).
(&mut self)
| 34 | |
| 35 | /// Take the next cache slot, returning (index, is_first_use). |
| 36 | pub fn take_slot(&mut self) -> (usize, bool) { |
| 37 | let idx = self.counter; |
| 38 | self.counter += 1; |
| 39 | if idx >= self.states.len() { |
| 40 | self.states.resize(idx + 1, None); |
| 41 | } |
| 42 | let is_first = self.states[idx].is_none(); |
| 43 | (idx, is_first) |
| 44 | } |
| 45 | |
| 46 | pub fn get(&self, idx: usize) -> Option<&Tensor> { |
| 47 | self.states.get(idx).and_then(|s| s.as_ref()) |
no outgoing calls