public class RowTree extends Object
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:
Additional concepts and terms:
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.
RowTree.Node,
IndexedRowTree| Modifier and Type | Class and Description |
|---|---|
static class |
RowTree.Node
Represents a single node or a
RowTree. |
| Constructor and Description |
|---|
RowTree() |
| Modifier and Type | Method and Description |
|---|---|
void |
appendForest(Forest forest)
Appends forest to the end of the tree.
|
void |
appendForest(Forest forest,
RowTree.Node underNode,
RowTree.Node afterNode)
Appends forest at the specified place.
|
int |
appendForest(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.Node |
createNode(long rowId,
int flags)
Called always to create a new node for insertion in this tree.
|
protected void |
forgetNode(RowTree.Node node)
Called always when a node is removed (with its sub-nodes).
|
RowTree.Node |
getSuperRoot() |
RowTree.Node |
insertNode(long rowId,
int flags,
RowTree.Node parentNode,
RowTree.Node afterNode)
Adds a node to the tree at the specified position.
|
RowTree.Node |
moveNode(RowTree.Node node,
RowTree.Node parentNode,
RowTree.Node afterNode)
Moves node within a tree
|
void |
remove(RowTree.Node node)
Removes node and its sub-tree from the tree.
|
ArrayForest |
toForest()
Creates
Forest representing this RowTree. |
String |
toString() |
public RowTree.Node getSuperRoot()
public void appendForest(@NotNull
Forest forest)
forest - the forestpublic void appendForest(@NotNull
Forest forest,
@NotNull
RowTree.Node underNode,
@Nullable
RowTree.Node afterNode)
forest - the forestunderNode - the would-be parentafterNode - the would-be preceding sibling, or null if the inserted nodes should come first under underNodepublic int appendForest(@NotNull
Forest forest,
@NotNull
RowTree.Node parentNode,
@Nullable
RowTree.Node afterNode,
int parentIndex,
int flags,
@Nullable
LongPredicate rowFilter)
forest - the source forestparentNode - the would-be parentafterNode - the would-be preceding sibling, or null if the inserted nodes should come first under underNodeparentIndex - the index of the source row in forest - 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)public RowTree.Node insertNode(long rowId, int flags, RowTree.Node parentNode, RowTree.Node afterNode)
rowId - row IDparentNode - the would-be parentafterNode - the would-be preceding sibling, or null if the inserted nodes should come first under underNodeflags - initial flags for all created nodespublic RowTree.Node moveNode(RowTree.Node node, RowTree.Node parentNode, RowTree.Node afterNode)
node - node to moveparentNode - the would-be parentafterNode - the would-be preceding sibling, or null if the inserted nodes should come first under underNodepublic void remove(RowTree.Node node)
node - nodepublic ArrayForest toForest()
Forest representing this RowTree.protected RowTree.Node createNode(long rowId, int flags)
protected void forgetNode(RowTree.Node node)
Copyright © 2022 ALM Works. All Rights Reserved.