a conversation of `turns` turns of `turn` tokens each after a `root`-token system prompt, a checkpoint at every turn's end and at most `cap` kept; returns how many tokens a request whose prompt differs `back` tokens before the end reuses
| 35 | // a conversation of `turns` turns of `turn` tokens each after a `root`-token system prompt, a checkpoint at every turn's |
| 36 | // end and at most `cap` kept; returns how many tokens a request whose prompt differs `back` tokens before the end reuses |
| 37 | int64_t reuse_after_edit(bool spread, int64_t root, int64_t turn, int turns, int64_t cap, int64_t back) { |
| 38 | std::vector<int64_t> lens = {root}; |
| 39 | std::vector<uint64_t> stamps = {1}; |
| 40 | for (int t = 1; t <= turns; ++t) { |
| 41 | lens.push_back(root + t * turn); |
| 42 | stamps.push_back(uint64_t(t + 1)); |
| 43 | while ((int64_t) lens.size() > cap) { |
| 44 | const size_t v = spread ? spread_victim(lens.data(), stamps.data(), lens.size(), cap, nullptr, nullptr) |
| 45 | : eviction_victim(stamps.data(), stamps.size(), cap); |
| 46 | lens.erase(lens.begin() + (std::ptrdiff_t) v); |
| 47 | stamps.erase(stamps.begin() + (std::ptrdiff_t) v); |
| 48 | } |
| 49 | } |
| 50 | const int64_t edit = lens.back() - back; |
| 51 | int64_t reuse = 0; |
| 52 | for (int64_t l : lens) |
| 53 | if (l <= edit) reuse = l; |
| 54 | return reuse; |
| 55 | } |
| 56 | |
| 57 | int main() { |
| 58 | std::printf("conv_cache_test\n"); |
no test coverage detected