Table of Contents

ConcurrentHashSet<T>.Enumerator Struct

Definition

Namespace
Bodu.Collections.Generic.Concurrent
Assembly
Bodu.Collections.Concurrent.dll
Package
Bodu.Collections.Concurrent 1.0.0
Source
ConcurrentHashSet{T}.Core.cs

Enumerates a weakly consistent snapshot of a ConcurrentHashSet<T>.

public struct ConcurrentHashSet<T>.Enumerator : IEnumerator<T>, IEnumerator, IDisposable
Implements
Inherited Members
Extension Methods

Remarks

The enumerator captures a snapshot of the set's elements when it is created, by calling ToArray(). All iteration runs over that fixed copy and is unaffected by concurrent additions or removals on the originating set. The snapshot itself is weakly consistent (see ToArray()): it contains every element present for the entire duration of its capture, but it is not guaranteed to correspond to the set's state at any single instant. The no-duplicate guarantee holds across distinct hash keys; an element concurrently removed and re-added may, in rare full-hash-collision interleavings, appear twice.

Because the snapshot is taken eagerly, creating the enumerator allocates an array proportional to the number of elements present at that moment. The enumerator never throws InvalidOperationException as a result of concurrent modification.

The order in which elements are yielded is unspecified and may differ between enumerators.

Properties

Current

Gets the element at the current position of the enumerator.

public readonly T Current { get; }

Property Value

T

The element at the enumerator's current position.

Methods

Dispose()

Releases all resources used by the enumerator.

public readonly void Dispose()

Remarks

The enumerator holds no unmanaged or disposable resources; this method does nothing.

MoveNext()

Advances the enumerator to the next element of the snapshot.

public bool MoveNext()

Returns

bool

true if the enumerator advanced to a new element; false if it has passed the end of the snapshot.

Remarks

A default-valued ConcurrentHashSet<T>.Enumerator - one produced by default rather than by GetEnumerator() - holds no snapshot and is treated as an empty sequence.

Reset()

Resets the enumerator to its initial position, before the first element of the snapshot.

public void Reset()

Explicit Interface Implementations

IEnumerator.Current

Gets the element at the current position of the enumerator.

readonly object IEnumerator.Current { get; }

Returns

object

The element at the enumerator's current position.

Applies to

ProductVersions
.NET8, 10