Sparse Index¶
In-memory sorted mapping from block first-keys to byte offsets.
SparseIndex()
¶
Bases: Serializable
In-memory sparse index mapping block first-keys to offsets.
Initialize an empty sparse index with no entries.
Source code in app/index/sparse.py
add(first_key, block_offset)
¶
Append a new index entry. Keys must be in ascending order.
Source code in app/index/sparse.py
floor_offset(key)
¶
Return the offset of the block whose first_key <= key.
Uses bisect_right: finds rightmost entry with first_key <= key.
Source code in app/index/sparse.py
ceil_offset(key)
¶
Return the offset of the block whose first_key >= key.
Uses bisect_left: finds leftmost entry with first_key >= key.
Source code in app/index/sparse.py
to_bytes()
¶
Serialize all index entries to bytes with CRC footer.
Source code in app/index/sparse.py
from_bytes(data)
classmethod
¶
Deserialize from data. Verifies CRC integrity.
Source code in app/index/sparse.py
next_offset_after(offset)
¶
Return the first offset strictly greater than offset, or None.
Source code in app/index/sparse.py
__len__()
¶
Return the number of index entries.
Returns:
| Type | Description |
|---|---|
int
|
The count of |
int
|
this index. |