Delete a cache entry and clean up empty trie nodes.
(self, model, tokens: Tuple[int, ...])
| 134 | return current["cache"] |
| 135 | |
| 136 | def _delete(self, model, tokens: Tuple[int, ...]) -> None: |
| 137 | """Delete a cache entry and clean up empty trie nodes.""" |
| 138 | path = [self._cache[model]] |
| 139 | for tok in tokens: |
| 140 | path.append(path[-1][tok]) |
| 141 | del path[-1]["cache"] |
| 142 | |
| 143 | # Clean up empty nodes bottom-up |
| 144 | for i in reversed(range(len(tokens))): |
| 145 | d_prev, d, t = path[i], path[i + 1], tokens[i] |
| 146 | if len(d) > 0: |
| 147 | break |
| 148 | del d_prev[t] |
| 149 | |
| 150 | def _extract(self, model, tokens: Tuple[int, ...]) -> CacheEntry: |
| 151 | """ |
no test coverage detected