Exemplo n.º 1
0
        public ImmutableHashMap <TKey, TValue> WithComparers(IEqualityComparer <TKey> keyComparer, IEqualityComparer <TValue> valueComparer)
        {
            if (keyComparer == null)
            {
                keyComparer = EqualityComparer <TKey> .Default;
            }

            if (valueComparer == null)
            {
                valueComparer = EqualityComparer <TValue> .Default;
            }

            if (this.keyComparer == keyComparer)
            {
                if (this.valueComparer == valueComparer)
                {
                    return(this);
                }
                else
                {
                    // When the key comparer is the same but the value comparer is different, we don't need a whole new tree
                    // because the structure of the tree does not depend on the value comparer.
                    // We just need a new root node to store the new value comparer.
                    return(new ImmutableHashMap <TKey, TValue>(this.root, this.keyComparer, valueComparer));
                }
            }
            else
            {
                var set = new ImmutableHashMap <TKey, TValue>(keyComparer, valueComparer);
                set = set.AddRange(this, overwriteOnCollision: false, avoidToHashMap: true);
                return(set);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Attempts to discover an <see cref="ImmutableHashMap&lt;TKey, TValue&gt;"/> 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="ImmutableHashMap&lt;TKey, TValue&gt;"/> 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, out ImmutableHashMap <TKey, TValue> other)
        {
            other = sequence as ImmutableHashMap <TKey, TValue>;
            if (other != null)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
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(ImmutableHashMap <TKey, TValue> map)
 {
     Requires.NotNull(map, "map");
     this.map = map;
 }