MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / is_token_subsequence

Function is_token_subsequence

atomic-core/src/merge/engine.rs:388–405  ·  view source on GitHub ↗

Check whether `sub`'s tokens are a subsequence of `sup`'s tokens. A subsequence means every token in `sub` appears in `sup` in the same order, possibly with extra tokens interspersed in `sup`. This is used for concurrent insertion resolution: if side A's tokens are a subsequence of side B's, then B is a superset that contains everything A has plus more — B subsumes A.

(sub: &[MergeToken], sup: &[MergeToken])

Source from the content-addressed store, hash-verified

386/// are a subsequence of side B's, then B is a superset that contains
387/// everything A has plus more — B subsumes A.
388fn is_token_subsequence(sub: &[MergeToken], sup: &[MergeToken]) -> bool {
389 if sub.is_empty() {
390 return true;
391 }
392 if sub.len() > sup.len() {
393 return false;
394 }
395 let mut si = 0; // index into sub
396 for token in sup {
397 if token == &sub[si] {
398 si += 1;
399 if si == sub.len() {
400 return true;
401 }
402 }
403 }
404 false
405}
406
407// ===========================================================================
408// Backward-compatible single-type-parameter wrapper

Callers 1

try_mergeMethod · 0.85

Calls 2

is_emptyMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected