IVersionedList<T> & IVersionedLongList<T> renamed to IRecyclableVersionedList<T> & IRecyclableVersionedLongList<T>. README.md updated.

This commit is contained in:
mlemanczyk committed 2023-06-25 01:08:06 +02:00
1 parent f96d9b056a
commit e65a7c2230
8 files changed
+34 -10

No files matched your search

+24
View File
@@ -222,7 +222,31 @@
* `blockSize` MUST be a power of 2. It will be rounded up to the closest power of 2, if needed. That is due to high performance gain on some operations, like the calculation of item index in a block.
* Array pools are shared between the same `T` type. I.e. `List<int>` will use a different pool from `List<short>` and so on. For high concurrency environments you may want to provide your own pools, when this feature becomes available in the upcoming releases.
* Trying to access `this[int index]`, `this[long index]`, `Count`, `LongCount` etc. when `Capacity == 0` will raise `NullReferenceException`. This is by design to remove all non-critical code from the constructor.
* ⚠️ The default enumerators don't check if the collection was modified. That's by design due to high performance hit of the check. That should be fine in most use-cases. If you need to check for modifications, you're welcomed to use `.GetVersionedEnumerator()` / `IRecyclableVersionedXxxList<T>` type-casting, e.g. in `foreach` loops.
```csharp
foreach (var item in (IRecyclableVersionedList<long>)recyclableList)
{
...
...
...
}
foreach (var item in (IRecyclableVersionedLongList<long>)recyclableLongList)
{
...
...
...
}
```
* ⚠️ The state of the default enumerators before the first & after the last call to `.MoveNext()` is undefined, but no exception is raised. That's by design due to high performance hit of the checks. This behavior is compatible with all `foreach` loop, which will never access `.Current` property
* when the collection is empty, or
* when `.MoveNext()` returned `false`, after reaching the end of the collection.
* ⚠️ If you decide to use `.GetEnumerator()` / `.GetVersionedEnumerator()`, instead of relying on `foreach` loops
* you MUST ensure that you always respect the the result of `.MoveNext()` call, and
* you MUST NEVER access `.Current` property before calling `.MoveNext()` or after reaching the end of the collection.
**Failing to do so WILL result in unpredictable behavior.**
## `RecyclableList<T>`
* Range: `int`
* Interfaces: `IList<T>`, `IEnumerable<T>`, `IDisposable`
@@ -60,7 +60,7 @@
public void RecyclableList_VersionedForEach()
{
foreach (var item in (IVersionedList<long>)TestObjectsAsRecyclableList)
foreach (var item in (IRecyclableVersionedList<long>)TestObjectsAsRecyclableList)
{
DoNothing(item);
}
@@ -76,7 +76,7 @@
public void RecyclableLongList_VersionedForEach()
{
foreach (var item in (IVersionedLongList<long>)TestObjectsAsRecyclableLongList)
foreach (var item in (IRecyclableVersionedLongList<long>)TestObjectsAsRecyclableLongList)
{
DoNothing(item);
}
@@ -1,6 +1,6 @@
namespace Recyclable.Collections
{
public interface IVersionedList<T> : IEnumerable<T>
public interface IRecyclableVersionedList<T> : IEnumerable<T>
{
new RecyclableList<T>.VersionedEnumerator GetEnumerator();
}
@@ -1,6 +1,6 @@
namespace Recyclable.Collections
{
public interface IVersionedLongList<T> : IEnumerable<T>
public interface IRecyclableVersionedLongList<T> : IEnumerable<T>
{
new RecyclableLongList<T>.VersionedEnumerator GetEnumerator();
}
@@ -4,9 +4,9 @@ using System.Runtime.InteropServices;
namespace Recyclable.Collections
{
public partial class RecyclableList<T> : IVersionedList<T>
public partial class RecyclableList<T> : IRecyclableVersionedList<T>
{
VersionedEnumerator IVersionedList<T>.GetEnumerator() => new(this);
VersionedEnumerator IRecyclableVersionedList<T>.GetEnumerator() => new(this);
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct VersionedEnumerator : IEnumerator<T>
@@ -4,10 +4,10 @@ using System.Diagnostics.Contracts;
namespace Recyclable.Collections
{
public partial class RecyclableLongList<T> : IVersionedLongList<T>
public partial class RecyclableLongList<T> : IRecyclableVersionedLongList<T>
{
public VersionedEnumerator GetVersionedEnumerator() => new(this);
VersionedEnumerator IVersionedLongList<T>.GetEnumerator() => new(this);
VersionedEnumerator IRecyclableVersionedLongList<T>.GetEnumerator() => new(this);
public struct VersionedEnumerator : IEnumerator<T>
{
@@ -560,7 +560,7 @@ namespace Recyclable.CollectionsTests
// Act
var yieldedItems = new List<long>((int)itemsCount);
foreach (var item in (IVersionedList<long>)list)
foreach (var item in (IRecyclableVersionedList<long>)list)
{
yieldedItems.Add(item);
}
@@ -407,7 +407,7 @@ namespace Recyclable.CollectionsTests
// Act
var actual = new List<long>();
foreach(var item in (IVersionedLongList<long>)list)
foreach(var item in (IRecyclableVersionedLongList<long>)list)
{
actual.Add(item);
}