/// <summary> /// Returns lengths of paths that are needed to encode exactly <paramref name="symbolCount"/> symbols. /// If <paramref name="symbolCount"/> equals 4, another bit is consumed from the <paramref name="reader"/> to determine the correct lengths. /// </summary> private static byte[] DetermineSimpleCodeLengths(IMarkedBitReader reader, int symbolCount) { return(symbolCount switch { 1 => new byte[] { 0 }, 2 => new byte[] { 1, 1 }, 3 => new byte[] { 1, 2, 2 }, 4 => reader.NextBit("tree-select") ? new byte[] { 1, 2, 3, 3 } : new byte[] { 2, 2, 2, 2 }, _ => throw new ArgumentOutOfRangeException(nameof(symbolCount), "The amount of symbols in a simple code must be in the range [1; 4]."), });
// Marking overloads public static bool NextBit(this IMarkedBitReader reader, string name) { reader.MarkStart(); bool result = reader.NextBit(); reader.MarkEndValue(name, result); return(result); }