Component-Weighted Centroid Search for Exact Incremental BPE
Exact incremental tokenizers keep the tokenization of a growing text up to date, so a long prompt or agent trace is not retokenized each time it grows. Jiang and Gong's algorithm does this for byte-pair encoding (BPE) in $O(\log^2 t)$ worst-case time per byte, where $t$ is the length of the longest token. Its search passes through $O(\log t)$ nested subproblems and runs a binary search over the possible branches at each one. We weight each branch by the size of the subproblem it leads to. Each step then costs about one probe for every halving of the remaining candidates, and a whole update costs $O(\log t)$, as much as one binary search over all candidates. Output and asymptotic memory are unchanged. We also construct valid BPE vocabularies on which the original search provably needs $Θ(\log^2 t)$ probes and ours $Θ(\log t)$, and a Rust implementation reproduces both counts exactly. On six real vocabularies the two searches run at about the same speed on ordinary text, while on long runs of spaces or hyphens the weighted search is up to 2.5$\times$ faster.