java.lang.Object
dev.civl.mc.util.IF.SeqSet.Node
- Enclosing class:
SeqSet
A node in the tree representation. Each node represents a single integer.
A minimal element of the set corresponds to a path in the tree from the
root to a leaf node.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) SeqSet.Node[]The children nodes.The set consisting of the indexes of the children of this node.(package private) intThe index of this node in the parent's list of children.(package private) SeqSet.NodeThe parent node in the tree, or null if this is the root. -
Constructor Summary
ConstructorsConstructorDescriptionNode(SeqSet.Node parent, int index) Creates new node with given index, empty set of childrenIndexes. -
Method Summary
Modifier and TypeMethodDescription(package private) voidclear()EmptieschildrenIndexes.(package private) booleanhasChild(int index) Does this node have a child with the given index?(package private) booleanisLeaf()Is this node a leaf node? A node is a leaf iff it has 0 children.iterator()Returns a new iterator overchildrenIndexes.(package private) booleansetChild(int index) If this node already contains the child at index, does nothing and returnsfalse.toString()
-
Field Details
-
parent
SeqSet.Node parentThe parent node in the tree, or null if this is the root. -
index
int indexThe index of this node in the parent's list of children. If this is the root node (the only node with no parent), -1. -
childrenIndexes
The set consisting of the indexes of the children of this node. -
children
SeqSet.Node[] childrenThe children nodes. If i is in childrenIndexes, then children[i] will be a non-null Node with index i and is considered "active". Otherwise, children[i] may or may not be null; if not null, the child is considered "inactive". An inactive child can be reactivated at some future point when this set changes. This is an optimization---it should be functionally equivalent but faster than setting children[i] to null and creating a new Node.
-
-
Constructor Details
-
Node
Node(SeqSet.Node parent, int index) Creates new node with given index, empty set of childrenIndexes.- Parameters:
parent- the parent node or null if the new node will be a rootindex- the index for the new node: should be -1 for a root, and nonnegative for any other node---the index of this new node in its parent
-
-
Method Details
-
hasChild
boolean hasChild(int index) Does this node have a child with the given index?- Parameters:
index- a nonnegative integer- Returns:
trueiff this node has a child with that index
-
isLeaf
boolean isLeaf()Is this node a leaf node? A node is a leaf iff it has 0 children.- Returns:
trueiff this is a leaf node
-
setChild
boolean setChild(int index) If this node already contains the child at index, does nothing and returnsfalse. Otherwise, the node is created or reactivated and cleared, and the child index is added to this node'schildrenIndexes.- Parameters:
index- index of child- Returns:
trueiff the child was not already there
-
clear
void clear()EmptieschildrenIndexes. -
iterator
Returns a new iterator overchildrenIndexes.- Returns:
-
toString
-