mattunderscorechampion / tree-root Goto Github PK
View Code? Open in Web Editor NEWTree collection and utility library
License: Other
Tree collection and utility library
License: Other
Presumable getChildren() returns a mutable collection? Why is removeChild() better than getChildren().remove()?
If its to reduce garbage, it might be better to allow an iterator (IWalker?) to mutate. E.g. remove the current node, alter children, ..
Java 7 public updates end April 2015 so it needs to move to Java 8.
http://www.oracle.com/technetwork/java/javase/eol-135779.html
A little bikeshedding...
The naming of interfaces IFoo is not idiomatic for Java. Please change to Foo.
Please document the design principles behind this API.
Would an isLeaf() convenience method be useful?
Should the selectors and matchers be generic classes or have generic methods? Currently they are generic classes. Can a single selector apply to trees with different element types?
The concurrent modification of path copy trees results in one modification winning out and the others discarded. This is a result of setting the root node to the new path. Only a single path should be copied at a time.
Supporting the selection of subtrees was always intended however with mutable trees it poses a question. Should modifications to the original tree be propagated to any selected subtrees? Initial implementations involved returning the root node of a subtree as the root. This provides O(1) node to tree conversion and is fine for immutable trees but with mutable trees modifications to the original or the subtree are visible in the other tree. I have decided that the mutations to different trees should not be visible in the other.
This means that several existing implementations are broken and the performance of tree selection may be O(n). It does however make it easier to understand and predict the consequences of modifying trees. It also makes it more in line with the possibility of selecting a subtree with different properties to the source tree.
It is possible for a binary trees to have a right node but not a left node. The iterators have been implemented to treat the first node returned by the iterator for the children as the left node. I suspect that the a missing left node would need to be handled by having a null as the placeholder for the left node with the walkers and iterators treating it as a left node but not traversing it
Does ITreeWalker.onEmpty() really pull its weight?
I'd have thought that an ITW that did something useful in onEmpty would naturally be stateful and so adding an additional boolean would be trivial.
Would hasMore() be better?
I'd like to be able to create an internal iterator to print a lisp like tree. Something like:
(root (firstChild secondChild))
The problem is that the walkers do not have callbacks for when walking a node's children. Instead it is presented as a stream of nodes.
There needs to be a way to created sorted trees. These would be related to the balancing trees.
To support sorting algorithms it is necessary to add nodes to specific positions. The initial tree implementation assumed an unordered bag of child nodes.
As support for structural iteration and placement has been added it has undermined the value of returning a collection.
The Node returns a SimpleCollection and says whether or not the Node is a leaf (the collection is empty). The SimpleCollection returns the size and a pair of iterators (one of which was added specifically for structural iteration). The MutableStructuralNode adds methods for adding new nodes in specific places. Methods for accessing and modifying nodes are split and duplicated between the Node and the SimpleCollection.
The SimpleCollection needs to be removed and everything needed placed directly on the node.
See issue #2 for some related problems.
The parent node and tree reference in the path copy tree node implementation makes it difficult to implement certain operations such as getting a subtree. A more flexible implementation needs to be implemented.
The current API does not support polymorphic access to elements - it expects them all to be an E.
Using generics with containers breaks down a little due to Java's limited type model, but I suspect some methods could be relaxed to take INode<? extends E>, and provide INode<? super E>, supporting operations between trees with related but different types.
Also, it would be nice to be able to create an IWalker that is restricted to visiting nodes of type .
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.