VOOZH about

URL: https://www.nuget.org/packages/PowTrees/

⇱ NuGet Gallery | PowTrees 0.2.1




PowTrees 0.2.1

dotnet add package PowTrees --version 0.2.1
 
 
NuGet\Install-Package PowTrees -Version 0.2.1
 
 
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="PowTrees" Version="0.2.1" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PowTrees" Version="0.2.1" />
 
Directory.Packages.props
<PackageReference Include="PowTrees" />
 
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 PowTrees --version 0.2.1
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: PowTrees, 0.2.1"
 
 
#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 PowTrees@0.2.1
 
 
#: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=PowTrees&version=0.2.1
 
Install as a Cake Addin
#tool nuget:?package=PowTrees&version=0.2.1
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

PowTrees

Table of content

Introduction

Tree structure with algorithms

Usage

JSON Serialization

TNod<T> root;

var jsonOpt = new JsonSerializerOptions();
jsonOpt.Converters.Add(NodConverterFactory.Instance);

var str = JsonSerializer.Serialize(root, jsonOpt);
var rootOut = JsonSerializer.Deserialize<TNod<T>>(str, jsonOpt)!;

FoldL

Map a tree recursively. For each node, we use the node and the mapped dad as input

Signature:

static TNod<U> FoldL<T, U>(
	this TNod<T> root,
	Func<TNod<T>, U, U> fun,
	U seed
);

Example:

record Rec(int Val, int Ofs); // where Ofs is an offset we want to apply to Val

// root =
// ┌►(30,0) 
// │ 
// (10,0)──►(20,3)─┤ ┌►(50,0)
// └►(40,6)─┤ 
// └►(60,1)

// 1. Apply Ofs on the node and its descendents:
// ---------------------------------------------
root.FoldL((nod, acc) => acc + nod.V.Ofs, 0)
 ┌►3 
 │ 
0──►3─┤ ┌►9
 └►9─┤ 
 └►10

// 2. Apply Ofs on the node descendents only:
// ------------------------------------------
root.FoldL((nod, acc) => acc + nod.DadOr(e => e.Ofs, 0), 0)
 ┌►3 
 │ 
0──►0─┤ ┌►9
 └►3─┤ 
 └►9

// 3. Create a dictionary from the nodes to their accumulators
// -----------------------------------------------------------
root.Zip(root.FoldL(fun))
	.ToDictionary(
		e => e.First.V,
		e => e.Second.V
	);

As these cases are quite common, there are some utility functions to implement them easily:

static TNod<U> FoldL_Dad<T, U>(
	this TNod<T> root,
	Func<T, U> get,
	Func<U, U, U> fun,
	U seed
);

static IReadOnlyDictionary<T, U> FoldL_Dict<T, U>(
	this TNod<T> root,
	Func<T, U, U> fun,
	U seed
) where T : notnull;

static IReadOnlyDictionary<T, U> FoldL_Dad_Dict<T, U>(
	this TNod<T> root,
	Func<T, U> get,
	Func<U, U, U> fun,
	U seed
) where T : notnull;

Build a node lookup map

If you transform a tree (A) into tree (B) without changing its shape (just changing the node content, not kidren). Very often, you then need to map the nodes of B back to A. For this use:

static IReadOnlyDictionary<TNod<T>, TNod<U>> BuildNodeLookup<T, U>(TNod<T> rootSrc, TNod<U> rootDst);

var lookupMap = TreeUtils.BuildNodeLookup(B, A);

License

MIT

Product Versions Compatible and additional computed target framework versions.
.NET net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 is compatible.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows 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 (5)

Showing the top 5 NuGet packages that depend on PowTrees:

Package Downloads
PowWinForms

WinForms reactive utilities

PowTrees.LINQPad

Tree structure with algorithms

PowLINQPad

Reactive control and utilities for LINQPad

PowWeb

Puppeteer and Chrome DOMSnapshot API wrapper

DynaServeLib

DynaServe

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.1 271 1/17/2025
0.2.0 209 1/17/2025
0.1.2 239 6/30/2024
0.1.1 259 6/30/2024
0.1.0 232 6/30/2024
0.0.48 300 9/15/2023
0.0.47 249 9/3/2023
0.0.46 262 8/23/2023
0.0.45 268 8/22/2023
0.0.44 546 8/5/2023
0.0.43 274 7/30/2023
0.0.42 279 7/18/2023
0.0.41 279 7/15/2023
0.0.40 282 7/15/2023
0.0.39 295 7/12/2023
0.0.38 286 7/12/2023
0.0.37 259 7/11/2023
0.0.36 281 7/10/2023
0.0.35 282 7/10/2023
0.0.34 281 7/9/2023
Loading failed