I am currently implementing a 2D Range Tree. I am having trouble coming up with a plausible model (in Java) for my Node class.
A node in the tree may have any of the following: midrange value, right and left child pointer, subtree, data pointer and/or previous and next pointers.
I have broken down the Node into three separate logical pieces
I tried applying Composite and Decorator patterns, but to no avail. I tried making:
It works like that, but I was wandering if there is a nicer way of modeling this as a set of classes?
EDIT: Range Tree (short info): In range trees - all data is stored in the Leaf nodes, and the tree is always balanced. Furthermore all leafs are at the same height. Also, the leaves are sorted, and linked together by a doubly linked list. Last, but not least, each non-leaf node has a subtree - which is also a range tree, but with the leaves sorted on next attribute (say y if original tree was sorted on x).
abstract class AbstractNode {
int midRange;
}
class InnerNode extends AbstractNode {
AbstractNode left;
AbstractNode right;
AbstractNode subtree;
}
class LeafNode extends AbstractNode {
LeafNode next;
LeafNode prev;
Object data;
}