Skip to content

Commit 833f6c0

Browse files
committed
Rewording Huffman coding
1 parent 922d481 commit 833f6c0

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

format.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ ProbabilityTable ::= ProbabilityTableUnreachable # Compression artifact. A t
6262
```
6363

6464
The probability tables are written down in an order extracted from the grammar and define a model
65-
`table: (parent type, my type) -> [(value, probabilities)]`.
65+
`huffman_at: (parent type, my type) -> HuffmanTable`.
6666

6767
FIXME: Specify how the order is extracted from the grammar.
6868

@@ -113,21 +113,28 @@ LazyAST ::= Node
113113
In the definition of `AST`, for each `i`, `LazyPartByteLen[i]` represents the number
114114
of bytes used to store the item of the sub-ast `LazyAST[i]`.
115115

116-
# Nodes and probabilities
116+
# Nodes
117117

118-
To decode a node, we need to know the type of its parent.
118+
Nodes are stored as sequences of Huffman-encoded values. Note that the encoding uses
119+
numerous distinct Huffman tables. Each `(parent tag, value type)` pair determines the
120+
Huffman table to be used to decode the next few bits in the sequence.
119121

120122
```
121123
RootNode ::= Value(ε)*
122124
Node(parent) ::= t=Tag(parent) Field(t)*
123-
Tag(parent) ::= Primitive(parent)
124-
Value(parent) ::= "" # If field is lazy
125-
| Node(parent) # If field is an interface or sum of interfaces
126-
| Primitive(parent) # If field is a primitive value
127-
| List(parent) # If field is a list
125+
Tag(parent) ::= Primitive(parent, TAG)
126+
Value(parent) ::= "" # If field is lazy
127+
| Node(parent) # If field is an interface or sum of interfaces
128+
| List(parent) # If field is a list
129+
| Primitive(parent, U32) # If field is a u32
130+
| Primitive(parent, I32) # If field is a i32
131+
| Primitive(parent, F64) # ...
132+
| Primitive(parent, StringIndex)
133+
| Primitive(parent, OptionalStringIndex)
128134
List(parent) ::= ListLength(parent) Value(parent)*
129-
ListPength(parent) ::= Value((parent, 'list-length')) # List lengths are u32 values with a special parent
130-
Primitive(parent) ::= bit*
135+
ListLength(parent) ::= Primitive(ListLength<parent>, U32) # List lengths are u32 values with a special parent
136+
Primitive(parent, type) ::= bit*
131137
```
132138

133-
To determine how many bits need to be read to decode a `Primitive(parent)`, it is sufficient for a decoder to know the distribution of probabilities for `(parent, expected type)`, as stored in the `ProbabilityPrelude`.
139+
In every instance of `Primitive(parent, type)`, we use the Huffman table defined as `huffman_at` (see above)
140+
to both determine the number of bits to read and interpret these bits as a value of the corresponding `type`.

0 commit comments

Comments
 (0)