Esempio n. 1
0
        public BitDecoder(char[] alphabet)
        {
            var valid = EncodedString.TestValidAlphabet(alphabet);

            if (AlphabetValidity.Valid != valid)
            {
                throw new ArgumentException(paramName: nameof(alphabet), message: valid.ToString());
            }
            CharacterBitWidth = (byte)Math.Log(alphabet.Length, 2);
            Alphabet          = new Dictionary <char, ulong>();
            for (var i = 0L; i < alphabet.LongLength; i += 1)
            {
                Alphabet[alphabet[i]] = (ulong)i;
            }
            HasPadding       = false;
            PaddingCharacter = '\0';
        }
Esempio n. 2
0
        public BitEncoder(char[] alphabet)
        {
            var valid = EncodedString.TestValidAlphabet(alphabet);

            if (AlphabetValidity.Valid != valid)
            {
                throw new ArgumentException(paramName: nameof(alphabet), message: valid.ToString());
            }
            Alphabet          = alphabet;
            CharacterBitWidth = (byte)Math.Log(alphabet.Length, 2);
            Mask = unchecked ((1ul << CharacterBitWidth) - 1);

            int a = 0;

            CharactersToMatchByteLength = 0;
            do
            {
                a += CharacterBitWidth;
                CharactersToMatchByteLength += 1;
            } while(a % 8 != 0);

            HasPadding       = false;
            PaddingCharacter = '\0';
        }