コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImmutableSortedDictionaryBuilderDebuggerProxy&lt;TKey, TValue&gt;"/> class.
 /// </summary>
 /// <param name="map">The collection to display in the debugger</param>
 public ImmutableSortedDictionaryBuilderDebuggerProxy(ImmutableSortedDictionary <TKey, TValue> .Builder map)
 {
     Requires.NotNull(map, "map");
     _map = map;
 }
コード例 #2
0
        /// <summary>
        /// Performs the set operation on a given data structure.
        /// </summary>
        private static MutationResult Except(IEnumerable <T> other, IEqualityComparer <T> equalityComparer, ImmutableSortedDictionary <int, HashBucket> .Node root)
        {
            Requires.NotNull(other, "other");
            Requires.NotNull(equalityComparer, "equalityComparer");
            Requires.NotNull(root, "root");

            int count   = 0;
            var newRoot = root;

            foreach (var item in other)
            {
                int        hashCode = equalityComparer.GetHashCode(item);
                HashBucket bucket;
                if (newRoot.TryGetValue(hashCode, Comparer <int> .Default, out bucket))
                {
                    OperationResult result;
                    HashBucket      newBucket = bucket.Remove(item, equalityComparer, out result);
                    if (result == OperationResult.SizeChanged)
                    {
                        count--;
                        newRoot = UpdateRoot(newRoot, hashCode, newBucket);
                    }
                }
            }

            return(new MutationResult(newRoot, count));
        }
コード例 #3
0
        public static ImmutableSortedDictionary <TKey, TValue> ToImmutableSortedDictionary <TKey, TValue>(this ImmutableSortedDictionary <TKey, TValue> .Builder builder) where TKey : notnull
        {
            Requires.NotNull(builder, nameof(builder));

            return(builder.ToImmutable());
        }
コード例 #4
0
        /// <summary>
        /// Attempts to discover an <see cref="ImmutableSortedDictionary{TKey, TValue}"/> instance beneath some enumerable sequence
        /// if one exists.
        /// </summary>
        /// <param name="sequence">The sequence that may have come from an immutable map.</param>
        /// <param name="other">Receives the concrete <see cref="ImmutableSortedDictionary{TKey, TValue}"/> typed value if one can be found.</param>
        /// <returns><c>true</c> if the cast was successful; <c>false</c> otherwise.</returns>
        private static bool TryCastToImmutableMap(IEnumerable <KeyValuePair <TKey, TValue> > sequence, [NotNullWhen(true)] out ImmutableSortedDictionary <TKey, TValue>?other)
        {
            other = sequence as ImmutableSortedDictionary <TKey, TValue>;
            if (other != null)
            {
                return(true);
            }

            if (sequence is Builder builder)
            {
                other = builder.ToImmutable();
                return(true);
            }

            return(false);
        }
コード例 #5
0
 /// <summary>
 /// Wraps the specified data structure with an immutable collection wrapper.
 /// </summary>
 /// <param name="root">The root of the data structure.</param>
 /// <param name="adjustedCountIfDifferentRoot">The adjusted count if the root has changed.</param>
 /// <returns>The immutable collection.</returns>
 private ImmutableHashSet <T> Wrap(ImmutableSortedDictionary <int, HashBucket> .Node root, int adjustedCountIfDifferentRoot)
 {
     return((root != this.root) ? new ImmutableHashSet <T>(root, this.equalityComparer, adjustedCountIfDifferentRoot) : this);
 }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImmutableDictionary&lt;TKey, TValue&gt;.MutationInput"/> struct.
 /// </summary>
 /// <param name="map">The map.</param>
 internal MutationInput(ImmutableDictionary <TKey, TValue> map)
 {
     this.root      = map.root;
     this.comparers = map.comparers;
     this.count     = map.count;
 }
コード例 #7
0
 /// <summary>
 /// Removes all items from the <see cref="T:System.Collections.Generic.ICollection`1"/>.
 /// </summary>
 /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only. </exception>
 public void Clear()
 {
     this.count = 0;
     this.Root  = ImmutableSortedDictionary <int, HashBucket> .Node.EmptyNode;
 }
コード例 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImmutableHashSet&lt;T&gt;.NodeEnumerable"/> struct.
 /// </summary>
 /// <param name="root">The root.</param>
 internal NodeEnumerable(ImmutableSortedDictionary <int, HashBucket> .Node root)
 {
     Requires.NotNull(root, "root");
     this.root = root;
 }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImmutableDictionary&lt;TKey, TValue&gt;.MutationResult"/> struct.
 /// </summary>
 /// <param name="root">The root.</param>
 /// <param name="countAdjustment">The count adjustment.</param>
 internal MutationResult(ImmutableSortedDictionary <int, HashBucket> .Node root, int countAdjustment)
 {
     Requires.NotNull(root, "root");
     this.root            = root;
     this.countAdjustment = countAdjustment;
 }
コード例 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImmutableDictionary&lt;TKey, TValue&gt;.MutationResult"/> struct.
 /// </summary>
 /// <param name="unchangedInput">The unchanged input.</param>
 internal MutationResult(MutationInput unchangedInput)
 {
     this.root            = unchangedInput.Root;
     this.countAdjustment = 0;
 }
コード例 #11
0
 /// <summary>
 /// Applies the result of some mutation operation to this instance.
 /// </summary>
 /// <param name="result">The result.</param>
 private bool Apply(MutationResult result)
 {
     this.Root   = result.Root;
     this.count += result.CountAdjustment;
     return(result.CountAdjustment != 0);
 }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImmutableSortedDictionaryDebuggerProxy{TKey, TValue}"/> class.
 /// </summary>
 /// <param name="map">The collection to display in the debugger</param>
 public ImmutableSortedDictionaryDebuggerProxy(ImmutableSortedDictionary <TKey, TValue> map)
 {
     Requires.NotNull(map, nameof(map));
     _map = map;
 }