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 { // mark the entry as unused Lengths[i] = -1; } } } // figure out the maximum bit size; if all are unused, don't do anything else if ((MaxBits = Lengths.Max()) > -1) { 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(); } PrefixList = Huffman.BuildPrefixedLinkedList(values ?? Enumerable.Range(0, codewords.Length).ToArray(), codewordLengths ?? Lengths, codewords, out PrefixBitLength, out PrefixOverflowTree); } }
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; } } } int max = ((Lengths.Length > 0) ? Lengths[0] : 0); foreach (int n in Lengths) { if (n > max) { max = n; } } //MaxBits = Lengths.Max(); MaxBits = 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(); } { List <int> ranges = new List <int>(); for (int i = 0; i < codewords.Length; i++) { ranges.Add(i); } PrefixList = Huffman.BuildPrefixedLinkedList(values ?? ranges.ToArray(), codewordLengths ?? Lengths, codewords, out PrefixBitLength, out PrefixOverflowTree); } }
public void InitTree(DataPacket packet) { int num = 0; bool flag; if (packet.ReadBit()) { int num2 = (int)packet.ReadBits(5) + 1; int num3 = 0; while (num3 < Entries) { int num4 = (int)packet.ReadBits(Utils.ilog(Entries - num3)); while (--num4 >= 0) { Lengths[num3++] = num2; } num2++; } num = 0; flag = false; } else { flag = packet.ReadBit(); for (int i = 0; i < Entries; i++) { if (!flag || packet.ReadBit()) { Lengths[i] = (int)packet.ReadBits(5) + 1; num++; } else { Lengths[i] = -1; } } } MaxBits = Lengths.Max(); int num5 = 0; int[] array = null; if (flag && num >= Entries >> 2) { array = new int[Entries]; Array.Copy(Lengths, array, Entries); flag = false; } num5 = (flag ? num : 0); int num6 = num5; int[] array2 = null; int[] array3 = null; if (!flag) { array3 = new int[Entries]; } else if (num6 != 0) { array = new int[num6]; array3 = new int[num6]; array2 = new int[num6]; } if (!ComputeCodewords(flag, num6, array3, array, Lengths, Entries, array2)) { throw new InvalidDataException(); } PrefixList = Huffman.BuildPrefixedLinkedList(array2 ?? Enumerable.Range(0, array3.Length).ToArray(), array ?? Lengths, array3, out PrefixBitLength, out PrefixOverflowTree); }
void InitTree(DataPacket packet) { bool sparse; int total = 0; if (packet.ReadBit()) { // ordered var len = (int)packet.ReadUBits(5) + 1; for (var i = 0; i < Entries;) { int cnt = (int)packet.ReadUBits(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.ReadUBits(5) + 1; total++; } else { // mark the entry as unused Lengths[i] = -1; } } } // figure out the maximum bit size; if all are unused, don't do anything else if ((MaxBits = Lengths.Max()) > -1) { Span <int> codewordLengths = stackalloc int[0]; if (sparse && total >= Entries >> 2) { codewordLengths = stackalloc int[Entries]; for (int i = 0; i < Entries; i++) { codewordLengths[i] = Lengths[i]; } sparse = false; } // compute size of sorted tables int sortedEntries = sparse ? total : 0; Span <int> values = stackalloc int[0]; Span <int> codewords = stackalloc int[0]; if (!sparse) { codewords = stackalloc int[Entries]; } else if (sortedEntries != 0) { codewordLengths = stackalloc int[sortedEntries]; codewords = stackalloc int[sortedEntries]; values = stackalloc int[sortedEntries]; } if (!ComputeCodewords(sparse, sortedEntries, codewords, codewordLengths, Lengths, Entries, values)) { throw new InvalidDataException(); } Span <int> valueList = stackalloc int[codewords.Length]; if (values.Length != 0) { valueList = values; } else { for (int i = 0; i < codewords.Length; i++) { valueList[i] = i; } } Span <int> lengthList = codewordLengths.Length > 0 ? codewordLengths : Lengths.AsSpan(); PrefixList = Huffman.BuildPrefixedLinkedList( valueList, lengthList, codewords, out PrefixBitLength, out PrefixOverflowTree); } }