/// <summary>
        /// Mutates the differential store from a concurrent read write data structure into a readonly sorted data structure.
        /// </summary>
        public void Sort()
        {
            var concurrentDictionary = this.component as ConcurrentDictionary <TKey, DifferentialStateVersions <TValue> >;

            Diagnostics.Assert(concurrentDictionary != null, this.traceType, "write operation came after becoming readonly.");

            // Using SortedList instead of SortedDictionary because
            // 1. SortedList uses less memory
            // 2. Populating all from sorted input is faster in SortedList than Sorted Dictionary
            // 3. SortedList keeps the state as two sorted arrays, which enables binarysearch and next/previous key searches (ReadNext).
            this.component = new SortedList <TKey, DifferentialStateVersions <TValue> >(concurrentDictionary, KeyComparer);
            Volatile.Write(ref this.isReadonly, true);

            // MCoskun: At this point, addList is not required anymore. AddList is still more efficient (since it only contains deltas) but it has memory overhead.
            // Using the "pay-as-you-go" philosophy, I am penalizing enumerators for smaller memory overhead in common case.
            this.addList = null;
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        public TDifferentialStoreComponent(
            ITransactionalReplicator transactionalReplicator,
            long stateProviderId,
            SnapshotContainer <TKey, TValue, TKeyComparer, TKeyEqualityComparer> snapshotContainer,
            LoadValueCounter loadValueCounter,
            bool isValueAReferenceType,
            string traceType)
        {
            this.traceType = traceType;
            this.transactionalReplicator = transactionalReplicator;
            this.stateProviderId         = stateProviderId;
            this.snapshotContainer       = snapshotContainer;

            this.component             = new ConcurrentDictionary <TKey, DifferentialStateVersions <TValue> >(KeyEqualityComparer);
            this.addList               = new AddList <TKey>(KeyComparer);
            this.isReadonly            = false;
            this.isValueAReferenceType = isValueAReferenceType;
            this.loadValueCounter      = loadValueCounter;
        }