Ejemplo n.º 1
0
        private static short[] checkValues(short[] values, short[] lengths)
        {
            if (values == null || values.Length > 256)
            {
                throw new ArgumentException("Values array is null or too long.");
            }

            //if (values.Any(x => x < 0))
            if (IEnum.Any(values, x => x < 0))
            {
                throw new ArgumentException("Negative values cannot appear in the values array.");
            }

            //if (values.Length != lengths.Sum(x => (int)x))
            if (IEnum.Sum(lengths) != values.Length)
            {
                throw new ArgumentException("Number of values does not match code length sum.");
            }

            return(values);
        }
Ejemplo n.º 2
0
        private static short[] checkLengths(short[] lengths)
        {
            if (lengths == null || lengths.Length > 16)
            {
                throw new ArgumentException("Length array is null or too long.");
            }

            //if (lengths.Any(x => x < 0))
            if (IEnum.Any(lengths, x => x < 0))
            {
                throw new ArgumentException("Negative values cannot appear in the length array.");
            }

            for (int i = 0; i < lengths.Length; i++)
            {
                if (lengths[i] > ((1 << (i + 1)) - 1))
                {
                    throw new ArgumentException(
                              string.Format("Invalid number of codes for code length {0}", (i + 1).ToString()));
                }
            }

            return(lengths);
        }