MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / tree_token_shape_units

Function tree_token_shape_units

src/mcp/compact_out.c:476–508  ·  view source on GitHub ↗

A dependency-free lower-resolution proxy for modern tokenizer pre-splits. * It deliberately undercounts words (camelCase and Unicode stay whole), while * counting punctuation, whitespace runs, and the common <=3-digit chunks. * Comparing complete renders catches byte wins such as `establishment.` -> * `@0+` that increase real cl100k/o200k tokens despite shorter text. */

Source from the content-addressed store, hash-verified

474 * Comparing complete renders catches byte wins such as `establishment.` ->
475 * `@0+` that increase real cl100k/o200k tokens despite shorter text. */
476static size_t tree_token_shape_units(const char *text) {
477 const unsigned char *p = (const unsigned char *)text;
478 size_t units = 0;
479 while (p && *p) {
480 if (isdigit(*p)) {
481 size_t digits = 0;
482 while (isdigit(*p)) {
483 digits++;
484 p++;
485 }
486 units += (digits + 2U) / 3U;
487 continue;
488 }
489 if (isalpha(*p) || *p >= 0x80U) {
490 do {
491 p++;
492 } while (*p && (isalpha(*p) || *p >= 0x80U));
493 units++;
494 continue;
495 }
496 if (isspace(*p)) {
497 do {
498 p++;
499 } while (*p && isspace(*p));
500 units++;
501 continue;
502 }
503
504 p++;
505 units++;
506 }
507 return units;
508}
509
510static bool tree_column_is_string(const bool *string_cols, int col) {
511 return !string_cols || string_cols[col];

Callers 1

tree_table_rows_implFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected