Exemplo n.º 1
0
        public void CopyTo(TKey [] array, int index)
        {
            if (array == null)
            {
                CheckParam.ThrowArgumentNull(nameof(array));
            }
            if (index < 0)
            {
                CheckParam.ThrowOutOfRange(nameof(index));
            }
            // we want no exception for index==array.Length && dictionary.Count == 0
            if (index > array.Length)
            {
                CheckParam.ThrowBadArgument("index larger than largest valid index of array");
            }
            if (array.Length - index < dictionary.Count)
            {
                CheckParam.ThrowBadArgument("Destination array cannot hold the requested elements!");
            }

            foreach (TKey k in this)
            {
                array [index++] = k;
            }
        }
Exemplo n.º 2
0
 /// <inheritdoc cref="Log2Floor(int)"/>
 public static int Log2Floor(long x)
 {
     if (x < 0)
     {
         CheckParam.ThrowOutOfRange(nameof(x), "Log2Floor({0}) called", x);
     }
     return(Log2Floor((ulong)x));
 }
Exemplo n.º 3
0
 public Num this[int index]
 {
     get {
         if ((uint)index >= (uint)_count)
         {
             CheckParam.ThrowOutOfRange("index", index, 0, _count - 1);
         }
         return(M.Add(_lo, M.From(index)));
     }
 }
Exemplo n.º 4
0
 public int this[int index]
 {
     get {
         if ((uint)index >= (uint)_count)
         {
             CheckParam.ThrowOutOfRange("index", index, 0, _count - 1);
         }
         return(_start + index);
     }
 }
Exemplo n.º 5
0
 private void Check(ref KeyWalker kw, string operation)
 {
     if ((kw.Offset | kw.Left) < 0)
     {
         CheckParam.ThrowOutOfRange(kw.Offset < 0 ? "offset" : "length", "{0}: offset or length are negative", operation);
     }
     if (kw.Offset + kw.Left > kw.Buffer.Length)
     {
         throw new ArgumentException("{0}: offset+length exceeds buffer length".Localized(operation));
     }
 }
Exemplo n.º 6
0
 public T this[int index]
 {
     get {
         bool fail;
         T    value = TryGet(index, out fail);
         if (fail)
         {
             CheckParam.ThrowOutOfRange("index", index, 0, _count - 1);
         }
         return(value);
     }
 }
Exemplo n.º 7
0
        public int IndexOf(T item, int startIndex)
        {
            EqualityComparer <T> comparer = EqualityComparer <T> .Default;
            int size1            = FirstHalfSize;
            int stop             = _start + size1;
            int stop2            = _count - size1;
            int returnAdjustment = -_start;
            int i;

            if ((uint)startIndex < (uint)size1)
            {
                i = _start + startIndex;
            }
            else
            {
                // start in the second half
                stop             = stop2;
                returnAdjustment = size1;
                i = startIndex - size1;
                if (startIndex < 0)
                {
                    CheckParam.ThrowOutOfRange("startIndex");
                }
            }

            for (;;)
            {
                for (; i < stop; i++)
                {
                    if (comparer.Equals(item, _array[i]))
                    {
                        return(i + returnAdjustment);
                    }
                }
                if (stop == stop2)
                {
                    return(-1);
                }
                stop             = stop2;
                returnAdjustment = size1;
                i = 0;
            }
        }
Exemplo n.º 8
0
        private static void Copy <T>(ICollection <T> source, T[] array, int arrayIndex)
        {
            if (array == null)
            {
                CheckParam.ThrowArgumentNull(nameof(array));
            }
            if ((uint)arrayIndex > (uint)array.Length)
            {
                CheckParam.ThrowOutOfRange(nameof(arrayIndex));
            }
            if ((array.Length - arrayIndex) < source.Count)
            {
                CheckParam.ThrowBadArgument("Destination array is not large enough. Check array.Length and arrayIndex.");
            }

            foreach (T item in source)
            {
                array[arrayIndex++] = item;
            }
        }
Exemplo n.º 9
0
        public void CopyTo(T[] array, int arrayIndex)
        {
            int space = array.Length - arrayIndex;
            int count = Count;

            if (space < count)
            {
                if ((uint)arrayIndex >= (uint)count)
                {
                    CheckParam.ThrowOutOfRange("arrayIndex");
                }
                else
                {
                    CheckParam.ThrowBadArgument(nameof(array), "CopyTo: array is too small ({0} < {1})", space, count);
                }
            }

            for (int i = 0; i < count; i++)
            {
                array[arrayIndex + i] = this[i];
            }
        }