Show / Hide Table of Contents

Class CopyOnWriteList<T>

A thread-safe variant of in which all mutative operations are implemented by making a snapshot copy of the underlying array.

Inheritance
Object
CopyOnWriteList<T>
Implements
IList<T>
ICloneable
Namespace: DotNext.Collections.Concurrent
Assembly: DotNext.dll
Syntax
public class CopyOnWriteList<T> : IReadOnlyList<T>, IList<T>, ICloneable
Type Parameters
Name Description
T

The type of elements held in this collection.

Remarks

This list is perfect for scenarios when reads are frequent and concurrent but writes not. Read operation never cause synchronization of the list. The enumerator doesn't track additions, removals or changes in the list since enumerator was created. As a result, dirty reads are possible.

Constructors

| Improve this Doc View Source

CopyOnWriteList()

Initializes a new empty list.

Declaration
public CopyOnWriteList()
| Improve this Doc View Source

CopyOnWriteList(IReadOnlyCollection<T>)

Initializes a new list containing elements copied from the given read-only collection.

Declaration
public CopyOnWriteList(IReadOnlyCollection<T> collection)
Parameters
Type Name Description
IReadOnlyCollection<T> collection

The source of the items in the creating list.

Properties

| Improve this Doc View Source

Count

Gets the number of elements in this list.

Declaration
public long Count { get; }
Property Value
Type Description
Int64
| Improve this Doc View Source

Item[Int64]

Gets or sets list item.

Declaration
public T this[long index] { get; set; }
Parameters
Type Name Description
Int64 index

The index of the list item.

Property Value
Type Description
T

The list item.

| Improve this Doc View Source

Snapshot

Gets the snapshot view of the current list.

Declaration
public ReadOnlyMemory<T> Snapshot { get; }
Property Value
Type Description
ReadOnlyMemory<T>

Methods

| Improve this Doc View Source

Add(T)

Adds an item to the end of this list.

Declaration
public void Add(T item)
Parameters
Type Name Description
T item

The item to be added to the end of this list. null is allowed.

Remarks

This operation causes reallocation of underlying array.

| Improve this Doc View Source

Clear()

Removes all items from this list.

Declaration
public void Clear()
| Improve this Doc View Source

Clear(Action<T>)

Removes all items from this list and performs cleanup operation for each item.

Declaration
public void Clear(Action<T> cleaner)
Parameters
Type Name Description
Action<T> cleaner

The action used to clean item from this list.

| Improve this Doc View Source

Clear(ValueAction<T>)

Removes all items from this list and performs cleanup operation for each item.

Declaration
public void Clear(in ValueAction<T> cleaner)
Parameters
Type Name Description
ValueAction<T> cleaner

The action used to clean item from this list.

| Improve this Doc View Source

Clone()

Creates copy of this list.

Declaration
public CopyOnWriteList<T> Clone()
Returns
Type Description
CopyOnWriteList<T>

The copy of this list.

| Improve this Doc View Source

Contains(T)

Determines whether an item is in this list.

Declaration
public bool Contains(T item)
Parameters
Type Name Description
T item

The object to locate in this list.

Returns
Type Description
Boolean

true, if item is found in this list; otherwise, false.

| Improve this Doc View Source

CopyTo(T[], Int32)

Copies the entire list to a compatible one-dimensional array, starting at the specified index of the target array.

Declaration
public void CopyTo(T[] array, int arrayIndex)
Parameters
Type Name Description
T[] array

The one-dimensional array that is the destination of the elements copied from this list.

Int32 arrayIndex

The zero-based index in array at which copying begins.

| Improve this Doc View Source

Exists(Predicate<T>)

Determines whether this list contains elements that match the conditions defined by the specified predicate.

Declaration
public bool Exists(Predicate<T> match)
Parameters
Type Name Description
DotNext.Predicate<T> match

The predicate that defines the conditions of the elements to search for.

Returns
Type Description
Boolean

true if array contains one or more elements that match the conditions defined by the specified predicate; otherwise, false.

| Improve this Doc View Source

