-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
259 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
NetFabric.DoublyLinkedList.Tests/NetFabric.DoublyLinkedList.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
NetFabric.DoublyLinkedList/DoublyLinkedList'1.WhereForwardEnumeration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using NetFabric.Hyperlinq; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Diagnostics.Contracts; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace NetFabric | ||
{ | ||
public partial class DoublyLinkedList<T> | ||
{ | ||
public readonly struct WhereForwardEnumeration | ||
: IValueEnumerable<T, WhereForwardEnumeration.DisposableEnumerator> | ||
{ | ||
readonly DoublyLinkedList<T> list; | ||
readonly Func<T, bool> predicate; | ||
|
||
internal WhereForwardEnumeration(DoublyLinkedList<T> list, Func<T, bool> predicate) | ||
{ | ||
this.list = list; | ||
this.predicate = predicate; | ||
} | ||
|
||
[Pure] | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public Enumerator GetEnumerator() => | ||
new(list, predicate); | ||
|
||
DisposableEnumerator IValueEnumerable<T, WhereForwardEnumeration.DisposableEnumerator>.GetEnumerator() => | ||
new(list, predicate); | ||
|
||
IEnumerator<T> IEnumerable<T>.GetEnumerator() => | ||
new DisposableEnumerator(list, predicate); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => | ||
new DisposableEnumerator(list, predicate); | ||
|
||
public struct Enumerator | ||
{ | ||
readonly DoublyLinkedList<T> list; | ||
readonly Func<T, bool> predicate; | ||
readonly int version; | ||
Node? current; | ||
|
||
internal Enumerator(DoublyLinkedList<T> list, Func<T, bool> predicate) | ||
{ | ||
this.list = list; | ||
this.predicate = predicate; | ||
version = list.version; | ||
current = null; | ||
} | ||
|
||
public readonly T Current | ||
=> current!.Value; | ||
|
||
public bool MoveNext() | ||
{ | ||
if (version != list.version) | ||
Throw.InvalidOperationException(); | ||
do | ||
{ | ||
current = current is null | ||
? list.First | ||
: current.Next; | ||
} | ||
while (current is not null && !predicate(current.Value)); | ||
return current is not null; | ||
} | ||
} | ||
|
||
public struct DisposableEnumerator | ||
: IEnumerator<T> | ||
{ | ||
readonly DoublyLinkedList<T> list; | ||
readonly Func<T, bool> predicate; | ||
readonly int version; | ||
Node? current; | ||
|
||
internal DisposableEnumerator(DoublyLinkedList<T> list, Func<T, bool> predicate) | ||
{ | ||
this.list = list; | ||
this.predicate = predicate; | ||
version = list.version; | ||
current = null; | ||
} | ||
|
||
public readonly T Current | ||
=> current!.Value; | ||
readonly object? IEnumerator.Current | ||
=> current!.Value; | ||
|
||
public bool MoveNext() | ||
{ | ||
if (version != list.version) | ||
Throw.InvalidOperationException(); | ||
do | ||
{ | ||
current = current is null | ||
? list.First | ||
: current.Next; | ||
} | ||
while (current is not null && !predicate(current.Value)); | ||
return current is not null; | ||
} | ||
|
||
public void Reset() | ||
=> current = null; | ||
|
||
public readonly void Dispose() | ||
{ } | ||
} | ||
} | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
NetFabric.DoublyLinkedList/DoublyLinkedList'1.WhereReverseEnumeration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using NetFabric.Hyperlinq; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Diagnostics.Contracts; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace NetFabric | ||
{ | ||
public partial class DoublyLinkedList<T> | ||
{ | ||
public readonly struct WhereReverseEnumeration | ||
: IValueEnumerable<T, WhereReverseEnumeration.DisposableEnumerator> | ||
{ | ||
readonly DoublyLinkedList<T> list; | ||
readonly Func<T, bool> predicate; | ||
|
||
internal WhereReverseEnumeration(DoublyLinkedList<T> list, Func<T, bool> predicate) | ||
{ | ||
this.list = list; | ||
this.predicate = predicate; | ||
} | ||
|
||
[Pure] | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public Enumerator GetEnumerator() => | ||
new(list, predicate); | ||
|
||
DisposableEnumerator IValueEnumerable<T, WhereReverseEnumeration.DisposableEnumerator>.GetEnumerator() => | ||
new(list, predicate); | ||
|
||
IEnumerator<T> IEnumerable<T>.GetEnumerator() => | ||
new DisposableEnumerator(list, predicate); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => | ||
new DisposableEnumerator(list, predicate); | ||
|
||
public struct Enumerator | ||
{ | ||
readonly DoublyLinkedList<T> list; | ||
readonly Func<T, bool> predicate; | ||
readonly int version; | ||
Node? current; | ||
|
||
internal Enumerator(DoublyLinkedList<T> list, Func<T, bool> predicate) | ||
{ | ||
this.list = list; | ||
this.predicate = predicate; | ||
version = list.version; | ||
current = null; | ||
} | ||
|
||
public readonly T Current | ||
=> current!.Value; | ||
|
||
public bool MoveNext() | ||
{ | ||
if (version != list.version) | ||
Throw.InvalidOperationException(); | ||
do | ||
{ | ||
current = current is null | ||
? list.Last | ||
: current.Previous; | ||
} | ||
while (current is not null && !predicate(current.Value)); | ||
return current is not null; | ||
} | ||
} | ||
|
||
public struct DisposableEnumerator | ||
: IEnumerator<T> | ||
{ | ||
readonly DoublyLinkedList<T> list; | ||
readonly Func<T, bool> predicate; | ||
readonly int version; | ||
Node? current; | ||
|
||
internal DisposableEnumerator(DoublyLinkedList<T> list, Func<T, bool> predicate) | ||
{ | ||
this.list = list; | ||
this.predicate = predicate; | ||
version = list.version; | ||
current = null; | ||
} | ||
|
||
public readonly T Current | ||
=> current!.Value; | ||
readonly object? IEnumerator.Current | ||
=> current!.Value; | ||
|
||
public bool MoveNext() | ||
{ | ||
if (version != list.version) | ||
Throw.InvalidOperationException(); | ||
do | ||
{ | ||
current = current is null | ||
? list.Last | ||
: current.Previous; | ||
} | ||
while (current is not null && !predicate(current.Value)); | ||
return current is not null; | ||
} | ||
|
||
public void Reset() | ||
=> current = null; | ||
|
||
public readonly void Dispose() | ||
{ } | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters