Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StringLineGroup"/> class.
 /// </summary>
 /// <param name="capacity"></param>
 public StringLineGroup(int capacity)
 {
     if (capacity <= 0)
     {
         ThrowHelper.ArgumentOutOfRangeException(nameof(capacity));
     }
     Lines = _pool.Rent(capacity);
     Count = 0;
 }
Пример #2
0
 internal StringLineGroup(int capacity, bool willRelease)
 {
     if (capacity <= 0)
     {
         ThrowHelper.ArgumentOutOfRangeException(nameof(capacity));
     }
     Lines = _pool.Rent(willRelease ? Math.Max(8, capacity) : capacity);
     Count = 0;
 }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CharacterMap{T}"/> class.
        /// </summary>
        /// <param name="maps">The states.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public CharacterMap(IEnumerable <KeyValuePair <char, T> > maps)
        {
            if (maps is null)
            {
                ThrowHelper.ArgumentNullException(nameof(maps));
            }
            var charSet = new HashSet <char>();
            int maxChar = 0;

            foreach (var map in maps)
            {
                var openingChar = map.Key;
                charSet.Add(openingChar);

                if (openingChar < 128)
                {
                    maxChar = Math.Max(maxChar, openingChar);

                    if (openingChar == 0)
                    {
                        ThrowHelper.ArgumentOutOfRangeException("Null is not a valid opening character.", nameof(maps));
                    }
                }
                else
                {
                    nonAsciiMap ??= new Dictionary <uint, T>();
                }
            }

            OpeningCharacters = charSet.ToArray();
            Array.Sort(OpeningCharacters);

            asciiMap = new T[maxChar + 1];

            foreach (var state in maps)
            {
                char openingChar = state.Key;
                if (openingChar < 128)
                {
                    asciiMap[openingChar] ??= state.Value;
                    isOpeningCharacter.Set(openingChar);
                }
                else if (!nonAsciiMap !.ContainsKey(openingChar))
                {
                    nonAsciiMap[openingChar] = state.Value;
                }
            }

#if NETCOREAPP3_1_OR_GREATER
            if (nonAsciiMap is null)
            {
                long bitmap_0_3 = 0;
                long bitmap_4_7 = 0;

                foreach (char openingChar in OpeningCharacters)
                {
                    int position = (openingChar >> 4) | ((openingChar & 0x0F) << 3);
                    if (position < 64)
                    {
                        bitmap_0_3 |= 1L << position;
                    }
                    else
                    {
                        bitmap_4_7 |= 1L << (position - 64);
                    }
                }

                _asciiBitmap = Vector128.Create(bitmap_0_3, bitmap_4_7).AsByte();
            }
#endif
        }