Find(Predicate<T>)

Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire list.

Declaration
public T Find(Predicate<T> match)
Parameters
Type Name Description
DotNext.Predicate<T> match

The predicate that defines the conditions of the element to search for.

Returns
Type Description
T

The first element that matches the conditions defined by the specified predicate, if found; otherwise, the default value for type T.

| Improve this Doc View Source

FindIndex(Predicate<T>)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the entire list

Declaration
public int FindIndex(Predicate<T> match)
Parameters
Type Name Description
DotNext.Predicate<T> match

The predicate that defines the conditions of the element to search for.

Returns
Type Description
Int32

The zero-based index of the first occurrence of an element that matches the conditions defined by match, if found; otherwise, -1.

| Improve this Doc View Source

FindLast(Predicate<T>)

Searches for an element that matches the conditions defined by the specified predicate, and returns the last occurrence within the entire list.

Declaration
public T FindLast(Predicate<T> match)
Parameters
Type Name Description
DotNext.Predicate<T> match

The predicate that defines the conditions of the element to search for.

Returns
Type Description
T

The last element that matches the conditions defined by the specified predicate, if found; otherwise, the default value for type T.

| Improve this Doc View Source

FindLastIndex(Predicate<T>)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the entire list

Declaration
public int FindLastIndex(Predicate<T> match)
Parameters
Type Name Description
DotNext.Predicate<T> match

The predicate that defines the conditions of the element to search for.

Returns
Type Description
Int32

The zero-based index of the last occurrence of an element that matches the conditions defined by match, if found; otherwise, -1.

| Improve this Doc View Source

GetEnumerator()

Gets enumerator over snapshot of this list.

Declaration
public CopyOnWriteList<T>.Enumerator GetEnumerator()
Returns
Type Description
CopyOnWriteList.Enumerator<>

The enumerator over snapshot of this list.

| Improve this Doc View Source

IndexOf(T)

Returns the zero-based index of the first occurrence of a value in this list.

Declaration
public int IndexOf(T item)
Parameters
Type Name Description
T item

The object to locate in this list.

Returns
Type Description
Int32

The zero-based index of the first occurrence of item, if found; otherwise, -1.

| Improve this Doc View Source

Insert(Int64, T)

Inserts an element into this list at the specified index.

Declaration
public void Insert(long index, T item)
Parameters
Type Name Description
Int64 index

The zero-based index at which item should be inserted.

T item

The object to insert.

Remarks

This operation causes reallocation of underlying array.

| Improve this Doc View Source

LastIndexOf(T)

Returns the zero-based index of the last occurrence of a value in this list.

Declaration
public int LastIndexOf(T item)
Parameters
Type Name Description
T item

The object to locate in this list.

Returns
Type Description
Int32

The zero-based index of the last occurrence of item, if found; otherwise, -1.

| Improve this Doc View Source

Remove(T)

Removes the first occurrence of an item from this list.

Declaration
public bool Remove(T item)
Parameters
Type Name Description
T item

The item to remove from this list.

Returns
Type Description
Boolean

true if item is successfully removed; otherwise, false.

Remarks

This operation causes reallocation of underlying array.

| Improve this Doc View Source

RemoveAll(Predicate<T>)

Removes all the elements that match the conditions defined by the specified predicate.

Declaration
public long RemoveAll(Predicate<T> match)
Parameters
Type Name Description
DotNext.Predicate<T> match

The predicate that defines the conditions of the elements to remove.

Returns
Type Description
Int64

The number of elements removed from this list.

| Improve this Doc View Source

RemoveAll(Predicate<T>, Action<T>)

Removes all the elements that match the conditions defined by the specified predicate.

Declaration
public void RemoveAll(Predicate<T> match, Action<T> callback)
Parameters
Type Name Description
DotNext.Predicate<T> match

The predicate that defines the conditions of the elements to remove.

Action<T> callback

The delegate that is used to accept removed items.

| Improve this Doc View Source

RemoveAll(ValueFunc<T, Boolean>)

Removes all the elements that match the conditions defined by the specified predicate.

Declaration
public long RemoveAll(ValueFunc<T, bool> match)
Parameters
Type Name Description
ValueFunc<T, Boolean> match

The predicate that defines the conditions of the elements to remove.

Returns
Type Description
Int64

The number of elements removed from this list.

| Improve this Doc View Source

RemoveAll(ValueFunc<T, Boolean>, ValueAction<T>)

Removes all the elements that match the conditions defined by the specified predicate.

Declaration
public void RemoveAll(in ValueFunc<T, bool> match, in ValueAction<T> callback)
Parameters
Type Name Description
ValueFunc<T, Boolean> match

The predicate that defines the conditions of the elements to remove.

ValueAction<T> callback

The delegate that is used to accept removed items.

| Improve this Doc View Source

RemoveAt(Int64)

Removes the element at the specified index of this list.

Declaration
public void RemoveAt(long index)
Parameters
Type Name Description
Int64 index

The zero-based index of the element to remove.

Remarks

This operation causes reallocation of underlying array.

| Improve this Doc View Source

Set(ReadOnlySpan<T>)

Replaces all items in this list with given array.

Declaration
public void Set(ReadOnlySpan<T> array)
Parameters
Type Name Description
ReadOnlySpan<T> array

The array of new items.

| Improve this Doc View Source

Set<G>(ICollection<G>, Converter<G, T>)

Replaces all items in this list with new items.

Declaration
public void Set<G>(ICollection<G> items, Converter<G, T> converter)
Parameters
Type Name Description
ICollection<G> items

The source items to be converted and placed into this list.

DotNext.Converter<G, T> converter

The convert of source items.

Type Parameters
Name Description
G

The type of source items.

| Improve this Doc View Source

Set<G>(ICollection<G>, ValueFunc<G, T>)

Replaces all items in this list with new items.

Declaration
public void Set<G>(ICollection<G> items, in ValueFunc<G, T> converter)
Parameters
Type Name Description
ICollection<G> items

The source items to be converted and placed into this list.

ValueFunc<G, T> converter

The convert of source items.

Type Parameters
Name Description
G

The type of source items.

Operators

| Improve this Doc View Source

Explicit(CopyOnWriteList<T> to ReadOnlySpan<T>)

Obtains snapshot of the underlying array in the form of the span.

Declaration
public static explicit operator ReadOnlySpan<T>(CopyOnWriteList<T> list)
Parameters
Type Name Description
CopyOnWriteList<T> list

The list to be converted into span.

Returns
Type Description
ReadOnlySpan<T>

Implements

IList<>
ICloneable

Extension Methods

AsyncLockAcquisition.AcquireLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireUpgradeableReadLockAsync<T>(T, TimeSpan)
AsyncLockAcquisition.AcquireUpgradeableReadLockAsync<T>(T, CancellationToken)
ExpressionBuilder.Const<T>(T)
ObjectExtensions.GetUserData<T>(T)
ObjectExtensions.IsOneOf<T>(T, IEnumerable<T>)
ObjectExtensions.IsOneOf<T>(T, T[])
ObjectExtensions.Decompose<T, R1, R2>(T, Func<T, R1>, Func<T, R2>, out R1, out R2)
ObjectExtensions.Decompose<T, R1, R2>(T, ValueFunc<T, R1>, ValueFunc<T, R2>, out R1, out R2)
ObjectExtensions.Decompose<T, R1, R2>(T, Func<T, R1>, Func<T, R2>)
ObjectExtensions.Decompose<T, R1, R2>(T, ValueFunc<T, R1>, ValueFunc<T, R2>)
LockAcquisition.AcquireReadLock<T>(T)
LockAcquisition.AcquireReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireWriteLock<T>(T)
LockAcquisition.AcquireWriteLock<T>(T, TimeSpan)
LockAcquisition.AcquireUpgradeableReadLock<T>(T)
LockAcquisition.AcquireUpgradeableReadLock<T>(T, TimeSpan)
  • Improve this Doc
  • View Source
Back to top Generated by DocFX