/// <summary>
        /// See the <see cref="IImmutableDictionary{TKey, TValue}"/> interface.
        /// </summary>
        public ImmutableSortedDictionary <TKey, TValue> AddRange(IEnumerable <KeyValuePair <TKey, TValue> > items)
        {
            Requires.NotNull(items, nameof(items));

            return(this.AddRange(items, overwriteOnCollision: false, avoidToSortedMap: false));
        }
 public static int IndexOf <T>(this IImmutableList <T> list, T item, IEqualityComparer <T> equalityComparer)
 {
     Requires.NotNull(list, nameof(list));
     return(list.IndexOf(item, 0, list.Count, equalityComparer));
 }
        public static ImmutableList <TSource> ToImmutableList <TSource>(this ImmutableList <TSource> .Builder builder)
        {
            Requires.NotNull(builder, nameof(builder));

            return(builder.ToImmutable());
        }
Exemple #4
0
 /// <summary>
 /// Adds the specified items to the end of the array.
 /// </summary>
 /// <param name="items">The items.</param>
 public void AddRange <TDerived>(ImmutableArray <TDerived> .Builder items) where TDerived : T
 {
     Requires.NotNull(items, "items");
     this.AddRange(items._elements, items.Count);
 }
 public static IImmutableList <T> Remove <T>(this IImmutableList <T> list, T value)
 {
     Requires.NotNull(list, nameof(list));
     return(list.Remove(value, EqualityComparer <T> .Default));
 }
 /// <summary>
 /// See the <see cref="IImmutableDictionary{TKey, TValue}"/> interface.
 /// </summary>
 public bool TryGetKey(TKey equalKey, out TKey actualKey)
 {
     Requires.NotNullAllowStructs(equalKey, "equalKey");
     return(TryGetKey(equalKey, this.Origin, out actualKey));
 }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Builder"/> class.
 /// </summary>
 /// <param name="capacity">The initial capacity of the internal array.</param>
 internal Builder(int capacity)
 {
     Requires.Range(capacity >= 0, "capacity");
     _elements = new T[capacity];
     _count    = 0;
 }
Exemple #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HashBucketByValueEqualityComparer"/> class.
 /// </summary>
 /// <param name="valueComparer">The value comparer for T.</param>
 internal HashBucketByValueEqualityComparer(IEqualityComparer <T> valueComparer)
 {
     Requires.NotNull(valueComparer, nameof(valueComparer));
     _valueComparer = valueComparer;
 }
Exemple #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DebuggerProxy"/> class.
 /// </summary>
 /// <param name="map">The collection to display in the debugger</param>
 public DebuggerProxy(ImmutableDictionary <TKey, TValue> map)
 {
     Requires.NotNull(map, "map");
     this.map = map;
 }
Exemple #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Builder"/> class.
 /// </summary>
 /// <param name="capacity">The initial capacity of the internal array.</param>
 internal Builder(int capacity)
 {
     Requires.Range(capacity >= 0, "capacity");
     this.elements = new RefAsValueType<T>[capacity];
     this.Count = 0;
 }
Exemple #11
0
 internal Comparer(IComparer<T> comparer = null)
 {
     Requires.NotNull(comparer, "comparer");
     this.comparer = comparer;
 }
 /// <summary>
 /// See the <see cref="IImmutableDictionary{TKey, TValue}"/> interface.
 /// </summary>
 public bool TryGetKey(TKey equalKey, out TKey actualKey)
 {
     Requires.NotNullAllowStructs(equalKey, nameof(equalKey));
     return(_root.TryGetKey(equalKey, _keyComparer, out actualKey));
 }
 /// <summary>
 /// See the <see cref="IImmutableDictionary{TKey, TValue}"/> interface.
 /// </summary>
 public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
 {
     Requires.NotNullAllowStructs(key, nameof(key));
     return(_root.TryGetValue(key, _keyComparer, out value !));
 }
 /// <summary>
 /// See the <see cref="IImmutableDictionary{TKey, TValue}"/> interface.
 /// </summary>
 public bool ContainsKey(TKey key)
 {
     Requires.NotNullAllowStructs(key, nameof(key));
     return(_root.ContainsKey(key, _keyComparer));
 }
 /// <summary>
 /// Determines whether the specified key contains key.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <returns>
 ///   <c>true</c> if the specified key contains key; otherwise, <c>false</c>.
 /// </returns>
 public bool ContainsKey(TKey key)
 {
     Requires.NotNullAllowStructs(key, "key");
     return(ContainsKey(key, this.Origin));
 }
