pub struct RadixCache {
pub page_pool: PagePool,
pub evictable_leaves: FxHashSet<NodeId>,
pub evictable_size: usize,
pub protected_size: usize,
/* private fields */
}Expand description
Radix tree for SGLang KV cache simulation.
Fields§
§page_pool: PagePool§evictable_leaves: FxHashSet<NodeId>Total token count in evictable nodes.
evictable_size: usize§protected_size: usizeTotal token count in protected (locked) nodes.
Implementations§
Source§impl RadixCache
impl RadixCache
pub fn new(total_tokens: usize, page_size: usize) -> Self
pub fn root(&self) -> NodeId
pub fn node(&self, id: NodeId) -> &TreeNode
pub fn page_size(&self) -> usize
pub fn num_nodes(&self) -> usize
pub fn match_prefix(&mut self, key: &[u32]) -> (usize, NodeId)
Sourcepub fn prefix_match_len(&self, key: &[u32]) -> usize
pub fn prefix_match_len(&self, key: &[u32]) -> usize
Read-only prefix match length (does not mutate timestamps or split nodes). Used for LPM scheduling scoring.
Sourcepub fn insert(&mut self, key: &[u32], value: &[usize]) -> NodeId
pub fn insert(&mut self, key: &[u32], value: &[usize]) -> NodeId
Insert a token sequence into the tree. Key is page-aligned before insertion.
Sourcepub fn insert_from_node(
&mut self,
prefix_node: NodeId,
prefix_len: usize,
key: &[u32],
value: &[usize],
) -> NodeId
pub fn insert_from_node( &mut self, prefix_node: NodeId, prefix_len: usize, key: &[u32], value: &[usize], ) -> NodeId
Insert only the suffix after a retained, page-aligned prefix.
prefix_node must be the locked terminal node for prefix_len. Keeping
that handle lets decode growth avoid walking the full sequence from the
root on every completed page.
pub fn is_leaf(&self, id: NodeId) -> bool
pub fn inc_lock_ref(&mut self, node_id: NodeId)
pub fn dec_lock_ref(&mut self, node_id: NodeId)
Sourcepub fn evict(&mut self, num_tokens: usize) -> (usize, Vec<KvPageId>)
pub fn evict(&mut self, num_tokens: usize) -> (usize, Vec<KvPageId>)
Evict tokens from the cache by LRU order, rounding partial leaves to full pages.
Returns (num_tokens_evicted, evicted_page_ids).
pub fn available_tokens(&self) -> usize
pub fn total_tokens(&self) -> usize
Auto Trait Implementations§
impl Freeze for RadixCache
impl RefUnwindSafe for RadixCache
impl Send for RadixCache
impl Sync for RadixCache
impl Unpin for RadixCache
impl UnsafeUnpin for RadixCache
impl UnwindSafe for RadixCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more