java - Slow building list of paths -
I am preparing a list of a hash that represents the path to the node path in a tree. My works work but they are incredibly slow in big tree structures - is there a better way? I have tried to create a list in a function, but I find unique shades where I do not want them.
Public Aurelith
Update:
The suggestion of Marcin to make a hash during the tree tree gives a wrong answer, but perhaps I did it?
Public Arrestists & lt; Integer & gt; GetPaths (Abstraction End Lt; String & gt; Tree, Stringbuilder Parent) {ArrayList & lt; Integer & gt; List = New Arrestist & lt; Integer & gt; (); Parent.append ("/"); Parent.append (tree.getNodeName ()); List.add (new stringbilder (original) .toString (.) Hashode ()); If (! Tree.isLeaf ()) {int i = 0; Iterator & LT; AbstractTree & LT; String & gt; & Gt; Baby = tree .get baby (). Iterator (); While (i & lt; tree.get Childen (). Size ()) {list.add all (getPaths (child.next), new stringbuilder (original))); I ++; }} Return list; }
I think your main problem is that you produce duplicate data Are: Every single leaf in the tree, you will make a copy of the entire path above that leaf and calculate the hash for that path. That is, if you have 50,000 cards under a top-level node, then the path name of that node will be copied 50,000 times and its hash is calculated 50,000 times.
If you can organize your data so that the shared path prefix is reused as a reference to the cards and hash calculations for these prefixes, they are cached and reused, You can greatly reduce the actual amount of work.
Comments
Post a Comment