budul.ChainFinder 1.1.0

dotnet add package budul.ChainFinder --version 1.1.0
                    
NuGet\Install-Package budul.ChainFinder -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="budul.ChainFinder" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="budul.ChainFinder" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="budul.ChainFinder" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add budul.ChainFinder --version 1.1.0
                    
#r "nuget: budul.ChainFinder, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package budul.ChainFinder@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=budul.ChainFinder&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=budul.ChainFinder&version=1.1.0
                    
Install as a Cake Tool

ChainFinder

Generic helper library to build chains (connected, ordered paths) from a set of directed elements, for example track segments, links or edges of any graph. Elements are connected by keys: the next key of one element has to match the key of the following element.

Installation

dotnet add package budul.ChainFinder

Usage

using ChainFinder;
using ChainFinder.Settings;

public record Segment(string From, string To);

var segments = new[]
{
    new Segment("A", "B"),
    new Segment("B", "C"),
    new Segment("C", "D"),
};

var finder = new Finder<Segment, string>(
    elements: segments,
    getterKey: s => s.From,
    getterNext: s => s.To,
    // Do not turn around on the same physical segment
    predicateNext: (current, next) => !(current.From == next.To && current.To == next.From),
    preventKeyRevisit: true,
    coverAll: true,
    reduction: ReductionType.None);

foreach (var chain in finder.Find())
{
    // A-B, B-C, C-D
}

Multiple keys per element are supported through the overload with getterKeys and getterNexts.

Options

Parameter Effect
predicateStarter Restricts which elements may start a chain
predicateNext Decides whether next may follow current
predicateChain Decides whether next may extend the current path (read only, the list is shared)
allowEdgeReuse false: an element is used once per starter. true: all simple paths per starter are returned
preventKeyRevisit A chain never starts an element at a key it has already passed (no loops)
coverAll Runs further rounds until every element is part of a chain, rings start at an arbitrary element
sorterNexts Orders the candidates, the first one is explored first
comparer, comparerKeys Custom equality, for example to treat both directions of a segment as one element
reduction None: raw chains. Overlaps: drops chains contained in longer ones. NonOverlaps: cuts chains at elements already used by a longer chain
preferShortest Orders the reduction by shortest instead of longest chain first

Notes

  • The search is a recursive depth first search, the recursion depth equals the chain length.
  • Chains of different starters may share elements unless a reduction is applied.
  • Progress can be reported by passing an IPackage from budul.ProgressWatcher to Find.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 42 10/14/2026
1.0.0 34 10/14/2026