Skip to content
This repository has been archived by the owner on Jan 23, 2022. It is now read-only.

Commit

Permalink
don't flatten table
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinKa committed Nov 18, 2021
1 parent 712666c commit df8ef5b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
Binary file modified Media/RGDViewer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 1 addition & 16 deletions RGDReader/ChunkyFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,9 @@ public KeyValueDataChunk ReadKeyValueDataChunk(int length)

var table = ReadTable();

Dictionary<ulong, (int Type, object Value)> flatTable = new();

void addToFlatTable(Dictionary<ulong, (int Type, object Value)> t)
{
foreach (var (key, tv) in t)
{
flatTable[key] = tv;
if (tv.Type == 100 || tv.Type == 101)
{
addToFlatTable((Dictionary<ulong, (int Type, object Value)>)tv.Value);
}
}
}
addToFlatTable(table);

BaseStream.Position = startPosition + length;

return new KeyValueDataChunk(flatTable);
return new KeyValueDataChunk(table);
}

public KeysDataChunk ReadKeysDataChunk()
Expand Down
31 changes: 21 additions & 10 deletions RGDReaderCLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,29 @@
var keysInv = ChunkyUtil.ReverseReadOnlyDictionary(keys.StringKeys);
var resolved = ChunkyUtil.ResolveKeyValues(keys, kvs);
Console.WriteLine("All key-values");
foreach (var kv in resolved)

void printTable(IReadOnlyDictionary<ulong, (int Type, object Value)> table, int indent = 0)
{
if (kv.Value.HasValue)
foreach (var (childKey, (childType, childValue)) in table)
{
Console.WriteLine(
"{0}: [{1}] <{2}>",
kv.Key,
typeDisplayName[kv.Value.Value.Type],
kv.Value.Value.Value is IReadOnlyDictionary<ulong, (int Type, object Value)> dict ?
string.Join(", ", dict.Keys.Select(key => keysInv.GetValueOrDefault(key, "<Unknown>"))) :
kv.Value.Value.Value
);
printValue(childKey, childType, childValue, indent + 1);
}
}

void printValue(ulong key, int type, object value, int indent = 0)
{
Console.Write(string.Join("", Enumerable.Range(0, indent).Select(_ => " ")));
Console.Write(keysInv.GetValueOrDefault(key, "<Unknown>"));
if (value is IReadOnlyDictionary<ulong, (int Type, object Value)> table)
{
Console.WriteLine(" [Table]");
printTable(table, indent + 1);
}
else
{
Console.WriteLine(" [{0}] <{1}>", typeDisplayName[type], value);
}
}

printTable(kvs.KeyValues);
}

0 comments on commit df8ef5b

Please sign in to comment.