PowTrees 0.1.2
dotnet add package PowTrees --version 0.1.2
NuGet\Install-Package PowTrees -Version 0.1.2
<PackageReference Include="PowTrees" Version="0.1.2" />
paket add PowTrees --version 0.1.2
#r "nuget: PowTrees, 0.1.2"
// Install PowTrees as a Cake Addin #addin nuget:?package=PowTrees&version=0.1.2 // Install PowTrees as a Cake Tool #tool nuget:?package=PowTrees&version=0.1.2
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 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
-
net6.0
- PowBasics (>= 0.2.1)
- PowBasics.Geom (>= 0.2.1)
-
net8.0
- PowBasics (>= 0.2.1)
- PowBasics.Geom (>= 0.2.1)
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.1.2 | 109 | 6/30/2024 |
0.1.1 | 116 | 6/30/2024 |
0.1.0 | 104 | 6/30/2024 |
0.0.48 | 187 | 9/15/2023 |
0.0.47 | 141 | 9/3/2023 |
0.0.46 | 154 | 8/23/2023 |
0.0.45 | 146 | 8/22/2023 |
0.0.44 | 307 | 8/5/2023 |
0.0.43 | 160 | 7/30/2023 |
0.0.42 | 139 | 7/18/2023 |
0.0.41 | 152 | 7/15/2023 |
0.0.40 | 162 | 7/15/2023 |
0.0.39 | 156 | 7/12/2023 |
0.0.38 | 168 | 7/12/2023 |
0.0.37 | 152 | 7/11/2023 |
0.0.36 | 158 | 7/10/2023 |
0.0.35 | 147 | 7/10/2023 |
0.0.34 | 151 | 7/9/2023 |
0.0.33 | 143 | 7/8/2023 |
0.0.32 | 150 | 7/5/2023 |
0.0.31 | 146 | 7/5/2023 |
0.0.30 | 159 | 7/5/2023 |
0.0.29 | 140 | 7/4/2023 |
0.0.28 | 154 | 7/2/2023 |
0.0.27 | 149 | 6/21/2023 |
0.0.26 | 135 | 6/20/2023 |
0.0.25 | 130 | 6/20/2023 |
0.0.24 | 136 | 6/15/2023 |
0.0.23 | 139 | 6/15/2023 |
0.0.22 | 148 | 6/15/2023 |
0.0.21 | 151 | 6/12/2023 |
0.0.20 | 148 | 6/12/2023 |
0.0.19 | 190 | 6/5/2023 |
0.0.18 | 134 | 6/3/2023 |
0.0.17 | 119 | 6/3/2023 |
0.0.16 | 135 | 6/1/2023 |
0.0.15 | 129 | 5/31/2023 |
0.0.14 | 161 | 5/28/2023 |
0.0.13 | 193 | 5/28/2023 |
0.0.12 | 123 | 5/12/2023 |
0.0.10 | 201 | 4/24/2023 |
0.0.9 | 162 | 4/24/2023 |
0.0.8 | 320 | 12/4/2022 |
0.0.7 | 310 | 11/26/2022 |
0.0.6 | 330 | 11/26/2022 |
0.0.5 | 330 | 11/15/2022 |
0.0.4 | 319 | 11/15/2022 |
0.0.2 | 352 | 9/6/2022 |