-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
0e3a7a1
commit ec2ee99
Showing
10 changed files
with
168 additions
and
18 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
8 changes: 8 additions & 0 deletions
8
src/Codibre.EnumerableExtensions.Branching/BranchRunOptions.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,8 @@ | ||
| ||
namespace Codibre.EnumerableExtensions.Branching; | ||
|
||
public readonly struct BranchRunOptions(int limit) | ||
{ | ||
public static readonly BranchRunOptions Default = new(ushort.MaxValue / 4); | ||
public int Limit => limit; | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/Codibre.EnumerableExtensions.Branching/Internal/AsyncBranchContext.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,15 @@ | ||
using System.Runtime.CompilerServices; | ||
using System.Xml.XPath; | ||
|
||
namespace Codibre.EnumerableExtensions.Branching.Internal; | ||
|
||
internal sealed record AsyncBranchContext<T>(Func<IBranchContext<T>, ValueTask<LinkedNode<T>?>> GetNext) | ||
: IBranchContext<T> | ||
{ | ||
|
||
public ValueTask<LinkedNode<T>?> FillNext() | ||
{ | ||
var result = GetNext(this); | ||
return result.IsCompleted ? new(Task.Run(() => result.Result)) : result; | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
src/Codibre.EnumerableExtensions.Branching/Internal/IBranchContext.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,9 @@ | ||
using System.Runtime.CompilerServices; | ||
using System.Xml.XPath; | ||
|
||
namespace Codibre.EnumerableExtensions.Branching.Internal; | ||
|
||
internal interface IBranchContext<T> | ||
{ | ||
ValueTask<LinkedNode<T>?> FillNext(); | ||
} |
10 changes: 9 additions & 1 deletion
10
src/Codibre.EnumerableExtensions.Branching/Internal/LinkedNode.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 |
---|---|---|
@@ -1,6 +1,14 @@ | ||
namespace Codibre.EnumerableExtensions.Branching.Internal; | ||
|
||
internal sealed record LinkedNode<T>(T Value, BranchContext<T> Context) | ||
internal sealed record LinkedNode<T>(T Value, IBranchContext<T> Context) | ||
{ | ||
public Lazy<ValueTask<LinkedNode<T>?>> Next { get; } = new(Context.FillNext, LazyThreadSafetyMode.ExecutionAndPublication); | ||
|
||
public static LinkedNode<T> Root(Func<IBranchContext<T>, ValueTask<LinkedNode<T>?>> getNext, BranchRunOptions options) | ||
{ | ||
IBranchContext<T> context = options.Limit <= 1 | ||
? new AsyncBranchContext<T>(getNext) | ||
: new BranchContext<T>(getNext, options); | ||
return new(default!, context); | ||
} | ||
} |
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