StreamSlab
struct StreamSlab[S: SlabEntry & Copyable & Deinitable]Dense small-int stream table parametric over the value type S.
Owns every per-stream S value the HTTP/2 connection has
open. See module docstring for the design rationale.
Implements Copyable, Defaultable, Movable, Sized
- Fields
fast: List[Optional[S]]:FAST_CAPACITYslots indexed by stream ID.Nonefor empty slots,Some(value)for occupied ones. Allocated once at construction; never resized.fast_count: Int: Number of occupied slots in :attr:fast. Maintained on every__setitem__so :meth:__len__is O(1).overflow: Dict[Int, S]: Spillover for stream IDs >=FAST_CAPACITY. Lazily populated; empty on most connections.overflow_count: Int: Count of entries in :attr:overflow. Avoids alen(self.overflow)walk on every__len__call.active: Int: Entries whoseslab_active()holds, kept exact by every write.ready: List[Int]: Ids whoseslab_ready()holds, ascending.
__init__
def __init__(out self) __getitem__
def __getitem__(self, sid: Int) -> ref[self] S Read-only view of the value at sid.
Raises if sid is not present, matching
Dict.__getitem__ semantics so existing call sites
that gate on a prior sid in slab check don't change.
Writes go through __setitem__ / pop so the tracked
count and ready list stay exact.
__setitem__
def __setitem__(mut self, sid: Int, var value: S) __contains__
def __contains__(self, sid: Int) -> Bool pop
def pop(mut self, sid: Int) -> S Remove and return the value at sid.
Raises if absent, matching Dict.pop semantics. The
slot is cleared so a subsequent __setitem__ at the
same sid overwrites without leaking the prior value.
get
def get(self, sid: Int) -> Optional[S] Non-raising read.
Returns None if absent. The caller does its own
copy; we return Optional[Self.S] so the slab keeps
ownership of the slot.
__len__
def __len__(self) -> Int active_count
def active_count(self) -> Int Entries whose slab_active() holds.
ready_ids
def ready_ids(self) -> List[Int] Ids whose slab_ready() holds, ascending.
ids
def ids(self) -> List[Int] Every id present, fast tier ascending, then the overflow tier.
items
def items(self) -> List[Tuple[Int, S]] Eager copy of every (sid, value) pair.
Used by :meth:flare.http2.server.Http2Connection.take_completed_streams
to scan the table for streams whose request is fully
buffered. The call already copies every entry, so the
eager-copy semantics here add no real cost over the prior
Dict iteration. Future bench-gated commit may expand this
to a true iterator if a hot-path use materializes.