Exemple #16
0
        /// <summary>
        /// Adds the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <param name="valueComparer">The value comparer.</param>
        /// <param name="replacedExistingValue">Receives a value indicating whether an existing value was replaced.</param>
        /// <param name="mutated">Receives a value indicating whether this node tree has mutated because of this operation.</param>
        internal SortedInt32KeyNode <TValue> SetItem(int key, TValue value, IEqualityComparer <TValue> valueComparer, out bool replacedExistingValue, out bool mutated)
        {
            Requires.NotNull(valueComparer, "valueComparer");

            return(this.SetOrAdd(key, value, valueComparer, true, out replacedExistingValue, out mutated));
        }
 /// <summary>
 /// See the <see cref="IImmutableDictionary{TKey, TValue}"/> interface.
 /// </summary>
 public bool TryGetValue(TKey key, out TValue value)
 {
     Requires.NotNullAllowStructs(key, "key");
     return(TryGetValue(key, this.Origin, out value));
 }
Exemple #18
0
 private static bool IsLeftHeavy(SortedInt32KeyNode <TValue> tree)
 {
     Requires.NotNull(tree, "tree");
     Debug.Assert(!tree.IsEmpty);
     return(Balance(tree) <= -2);
 }
 internal SecurePooledObject(T newValue)
 {
     Requires.NotNullAllowStructs(newValue, nameof(newValue));
     _value = newValue;
 }
Exemple #20
0
 public static bool Contains <TKey, TValue>(this IImmutableDictionary <TKey, TValue> map, TKey key, TValue value)
 {
     Requires.NotNull(map, nameof(map));
     Requires.NotNullAllowStructs(key, nameof(key));
     return(map.Contains(new KeyValuePair <TKey, TValue>(key, value)));
 }
Exemple #21
0
 /// <summary>
 /// Adds the specified items to the end of the array.
 /// </summary>
 /// <param name="items">The items.</param>
 public void AddRange(Builder items)
 {
     Requires.NotNull(items, "items");
     this.AddRange(items._elements, items.Count);
 }
        public bool IsSupersetOf(IEnumerable <T> other)
        {
            Requires.NotNull(other, "other");

            return(IsSupersetOf(other, this.Origin));
        }
Exemple #23
0
 /// <summary>
 /// Copies the current contents to the specified array.
 /// </summary>
 /// <param name="array">The array to copy to.</param>
 /// <param name="index">The starting index of the target array.</param>
 public void CopyTo(T[] array, int index)
 {
     Requires.NotNull(array, "array");
     Requires.Range(index >= 0 && index + this.Count <= array.Length, "start");
     Array.Copy(_elements, 0, array, index, this.Count);
 }
        public bool Overlaps(IEnumerable <T> other)
        {
            Requires.NotNull(other, "other");

            return(Overlaps(other, this.Origin));
        }
 public static IImmutableList <T> RemoveRange <T>(this IImmutableList <T> list, IEnumerable <T> items)
 {
     Requires.NotNull(list, nameof(list));
     return(list.RemoveRange(items, EqualityComparer <T> .Default));
 }
 /// <summary>
 /// See the <see cref="IImmutableSet{T}"/> interface.
 /// </summary>
 public bool Contains(T item)
 {
     Requires.NotNullAllowStructs(item, "item");
     return(Contains(item, this.Origin));
 }
 public static int LastIndexOf <T>(this IImmutableList <T> list, T item, int startIndex, int count)
 {
     Requires.NotNull(list, nameof(list));
     return(list.LastIndexOf(item, startIndex, count, EqualityComparer <T> .Default));
 }
