commonPrefixLength
CORE · function · Runtime value
Length of the longest common prefix of two strings.
Implemented as a binary search over slice comparisons so long prompts stay on the native string comparison path instead of running a JavaScript character loop.
Import
ts
import { commonPrefixLength } from '@jangts/agent-core/context';js
import { commonPrefixLength } from '@jangts/agent-core/context';Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/context, @jangts/agent-core/support, @jangts/agent-core/support/context.
Definition
Call
ts
commonPrefixLength(left: string, right: string): numberLength of the longest common prefix of two strings.
Implemented as a binary search over slice comparisons so long prompts stay on the native string comparison path instead of running a JavaScript character loop.
| Parameter | Type | Passing | Description |
|---|---|---|---|
left | string | Required | — |
right | string | Required | — |
Returns: number.
Examples
- Structural query keys and text common prefixes: Small pure functions for stable comparison and usage analysis, not an authorization, hashing, or semantic deduplication system.
Compare the stable prefix of two real inputs
Beginner · Node.js
ts
import { commonPrefixLength } from '@jangts/agent-core';
console.log(commonPrefixLength('服务:正常', '服务:繁忙')); // 3js
import { commonPrefixLength } from '@jangts/agent-core';
console.log(commonPrefixLength('服务:正常', '服务:繁忙')); // 3Different object key order keeps the same structure semantics
Configuration · Node.js
ts
import { retrievalQueryKey } from '@jangts/agent-core';
const first = retrievalQueryKey({ query: '服务状态', filters: { region: 'cn', active: true } });
const second = retrievalQueryKey({ filters: { active: true, region: 'cn' }, query: '服务状态' });
console.log(first === second); // true
console.log(retrievalQueryKey({ ids: ['a', 'b'] }) === retrievalQueryKey({ ids: ['b', 'a'] })); // falsejs
import { retrievalQueryKey } from '@jangts/agent-core';
const first = retrievalQueryKey({ query: '服务状态', filters: { region: 'cn', active: true } });
const second = retrievalQueryKey({ filters: { active: true, region: 'cn' }, query: '服务状态' });
console.log(first === second); // true
console.log(retrievalQueryKey({ ids: ['a', 'b'] }) === retrievalQueryKey({ ids: ['b', 'a'] })); // false