Class WeakList<T>
Represents a collection of weakly referenced values that maintains relative insertion order. If this collection is accessed concurrently from multiple threads in a read-only manner then no locking is necessary, otherwise a full lock or reader/writer lock must be obtained around all accesses.
Inherited Members
Namespace: Singulink.Collections
Assembly: Singulink.Collections.Weak.dll
Syntax
public sealed class WeakList<T> : IEnumerable<T>, IEnumerable where T : class
Type Parameters
Name | Description |
---|---|
T | Represents a collection of weakly referenced values that maintains relative insertion order. If this collection is accessed concurrently from multiple threads in a read-only manner then no locking is necessary, otherwise a full lock or reader/writer lock must be obtained around all accesses. |
Remarks
Internal entries for garbage collected values are not removed automatically by default. You can perform a full clean by calling the Clean() method or configure automatic cleaning after a set number of Add(T) operations by setting the AutoCleanAddCount property.
Constructors
Name | Description |
---|---|
WeakList() | Initializes a new instance of the WeakList<T> class. |
Properties
Name | Description |
---|---|
AddCountSinceLastClean | Gets the number of add operations that have been performed since the last cleaning. |
AutoCleanAddCount | Gets or sets the number of Add(T) operations that automatically triggers the Clean() method to run. Default value is null which indicates that automatic cleaning is not performed. |
Capacity | Gets or sets the total number of elements the internal data structure can hold without resizing. |
ExtraTrimCapacity | Gets or sets the extra capacity to leave when TrimExcess() is called. Default value is |
TrimExcessDuringClean | Gets or sets a value indicating whether to automatically call TrimExcess() whenever Clean() is called. Default value is false. |
UnsafeCount | Gets the number of entries in the internal data structure. This value will be different than the actual count if any of the values were garbage collected but still have internal entries in the list that have not been cleaned. |
Methods
Name | Description |
---|---|
Add(T) | Adds an item to the end of the collection. |
Clean() | Removes internal entries for values that have been garbage collected and trims the excess if TrimExcessDuringClean is set. |
Clear() | Removes all the elements from the collection. |
Contains(T, IEqualityComparer<T>?) | Determines whether the collection contains the given item using the specified equality comparer. |
GetEnumerator() | Returns an enumerator that iterates through the collection. |
InsertAfter(T, T, IEqualityComparer<T>?) | Inserts an item after another item. |
InsertBefore(T, T, IEqualityComparer<T>?) | Inserts an item before another item. |
InsertFirst(T) | Inserts an item to the beginning of the collection. |
Remove(T, IEqualityComparer<T>?) | Removes an item from the collection using the specified equality comparer. |
TrimExcess() | Reduces the internal capacity to the number of entries in the collection plus ExtraTrimCapacity. |
TryInsertAfter(T, T, IEqualityComparer<T>?) | Inserts an item after another item. |
TryInsertBefore(T, T, IEqualityComparer<T>?) | Inserts an item before another item. |
Explicit Interface Implementations
Name | Description |
---|---|
IEnumerable.GetEnumerator() | Returns an enumerator that iterates through the collection. |