Version: Unity 6.7 Beta (6000.7)
LanguageEnglish
  • C#

StreamCompressionModel

struct in Unity.Collections

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

A type that uses Huffman encoding to encode values in a lossless manner.

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.

Static Properties

Property Description
Default A shared singleton instance of StreamCompressionModel, this instance is initialized using hardcoded bucket parameters and model.

Public Methods

Method Description
CalculateBucket Calculates the bucket index into the Unity.Collections.StreamCompressionModel._encodeTable where the specified value should be written.
GetCompressedSizeInBits The compressed size in bits of the given unsigned integer value