using System.Collections.Generic;
using System.Text.RegularExpressions;
using Platform.Data.Doublets;
using Platform.Data.Doublets.Memory.United.Generic;
using var links = new UnitedMemoryLinks<uint>("db.links");
var root = links.CreatePoint();
var h_node = links.CreatePoint();
var e_node = links.CreatePoint();
var r_node = links.CreatePoint();
var s_node = links.CreatePoint();
var i_node = links.CreatePoint();
var node_1 = links.CreatePoint();
var node_2 = links.CreatePoint();
var node_3 = links.CreatePoint();
var node_4 = links.CreatePoint();
var root_h_link = links.CreateAndUpdate(root, h_node);
var root_h_e_link = links.CreateAndUpdate(root_h_link, e_node);
var root_h_e_1_link = links.CreateAndUpdate(root_h_e_link, node_1);
var root_h_e_r_link = links.CreateAndUpdate(root_h_e_link, r_node);
var root_h_e_r_s_link = links.CreateAndUpdate(root_h_e_r_link, s_node);
var root_h_e_r_s_4_link = links.CreateAndUpdate(root_h_e_r_s_link, node_4);
var root_h_i_link = links.CreateAndUpdate(root_h_link, i_node);
var root_h_i_s_link = links.CreateAndUpdate(root_h_i_link, s_node);
var root_h_i_s_3_link = links.CreateAndUpdate(root_h_i_s_link, node_3);
var root_s_link = links.CreateAndUpdate(root, s_node);
var root_s_h_link = links.CreateAndUpdate(root_s_link, h_node);
var root_s_h_e_link = links.CreateAndUpdate(root_s_h_link, e_node);
var root_s_h_e_2_link = links.CreateAndUpdate(root_s_h_e_link, node_2);
Func<string, string> replaceAddressesToNames = (sourceString) => {
sourceString = Regex.Replace(sourceString, $@"\b{root}\b", "'root'");
sourceString = Regex.Replace(sourceString, $@"\b{h_node}\b", "'h'");
sourceString = Regex.Replace(sourceString, $@"\b{e_node}\b", "'e'");
sourceString = Regex.Replace(sourceString, $@"\b{r_node}\b", "'r'");
sourceString = Regex.Replace(sourceString, $@"\b{s_node}\b", "'s'");
sourceString = Regex.Replace(sourceString, $@"\b{i_node}\b", "'i'");
sourceString = Regex.Replace(sourceString, $@"\b{node_1}\b", "'1'");
sourceString = Regex.Replace(sourceString, $@"\b{node_2}\b", "'2'");
sourceString = Regex.Replace(sourceString, $@"\b{node_3}\b", "'3'");
sourceString = Regex.Replace(sourceString, $@"\b{node_4}\b", "'4'");
void printChildren(IList<uint> link, int offset) {
var constants = links.Constants;
links.Each((innerLink) => {
if (links.GetIndex(innerLink) == links.GetIndex(link)) {
return constants.Continue;
Console.Write(new string('\t', offset));
Console.WriteLine(replaceAddressesToNames(links.Format(innerLink)));
printChildren(innerLink, offset + 1);
return constants.Continue;
}, new uint[] { constants.Any, links.GetIndex(link), constants.Any });
Console.WriteLine(replaceAddressesToNames(links.Format(root)));
printChildren(links.GetLink(root), 1);