Beispiel #1
0
            IEnumerator <TValue> IEnumerable <TValue> .GetEnumerator()
            {
                long startingVersion;
                int  startingSize;

                lock (_Dictionary._InternalLock)                        // Read with possible write operation
                {
                    if (_Dictionary.IsDeletedEntryAtHead)
                    {
                        _Dictionary.PruneDeletedEntries();
                    }

                    if (!_Dictionary._IsHeapOrdered)
                    {
                        _Dictionary.SortHeap();
                    }

                    startingVersion = _Dictionary._Version;
                    startingSize    = _Dictionary.HeapCount;
                }

                for (int heapIndex = 0; heapIndex < startingSize; heapIndex++)
                {
                    if (startingVersion != _Dictionary._Version)
                    {
                        throw new InvalidOperationException("The collection was modified; enumeration operation may not execute.");
                    }

                    HeapEntry appointment = _Dictionary._HeapEntries[heapIndex];

                    if (appointment.IsDeleted)
                    {
                        continue;
                    }

                    yield return(appointment.Value);
                }
            }