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

Function is_token_subsequence

atomic-core/src/merge/engine.rs:417–434  ·  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

415/// are a subsequence of side B's, then B is a superset that contains
416/// everything A has plus more — B subsumes A.
417fn is_token_subsequence(sub: &[MergeToken], sup: &[MergeToken]) -> bool {
418 if sub.is_empty() {
419 return true;
420 }
421 if sub.len() > sup.len() {
422 return false;
423 }
424 let mut si = 0; // index into sub
425 for token in sup {
426 if token == &sub[si] {
427 si += 1;
428 if si == sub.len() {
429 return true;
430 }
431 }
432 }
433 false
434}
435
436// ===========================================================================
437// 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