Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ImmutableDictionary{TKey, TValue}"/> class.
        /// </summary>
        /// <param name="root">The root.</param>
        /// <param name="comparers">The comparers.</param>
        /// <param name="count">The number of elements in the map.</param>
        private ImmutableDictionary(SortedInt32KeyNode <HashBucket> root, Comparers comparers, int count)
            : this(Requires.NotNullPassthrough(comparers, nameof(comparers)))
        {
            Requires.NotNull(root, nameof(root));

            root.Freeze(s_FreezeBucketAction);
            _root  = root;
            _count = count;
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ImmutableDictionary&lt;TKey, TValue&gt;"/> class.
        /// </summary>
        /// <param name="root">The root.</param>
        /// <param name="comparers">The comparers.</param>
        /// <param name="count">The number of elements in the map.</param>
        private ImmutableDictionary(SortedInt32KeyNode <HashBucket> root, Comparers comparers, int count)
            : this(Requires.NotNullPassthrough(comparers, "comparers"))
        {
            Requires.NotNull(root, "root");

            root.Freeze(FreezeBucketAction);
            this.root  = root;
            this.count = count;
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ImmutableHashSet&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="root">The sorted set that this set wraps.</param>
        /// <param name="equalityComparer">The equality comparer used by this instance.</param>
        /// <param name="count">The number of elements in this collection.</param>
        private ImmutableHashSet(SortedInt32KeyNode <HashBucket> root, IEqualityComparer <T> equalityComparer, int count)
        {
            Requires.NotNull(root, "root");
            Requires.NotNull(equalityComparer, "equalityComparer");

            root.Freeze(FreezeBucketAction);
            this.root             = root;
            this.count            = count;
            this.equalityComparer = equalityComparer;
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ImmutableHashSet{T}"/> class.
        /// </summary>
        /// <param name="root">The sorted set that this set wraps.</param>
        /// <param name="equalityComparer">The equality comparer used by this instance.</param>
        /// <param name="count">The number of elements in this collection.</param>
        private ImmutableHashSet(SortedInt32KeyNode <HashBucket> root, IEqualityComparer <T> equalityComparer, int count)
        {
            Requires.NotNull(root, nameof(root));
            Requires.NotNull(equalityComparer, nameof(equalityComparer));

            root.Freeze(s_FreezeBucketAction);
            _root             = root;
            _count            = count;
            _equalityComparer = equalityComparer;
        }
Пример #5
0
        /// <summary>
        /// Freezes this node and all descendant nodes so that any mutations require a new instance of the nodes.
        /// </summary>
        internal void Freeze(Action <KeyValuePair <int, TValue> > freezeAction = null)
        {
            // If this node is frozen, all its descendants must already be frozen.
            if (!_frozen)
            {
                freezeAction?.Invoke(new KeyValuePair <int, TValue>(_key, _value));

                _left.Freeze(freezeAction);
                _right.Freeze(freezeAction);
                _frozen = true;
            }
        }