Exemple #28
0
            /// <summary>
            /// Initializes an <see cref="Enumerator"/> structure.
            /// </summary>
            /// <param name="root">The root of the set to be enumerated.</param>
            /// <param name="builder">The builder, if applicable.</param>
            /// <param name="startIndex">The index of the first element to enumerate.</param>
            /// <param name="count">The number of elements in this collection.</param>
            /// <param name="reversed"><c>true</c> if the list should be enumerated in reverse order.</param>
            internal Enumerator(Node root, Builder builder = null, int startIndex = -1, int count = -1, bool reversed = false)
            {
                Requires.NotNull(root, nameof(root));
                Requires.Range(startIndex >= -1, nameof(startIndex));
                Requires.Range(count >= -1, nameof(count));
                Requires.Argument(reversed || count == -1 || (startIndex == -1 ? 0 : startIndex) + count <= root.Count);
                Requires.Argument(!reversed || count == -1 || (startIndex == -1 ? root.Count - 1 : startIndex) - count + 1 >= 0);

                _root    = root;
                _builder = builder;
                _current = null;
                _currentNodeEnumeratingByIndex = null;
                _startIndex                = startIndex >= 0 ? startIndex : (reversed ? root.Count - 1 : 0);
                _currentIndex              = _startIndex;
                _count                     = count == -1 ? root.Count : count;
                _remainingCount            = _count;
                _reversed                  = reversed;
                _enumeratingBuilderVersion = builder != null ? builder.Version : -1;
                _stackSlot0                = default;
                _stackSlot1                = default;
                _stackSlot2                = default;
                _stackSlot3                = default;
                _stackSlot4                = default;
                _stackSlot5                = default;
                _stackSlot6                = default;
                _stackSlot7                = default;
                _stackSlot8                = default;
                _stackSlot9                = default;
                _stackSlot10               = default;
                _stackSlot11               = default;
                _stackSlot12               = default;
                _stackSlot13               = default;
                _stackSlot14               = default;
                _stackSlot15               = default;
                _stackSlot16               = default;
                _stackSlot17               = default;
                _stackSlot18               = default;
                _stackSlot19               = default;
                _stackSlot20               = default;
                _stackSlot21               = default;
                _stackSlot22               = default;
                _stackSlot23               = default;
                _stackSlot24               = default;
                _stackSlot25               = default;
                _stackSlot26               = default;
                _stackSlot27               = default;
                _stackSlot28               = default;
                _stackSlot29               = default;
                _stackSlot30               = default;
                _stackSlot31               = default;
                _stackSlot32               = default;
                _stackSlot33               = default;
                _stackSlot34               = default;
                _stackSlot35               = default;
                _stackSlot36               = default;
                _stackSlot37               = default;
                _stackSlot38               = default;
                _stackSlot39               = default;
                _stackSlot40               = default;
                _stackSlot41               = default;
                _stackSlot42               = default;
                _stackSlot43               = default;
                _stackSlot44               = default;
                _stackSlot45               = default;
                _stackSlot46               = default;
                _stackTopIndex             = -1;
                if (_count > 0)
                {
                    this.ResetStack();
                }
            }
 public static IImmutableList <T> Replace <T>(this IImmutableList <T> list, T oldValue, T newValue)
 {
     Requires.NotNull(list, nameof(list));
     return(list.Replace(oldValue, newValue, EqualityComparer <T> .Default));
 }
        /// <summary>
        /// Returns a read-only reference to the value associated with the provided key.
        /// </summary>
        /// <exception cref="KeyNotFoundException">If the key is not present.</exception>
        public ref readonly TValue ValueRef(TKey key)
        {
            Requires.NotNullAllowStructs(key, nameof(key));

            return(ref _root.ValueRef(key, _keyComparer));
        }