• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2015 Google Inc. All Rights Reserved.
2 
3 Distributed under MIT license.
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 */
6 namespace Org.Brotli.Dec
7 {
8 	/// <summary>Contains a collection of huffman trees with the same alphabet size.</summary>
9 	internal sealed class HuffmanTreeGroup
10 	{
11 		/// <summary>The maximal alphabet size in this group.</summary>
12 		private int alphabetSize;
13 
14 		/// <summary>Storage for Huffman lookup tables.</summary>
15 		internal int[] codes;
16 
17 		/// <summary>
18 		/// Offsets of distinct lookup tables in
19 		/// <see cref="codes"/>
20 		/// storage.
21 		/// </summary>
22 		internal int[] trees;
23 
24 		/// <summary>Initializes the Huffman tree group.</summary>
25 		/// <param name="group">POJO to be initialised</param>
26 		/// <param name="alphabetSize">the maximal alphabet size in this group</param>
27 		/// <param name="n">number of Huffman codes</param>
Init(Org.Brotli.Dec.HuffmanTreeGroup group, int alphabetSize, int n)28 		internal static void Init(Org.Brotli.Dec.HuffmanTreeGroup group, int alphabetSize, int n)
29 		{
30 			group.alphabetSize = alphabetSize;
31 			group.codes = new int[n * Org.Brotli.Dec.Huffman.HuffmanMaxTableSize];
32 			group.trees = new int[n];
33 		}
34 
35 		/// <summary>Decodes Huffman trees from input stream and constructs lookup tables.</summary>
36 		/// <param name="group">target POJO</param>
37 		/// <param name="br">data source</param>
Decode(Org.Brotli.Dec.HuffmanTreeGroup group, Org.Brotli.Dec.BitReader br)38 		internal static void Decode(Org.Brotli.Dec.HuffmanTreeGroup group, Org.Brotli.Dec.BitReader br)
39 		{
40 			int next = 0;
41 			int n = group.trees.Length;
42 			for (int i = 0; i < n; i++)
43 			{
44 				group.trees[i] = next;
45 				Org.Brotli.Dec.Decode.ReadHuffmanCode(group.alphabetSize, group.codes, next, br);
46 				next += Org.Brotli.Dec.Huffman.HuffmanMaxTableSize;
47 			}
48 		}
49 	}
50 }
51