/* Copyright 2015 Google Inc. All Rights Reserved.
Distributed under MIT license.
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
namespace Org.Brotli.Dec
{
/// Contains a collection of huffman trees with the same alphabet size.
internal sealed class HuffmanTreeGroup
{
/// The maximal alphabet size in this group.
private int alphabetSize;
/// Storage for Huffman lookup tables.
internal int[] codes;
///
/// Offsets of distinct lookup tables in
///
/// storage.
///
internal int[] trees;
/// Initializes the Huffman tree group.
/// POJO to be initialised
/// the maximal alphabet size in this group
/// number of Huffman codes
internal static void Init(Org.Brotli.Dec.HuffmanTreeGroup group, int alphabetSize, int n)
{
group.alphabetSize = alphabetSize;
group.codes = new int[n * Org.Brotli.Dec.Huffman.HuffmanMaxTableSize];
group.trees = new int[n];
}
/// Decodes Huffman trees from input stream and constructs lookup tables.
/// target POJO
/// data source
internal static void Decode(Org.Brotli.Dec.HuffmanTreeGroup group, Org.Brotli.Dec.BitReader br)
{
int next = 0;
int n = group.trees.Length;
for (int i = 0; i < n; i++)
{
group.trees[i] = next;
Org.Brotli.Dec.Decode.ReadHuffmanCode(group.alphabetSize, group.codes, next, br);
next += Org.Brotli.Dec.Huffman.HuffmanMaxTableSize;
}
}
}
}