MCPcopy Create free account
hub / github.com/Niko1221/Strata / reuse_after_edit

Function reuse_after_edit

engine/src/program/conv_cache_test.cpp:37–55  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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
37int64_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
57int main() {
58 std::printf("conv_cache_test\n");

Callers 1

mainFunction · 0.85

Calls 8

spread_victimFunction · 0.85
eviction_victimFunction · 0.85
push_backMethod · 0.80
eraseMethod · 0.80
sizeMethod · 0.45
dataMethod · 0.45
beginMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected