private void InitTree(DataPacket packet) { int num1 = 0; bool flag; if (packet.ReadBit()) { int num2 = (int)packet.ReadBits(5) + 1; int num3 = 0; while (num3 < this.Entries) { int num4 = (int)packet.ReadBits(Utils.ilog(this.Entries - num3)); while (--num4 >= 0) { this.Lengths[num3++] = num2; } ++num2; } num1 = 0; flag = false; } else { flag = packet.ReadBit(); for (int index = 0; index < this.Entries; ++index) { if (!flag || packet.ReadBit()) { this.Lengths[index] = (int)packet.ReadBits(5) + 1; ++num1; } else { this.Lengths[index] = -1; } } } this.MaxBits = Enumerable.Max((IEnumerable <int>) this.Lengths); int[] numArray1 = (int[])null; if (flag && num1 >= this.Entries >> 2) { numArray1 = new int[this.Entries]; Array.Copy((Array)this.Lengths, (Array)numArray1, this.Entries); flag = false; } int length = !flag ? 0 : num1; int[] numArray2 = (int[])null; int[] codeList = (int[])null; if (!flag) { codeList = new int[this.Entries]; } else if (length != 0) { numArray1 = new int[length]; codeList = new int[length]; numArray2 = new int[length]; } VorbisCodebook vorbisCodebook = this; int[] numArray3 = this.Lengths; int num5 = this.Entries; int[] numArray4 = numArray2; int num6 = flag ? 1 : 0; int sortedEntries = length; int[] codewords = codeList; int[] codewordLengths = numArray1; int[] len = numArray3; int n = num5; int[] values = numArray4; if (!vorbisCodebook.ComputeCodewords(num6 != 0, sortedEntries, codewords, codewordLengths, len, n, values)) { throw new InvalidDataException(); } this.LTree = Huffman.BuildLinkedList <int>(numArray2 ?? Enumerable.ToArray <int>(Enumerable.Range(0, codeList.Length)), numArray1 ?? this.Lengths, codeList); }
void InitTree(DataPacket packet) { bool sparse; int total = 0; if (packet.ReadBit()) { // ordered var len = (int)packet.ReadBits(5) + 1; for (var i = 0; i < Entries;) { var cnt = (int)packet.ReadBits(Utils.ilog(Entries - i)); while (--cnt >= 0) { Lengths[i++] = len; } ++len; } total = 0; sparse = false; } else { // unordered sparse = packet.ReadBit(); for (var i = 0; i < Entries; i++) { if (!sparse || packet.ReadBit()) { Lengths[i] = (int)packet.ReadBits(5) + 1; ++total; } else { Lengths[i] = -1; } } } MaxBits = Lengths.Max(); int sortedCount = 0; int[] codewordLengths = null; if (sparse && total >= Entries >> 2) { codewordLengths = new int[Entries]; Array.Copy(Lengths, codewordLengths, Entries); sparse = false; } // compute size of sorted tables if (sparse) { sortedCount = total; } else { sortedCount = 0; } int sortedEntries = sortedCount; int[] values = null; int[] codewords = null; if (!sparse) { codewords = new int[Entries]; } else if (sortedEntries != 0) { codewordLengths = new int[sortedEntries]; codewords = new int[sortedEntries]; values = new int[sortedEntries]; } if (!ComputeCodewords(sparse, sortedEntries, codewords, codewordLengths, len: Lengths, n: Entries, values: values)) { throw new InvalidDataException(); } LTree = Huffman.BuildLinkedList(values ?? Enumerable.Range(0, codewords.Length).ToArray(), codewordLengths ?? Lengths, codewords); }