Context: Andreas (above) asked the OP about the "exotic" nature of his proposed data-structure. The OP replied: "I know it's really bad, and I'm trying to abstract it a bit because it is really hard to work with."
As best as I can understand it, the OP is using this data-structure:
Dictionary<
string,
HashSet<
Dictionary<
string,
HashSet<string>>>>
I think it's useful to try and approach improving a data-structure like this by considering how it would "map" to Classes:
I'd start by defining the nested data-elements from "outermost to innermost:"
public class OuterD : Dictionary<string, InnerH>
{
public static StringBuilder sb = new StringBuilder();
public override string ToString()
{
sb.Clear();
sb.AppendLine("Outer Dictionary:");
foreach (var kvp in this)
{
sb.Append("\tKey: ");
sb.AppendLine(kvp.Key);
sb.Append("\tValue: ");
sb.Append(kvp.Value.ToString());
sb.AppendLine();
}
return sb.ToString();
}
}
public class InnerH : HashSet<InnerD>
{
public override string ToString()
{
OuterD.sb.AppendLine("\t\tHashSet of Outer Dictionary Value Value:");
foreach (var hshval in this)
{
}
return "";
}
}
public class InnerD : Dictionary<string,HashSet<string>>
{
public override string ToString()
{
OuterD.sb.AppendLine("\t\t\tInner Dictionary of Inner HashSet:");
foreach (var kvp in this)
{
OuterD.sb.Append("\t\t\tKey: ");
OuterD.sb.AppendLine(kvp.Key);
foreach (var hsh in kvp.Value)
{
}
}
return "";
}
}
What "jumps out" at me looking at the data-structure from this "point-of-view" is that you've got two "levels" of hashing going on here: why do you need two; why can't you just use a Dictionary<string, string> for the innermost Dictionary, and only Hash the Dictionary itself ?
I hope you can see who the task of printing ... if by "printing" you mean rendering the current state of the data-structure into one string ... can be done by overloading 'ToString() in each of the Classes and then essentially "chaining" their calls, while providing a 'static StringBuilder to use to hold the assembling string.