Class RowTree
Object
RowTree
- Direct Known Subclasses:
IndexedRowTree
RowTree is another representation of the Forest concept. It is implemented as a tree structure and is an alternative to ArrayForest when it comes to manipulating the forest.
RowTree is far more heavy on memory and GC - each row is a separate object + 52 bytes of payload. However, it is very fast with the modification operations.
Suggested use:
- Do not use for long-term forest storage!
- Do not use when ArrayForest is sufficient for the modifications you need.
- Do not use when you can arrange the modifications you need in a bulk array-creation fashion.
- DO use as a temporary object when you need a (potentially big) number of random changes with a forest and none of the above applies.
Additional concepts and terms:
- Super-root is the "hidden" node that all root nodes are children of.
- There's no concept of depth! Depth can be calculated by going up the parent chain, if needed. But it shouldn't be needed.
- Flags field lets you store temporary bitmask data in each node to help your algorithms. Semantics is up to you.
Note that this class does not check invariants (like uniqueness of row IDs).
Not thread-safe.
This method does not and should not implement Forest because it does not provide indexed access.
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidappendForest(Forest forest) Appends forest to the end of the tree.voidappendForest(Forest forest, RowTree.Node underNode, RowTree.Node afterNode) Appends forest at the specified place.intappendForest(Forest forest, RowTree.Node parentNode, RowTree.Node afterNode, int parentIndex, int flags, LongPredicate rowFilter) Generic utility method for adding the forest to the RowTree, with parameters for optimization.protected RowTree.NodecreateNode(long rowId, int flags) Called always to create a new node for insertion in this tree.protected voidforgetNode(RowTree.Node node) Called always when a node is removed (with its sub-nodes).insertNode(long rowId, int flags, RowTree.Node parentNode, RowTree.Node afterNode) Adds a node to the tree at the specified position.moveNode(RowTree.Node node, RowTree.Node parentNode, RowTree.Node afterNode) Moves node within a treevoidremove(RowTree.Node node) Removes node and its sub-tree from the tree.toForest()CreatesForestrepresenting this RowTree.toString()
-
Constructor Details
-
RowTree
public RowTree()
-
-
Method Details
-
getSuperRoot
-
toString
-
appendForest
Appends forest to the end of the tree. Forest roots also become roots in the RowTree.- Parameters:
forest- the forest
-
appendForest
public void appendForest(@NotNull Forest forest, @NotNull RowTree.Node underNode, @Nullable RowTree.Node afterNode) Appends forest at the specified place.- Parameters:
forest- the forestunderNode- the would-be parentafterNode- the would-be preceding sibling, or null if the inserted nodes should come first underunderNode
-
appendForest
public int appendForest(@NotNull Forest forest, @NotNull RowTree.Node parentNode, @Nullable RowTree.Node afterNode, int parentIndex, int flags, @Nullable LongPredicate rowFilter) Generic utility method for adding the forest to the RowTree, with parameters for optimization.- Parameters:
forest- the source forestparentNode- the would-be parentafterNode- the would-be preceding sibling, or null if the inserted nodes should come first underunderNodeparentIndex- the index of the source row inforest- only children of of that row and their sub-trees are added (the row itself is not added); use -1 to insert the whole forestflags- initial flags for all created nodesrowFilter- when not null, each node is tested with this predicate; failed nodes and their sub-trees are skipped (even if some row in the sub-tree passes the filter)- Returns:
- the index in the forest where iteration stopped (subtreeEnd for the parentNode)
-
insertNode
public RowTree.Node insertNode(long rowId, int flags, RowTree.Node parentNode, RowTree.Node afterNode) Adds a node to the tree at the specified position.- Parameters:
rowId- row IDparentNode- the would-be parentafterNode- the would-be preceding sibling, or null if the inserted nodes should come first underunderNodeflags- initial flags for all created nodes- Returns:
- inserted node
-
moveNode
Moves node within a tree- Parameters:
node- node to moveparentNode- the would-be parentafterNode- the would-be preceding sibling, or null if the inserted nodes should come first underunderNode- Returns:
- node
-
remove
Removes node and its sub-tree from the tree.- Parameters:
node- node
-
toForest
CreatesForestrepresenting this RowTree.- Returns:
- ArrayForest
-
createNode
Called always to create a new node for insertion in this tree. Intended to be overridden with additional checks and maintaining state. -
forgetNode
Called always when a node is removed (with its sub-nodes). Not called for sub-nodes explicitly. Intended to be overridden with additional checks and maintaining state.
-