Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a plan to introduce TreeMap pathstep , similar to HashMap #6

Open
sadaaithal opened this issue Feb 10, 2021 · 2 comments
Open

Comments

@sadaaithal
Copy link

Currently to walk HashMap instances we use the "?entrySet" path step.
Is there one under works for TreeMap instances?
Thanks in advance!

@alexey-ragozin
Copy link

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.

@sadaaithal
Copy link
Author

sadaaithal commented Feb 10, 2021

@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"); .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants