public void Add(ulong key, TValue value) { if (!TryAdd(key, value)) { CheckParam.ThrowBadArgument(nameof(key), "Key already exists: {0}", key); } }
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; } }
public void SetTag(Symbol key, ValueT val) { if (key == null) { CheckParam.ThrowBadArgument("SetTag: key is null"); } int count = Count; KeyValuePair <Symbol, ValueT> kvp; // Try the last-accessed entry int hint = UserByte; if (hint < count) { if ((kvp = GetAtDff(hint)).Key == key) { SetAt(hint, new KeyValuePair <Symbol, ValueT>(key, val)); return; } } // Try the other entries for (int i = 0; i < count; i++) { if (i != hint && (kvp = GetAtDff(hint)).Key == key) { UserByte = (byte)i; SetAt(i, new KeyValuePair <Symbol, ValueT>(key, val)); return; } } Add(new KeyValuePair <Symbol, ValueT>(key, val)); }
public StdIdNode(Symbol name, LNode ras) : base(ras) { if ((_name = name) == null) { CheckParam.ThrowBadArgument("Cannot set IdNode.Name to null."); } }
public StdIdNode(Symbol name, SourceRange range, NodeStyle style = NodeStyle.Default) : base(range, style) { if ((_name = name) == null) { CheckParam.ThrowBadArgument("Cannot set IdNode.Name to null."); } }
void IDictionary <Symbol, ValueT> .Add(Symbol key, ValueT value) { if (HasTag(key)) { CheckParam.ThrowBadArgument(nameof(key), "The key '{0}' already exists in the IDictionary", key.Name); } SetTag(key, value); }
/// <summary>Adds the specified item to the set, or throws an exception if /// a matching item is already present.</summary> /// <exception cref="ArgumentException">The item already exists in the set.</exception> public void AddUnique(T item) { if (_set.Add(ref item, _comparer, false)) { _count++; } CheckParam.ThrowBadArgument("The item already exists in the set."); }
public void CopyTo(T[] array, int arrayIndex) { if (_count > array.Length - arrayIndex) { CheckParam.ThrowBadArgument("CopyTo: Insufficient space in supplied array"); } _set.CopyTo(array, arrayIndex); }
/// <summary>Adds the specified key-value pair to the trie, throwing an /// exception if the key is already present.</summary> public void Add(byte[] key, TValue value) { KeyWalker kw = new KeyWalker(key, key.Length); if (base.Set(ref kw, ref value, CPMode.Create)) { CheckParam.ThrowBadArgument(nameof(key), "Key already exists: {0}", key); } }
public void Add(string key, TValue value) { KeyWalker kw = StringToBytes(key); if (base.Set(ref kw, ref value, CPMode.Create)) { CheckParam.ThrowBadArgument(nameof(key), "Key already exists: {0}", key); } }
/// <inheritdoc cref="InternalSet{T}.IsProperSubsetOf(ISet{T}, int)"/> public void Add(KeyValuePair <K, V> item) { if (_set.Add(ref item, Comparer, false)) { _count++; return; } CheckParam.ThrowBadArgument("The specified key already exists in the map."); }
protected void CopyTo(T[] array, int arrayIndex) { if (Count > array.Length - arrayIndex) { CheckParam.ThrowBadArgument("CopyTo: Insufficient space in supplied array"); } IEnumerator <T> e = GetIEnumerator(); while (e.MoveNext()) { array[arrayIndex++] = e.Current; } }
public static void CopyTo <T>(this IReadOnlyCollection <T> c, T[] array, int arrayIndex) { int space = array.Length - arrayIndex; if (c.Count > space) { CheckParam.ThrowBadArgument(nameof(array), "CopyTo: array is too small ({0} < {1})", space, c.Count); } CheckParam.IsNotNegative(nameof(arrayIndex), arrayIndex); foreach (var item in c) { array[arrayIndex++] = item; } }
/// <summary>Gets the Symbol for an array with the specified number of /// dimensions, e.g. <c>GetArrayKeyword(3)</c> returns <c>[,,]</c>.</summary> public static Symbol GetArrayKeyword(int dims) { if (dims <= 0) { CheckParam.ThrowBadArgument("GetArrayKeyword(dims <= 0)"); } if (dims == 1) { return(Array); } if (dims == 2) { return(TwoDimensionalArray); } return(GSymbol.Get("'[" + new string(',', dims - 1) + "]")); }
public StreamCharSource(Stream stream, Decoder decoder, int bufSize) { if (bufSize <= MaxSeqSize) { throw new ArgumentException("bufSize <= " + MaxSeqSize.ToString()); } if (!stream.CanSeek) { CheckParam.ThrowBadArgument("stream does not support seeking."); } _buf = new byte[bufSize]; _blk = _blk2 = EmptyArray <char> .Value; _stream = stream; _decoder = decoder; _blkStart = _blk2Start = int.MinValue; _blkOffsets.Add(new Pair <int, uint>(0, 0)); // start of the first block }
/// <summary>Initializes a slice.</summary> /// <exception cref="ArgumentException">The start index was below zero.</exception> /// <remarks>The (start, count) range is allowed to be invalid, as long /// as 'start' is <c>Min</c> or above and 'count' is zero or above. /// <ul> /// <li>If 'start' is above the original Count, the Count of the new slice /// is set to zero.</li> /// <li>if (start + count) is above the original Count, the Count of the new /// slice is reduced to <c>list.Count - start</c>.</li> /// </ul> /// </remarks> public NegListSlice(INegListSource <T> list, int start, int count = int.MaxValue) { _list = list; _start = start; _count = count; if (start < list.Min) { CheckParam.ThrowBadArgument("The start index was below Min."); } if (count < 0) { CheckParam.ThrowBadArgument("The count was below zero."); } if ((long)start + count - 1 > _list.Max) { _count = (int)System.Math.Max((long)_list.Max + 1 - start, 0); // use long to avoid overflow if start==int.MaxValue && Max<0 } }
/// <summary>Initializes an array slice.</summary> /// <exception cref="ArgumentException">The start index was below zero.</exception> /// <remarks>The (start, count) range is allowed to be invalid, as long /// as 'start' is zero or above. /// <ul> /// <li>If 'count' is below zero, or if 'start' is above the original Length, /// the Count of the new slice is set to zero.</li> /// <li>if (start + count) is above the original Length, the Count of the new /// slice is reduced to <c>list.Length - start</c>.</li> /// </ul> /// </remarks> public ArraySlice(T[] list, int start, int count) { _list = list; _start = start; _count = count; if (start < 0) { CheckParam.ThrowBadArgument("The start index was below zero."); } if (count < 0) { CheckParam.ThrowBadArgument("The count was below zero."); } if (count > _list.Length - start) { _count = System.Math.Max(_list.Length - start, 0); } }
/// <summary>Initializes a slice.</summary> /// <exception cref="ArgumentException">The start index was below zero.</exception> /// <remarks>The (start, count) range is allowed to be invalid, as long /// as 'start' and 'count' are zero or above. /// <ul> /// <li>If 'start' is above the original Count, the Count of the new slice /// is set to zero.</li> /// <li>if (start + count) is above the original Count, the Count of the new /// slice is reduced to <c>list.Count - start</c>. Note that the Count of /// the slice will not increase if the list expands after the slice is /// created.</li> /// </ul> /// </remarks> public ListSlice(IList <T> list, int start, int count = int.MaxValue) { _list = list; _start = start; _count = count; if (start < 0) { CheckParam.ThrowBadArgument("The start index was below zero."); } if (count < 0) { CheckParam.ThrowBadArgument("The count was below zero."); } if (count > _list.Count - start) { _count = System.Math.Max(_list.Count - start, 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; } }
public ListSlice <T> Slice(int start, int count = int.MaxValue) { if (start < 0) { CheckParam.ThrowBadArgument("The start index was below zero."); } if (count < 0) { count = 0; } var slice = new ListSlice <T>(); slice._list = this._list; slice._start = this._start + start; slice._count = count; if (slice._count > this._count - start) { slice._count = System.Math.Max(this._count - start, 0); } return(slice); }
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]; } }
private void InsertRangeSizeMismatch() { CheckParam.ThrowBadArgument("InsertRange: Input collection's Count is different from the number of items enumerated"); }
private void ThrowKeyAlreadyExists(long key) { CheckParam.ThrowBadArgument(nameof(key), "Key already exists: {0}", key); }