Struct StreamCompressionModel
A type that uses Huffman encoding to encode values in a lossless manner.
Namespace: Unity.Collections
Assembly: Unity.Collections.dll
Syntax
public struct StreamCompressionModel
Remarks
This type puts values into a manageable number of power-of-two-sized buckets. It codes the bucket index with Huffman, and uses several raw bits that correspond to the size of the bucket to code the position in the bucket.
For example, if you want to send a 32-bit integer over the network, it's impractical to create a Huffman tree that encompasses every value the integer can take because it requires a tree with 2^32 leaves. This type manages that situation.
The buckets are small, around 0, and become progressively larger as the data moves away from zero. Because most data is deltas against predictions, most values are small and most of the redundancy is in the error's size and not in the values of that size we end up hitting.
The context is as a sub-model that has its own statistics and uses its own Huffman tree. When using the context to read and write a specific value, the context must always be the same. The benefit of using multiple contexts is that it allows you to separate the statistics of things that have different expected distributions, which leads to more precise statistics, which again yields better compression. More contexts does, however, result in a marginal cost of a slightly larger model.
Properties
Default
A shared singleton instance of StreamCompressionModel, this instance is initialized using hardcoded bucket parameters and model.
Declaration
public static StreamCompressionModel Default { get; }
Property Value
Type | Description |
---|---|
StreamCompressionModel |
Methods
CalculateBucket(uint)
Calculates the bucket index into the encodeTable where the specified value should be written.
Declaration
public readonly int CalculateBucket(uint value)
Parameters
Type | Name | Description |
---|---|---|
uint | value | A 4-byte unsigned integer value to find a bucket for. |
Returns
Type | Description |
---|---|
int | The bucket index where to put the value. |
GetCompressedSizeInBits(uint)
The compressed size in bits of the given unsigned integer value
Declaration
public readonly int GetCompressedSizeInBits(uint value)
Parameters
Type | Name | Description |
---|---|---|
uint | value | the unsigned int value you want to compress |
Returns
Type | Description |
---|---|
int |