Field Paths¶
Decodes Huffman-coded field path operations used to address properties inside entity deltas.
See also: Field Paths & Huffman
gem.field_path.read_field_paths(r: BitReader) -> list[FieldPath]
¶
Decode a Huffman-coded sequence of field paths from r.
Uses a flat O(1) decode table to resolve each Huffman op in a single peek + skip rather than a per-bit tree walk. The peek/skip/rem_bits calls are inlined directly against BitReader's private attributes to eliminate ~22M Python function calls per replay.
Falls back to the tree walk for the last few bits when fewer than
_HUFF_TABLE_BITS bits remain in the buffer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
BitReader
|
BitReader positioned at the start of the field path sequence. |
required |
Returns:
| Type | Description |
|---|---|
list[FieldPath]
|
List of FieldPath objects, one per updated field (not including the |
list[FieldPath]
|
finish sentinel). |
Source code in src/gem/field_path.py
gem.field_path.FieldPath
¶
A mutable path of up to 7 integer field indices.
Starts at path = [-1, 0, 0, 0, 0, 0, 0], last = 0.
Operations mutate path and last in place.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
list[int]
|
Seven-element list; active indices are |
last |
int
|
Index of the deepest active level (0-based). |
done |
bool
|
Set to True by |
Source code in src/gem/field_path.py
reset() -> None
¶
pop(n: int) -> None
¶
Pop n levels off the path, zeroing the vacated slots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of levels to remove. |
required |
copy() -> FieldPath
¶
Return an independent copy of this path.
Returns:
| Type | Description |
|---|---|
FieldPath
|
A new FieldPath with identical state. |
to_tuple() -> tuple[int, ...]
¶
Return the active indices as an immutable tuple.
Returns:
| Type | Description |
|---|---|
tuple[int, ...]
|
Tuple of active integer indices, e.g. |
to_str() -> str
¶
Return a slash-separated string of active indices.
Returns:
| Type | Description |
|---|---|
str
|
String like |
gem.field_path.FieldPathOp
dataclass
¶
A single field-path operation with its Huffman weight.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Human-readable operation name. |
weight |
int
|
Huffman frequency weight (higher = shallower in tree). |
fn |
Callable[[BitReader, FieldPath], None]
|
Callable that mutates a FieldPath using bits from a BitReader. |