Is there a plan to introduce TreeMap pathstep , similar to HashMap
sadaaithal opened this issue · 2 comments
Currently to walk HashMap instances we use the "?entrySet" path step.
Is there one under works for TreeMap instances?
Thanks in advance!
Surprisingly, I never had to deal with TreeMap in practice. TreeMap is nasty due to few subclasses you have to deal with, but otherwise it is not hard to support.
I'll try to find some time to address it.
If you feel like contributing, though, you are welcome.
@alexey-ragozin
In my case, its used a lot for sorted collections all over the place.
I have to read up on the heappath way of iterating Map's but I currently have this hack
`private static Set getTreeMapEntries(Instance treeInstance) {
Set mapEntries = new HashSet(0);
int size = (int) valueOf(treeInstance, "size");
if (size > 0) {
Instance root = valueOf(treeInstance, "root");
extractTreeMapEntries(root, mapEntries);
}
return mapEntries;
}
private static void extractTreeMapEntries(Instance root,
Set mapEntries) {
if (root == null)
return;
mapEntries.add(root);
Instance left = valueOf(root, "left");
extractTreeMapEntries(left, mapEntries);
Instance right = valueOf(root, "right");
extractTreeMapEntries(right, mapEntries);
}`
I suppose something like HeapWalker.walk(instance, "?root");
.