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

Function lookup_drafts

engine/src/split/src/session.cpp:379–396  ·  view source on GitHub ↗

A window's cost grows with its rows (Q4: 8 rows ~20 ms, 16 ~34): in a run being copied (a code edit) the match is long and the drafts are kept, a short match (new code) is mostly a coincidence

Source from the content-addressed store, hash-verified

377// A window's cost grows with its rows (Q4: 8 rows ~20 ms, 16 ~34): in a run being copied (a code edit) the match is long
378// and the drafts are kept, a short match (new code) is mostly a coincidence
379std::vector<int> lookup_drafts(const std::vector<int>& ctx, int lk, int d1) {
380 std::vector<int> r;
381 if (lk == 0 || (int) ctx.size() <= LOOKUP_N) return r;
382 const size_t n0 = ctx.size() - LOOKUP_N;
383 for (size_t s = n0; s-- > 0;)
384 if (std::equal(ctx.begin() + s, ctx.begin() + s + LOOKUP_N, ctx.begin() + n0)) {
385 if (s + LOOKUP_N < ctx.size() && (d1 < 0 || ctx[s + LOOKUP_N] == d1)) {
386 int m = LOOKUP_N;
387 while (m < lk && (size_t) (m - LOOKUP_N) < s && ctx[s - 1 - (m - LOOKUP_N)] == ctx[n0 - 1 - (m - LOOKUP_N)]) ++m;
388 const int k = std::min(lk, std::max(LOOKUP_MIN, m));
389 r.assign(ctx.begin() + s + LOOKUP_N, ctx.begin() + std::min(ctx.size(), s + LOOKUP_N + k));
390 }
391 break;
392 }
393 // an image cell is never a draft (nor anything after it)
394 r.erase(std::find_if(r.begin(), r.end(), [](int t) { return t >= Engine::IMAGE_TOK; }), r.end());
395 return r;
396}
397
398Finish Session::generate(int max_new, const Sampling& s, const std::function<void(int)>& emit, const std::atomic<bool>* stop,
399 GenStats& st) {

Callers 2

draft_nextMethod · 0.85
lookupMethod · 0.85

Calls 8

assignMethod · 0.80
eraseMethod · 0.80
equalFunction · 0.50
minFunction · 0.50
maxFunction · 0.50
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected