Expand description
Radix tree implementations for prefix matching and cache-aware routing.
This module provides radix tree data structures that mirror SGLang’s scheduler memory management patterns. Two implementations are available:
StringTree: Character-based tree for HTTP router (text input)TokenTree: Token-based tree for gRPC router (pre-tokenized input)
Both implementations support:
- Multi-tenant prefix tracking with LRU eviction
- Concurrent access via DashMap and RwLock
- Efficient prefix matching with match counts
Modules§
- snapshot
- Compact serializable snapshot of a radix tree.
Structs§
- Content
Hash - Position-independent content hash of tokens within a single block. Computed via XXH3-64 from token IDs. Same tokens always produce the same hash regardless of their position in the sequence.
- Overlap
Scores - Overlap scores: how many consecutive blocks each worker has cached.
- Positional
Indexer - Positional indexer for cache-aware routing.
- Prefix
Match Result - Result of a prefix match operation, including char counts to avoid recomputation.
- Sequence
Hash - Position-aware block hash from backend (sequence hash).
Matches the
block_hashfield in KvBlock proto (i64, bitwise reinterpreted as u64). Different from ContentHash because it encodes the full prefix history. - Stored
Block - A block from a store event, carrying both hash representations.
- String
Match Result - Result of a prefix match operation, including char counts to avoid recomputation.
- String
Tree - Token
Match Result - Result of a prefix match operation with token counts.
- Token
Tree - Token-based radix tree for cache-aware routing.
- Tree
Enums§
- Apply
Error - Error returned by
PositionalIndexer::apply_storedwhen the event cannot be applied.
Constants§
- GLOBAL_
EVICTION_ HASH - Sentinel hash meaning “evict this tenant from ALL nodes” in
the tenant-eviction wire format. Real prefixes never hash to
this value:
hash_node_pathandhash_token_pathremap0to1if Blake3 lands there.
Traits§
- Match
Result - Trait for prefix match results.
- Radix
Tree - Trait for radix tree implementations.
Functions§
- compute_
content_ hash - Compute content hash from token IDs (position-independent). Uses XXH3-64 streaming hasher with standard seed — avoids intermediate allocation.
- compute_
request_ content_ hashes - Chunk request tokens by block size and compute a
ContentHashper full block. - hash_
node_ path - Compute a compact 8-byte hash of a prefix path. Returns a
non-zero hash;
0is reserved forGLOBAL_EVICTION_HASH. - hash_
token_ path - Compute a compact 8-byte hash of a token-id sequence. Returns
a non-zero hash;
0is reserved forGLOBAL_EVICTION_HASH. Streams into the hasher to avoid an intermediateVec<u8>(~128 KB at 32K tokens).
Type Aliases§
- Tenant
Id - Interned tenant identifier for efficient comparison and storage.
- Worker
Block Map - Per-worker reverse lookup: backend_seq_hash → (position, content_hash, prefix_hash).
The
prefix_hashis the router-computed rolling hash used as the SeqEntry key. - Worker
Id - Internal worker identifier used in
OverlapScores.