/** * Internal method for setting the root node. * @param root the root node to set */ void setRoot(Node root) { m_root = root.getRow(); }
/** * Get the child index (order number of the child) for the given parent * and child nodes. * @param p the parent Node * @param c the child Node * @return the index of the child, or -1 if the given child node is not * actually a child of the given parent node, or either node is * invalud. */ public int getChildIndex(Node p, Node c) { return getChildIndex(p.getRow(), c.getRow()); }
/** * Get the next sibling of the given node. * @param node a node * @return the next sibling, or null if there is no next sibling */ public Node getNextSibling(Node node) { int n = getNextSiblingRow(node.getRow()); return ( n<0 ? null : getNode(n) ); }
/** * Get a node's parent node * @param n the child node * @return the parent node, or null if there is no parent */ public Node getParent(Node n) { int p = getParent(n.getRow()); return ( p < 0 ? null : getNode(p) ); }
/** * Get the in-degree of a node, the number of edges for which the node * is the target. * @param n the Node instance * @return the in-degree of the node */ public int getInDegree(Node n) { nodeCheck(n, true); return getInDegree(n.getRow()); }
/** * Get the out-degree of a node, the number of edges for which the node * is the source. * @param n the Node instance * @return the out-degree of the node */ public int getOutDegree(Node n) { nodeCheck(n, true); return getOutDegree(n.getRow()); }
/** * Get the degree of a node, the number of edges for which a node * is either the source or the target. * @param n the Node instance * @return the total degree of the node */ public int getDegree(Node n) { nodeCheck(n, true); return getDegree(n.getRow()); }
/** * Get the previous sibling of the given node. * @param node a node * @return the previous sibling, or null if there is no previous sibling */ public Node getPreviousSibling(Node node) { int n = getPreviousSiblingRow(node.getRow()); return ( n<0 ? null : getNode(n) ); }
/** * Get an Edge with given source and target Nodes. There may be times * where there are multiple edges between two nodes; in those cases * this method returns the first such edge found. * @param source the source Node * @param target the target Node * @return an Edge with given source and target nodes, or null if no * such edge is found. */ public Edge getEdge(Node source, Node target) { nodeCheck(source, true); nodeCheck(target, true); return getEdge(getEdge(source.getRow(), target.getRow())); }
/** * Add a child edge between the given nodes. * @param parent the parent node * @param child the child node * @return the added child edge */ public Edge addChildEdge(Node parent, Node child) { nodeCheck(parent, true); nodeCheck(child, true); return getEdge(addChildEdge(parent.getRow(), child.getRow())); }
/** * Remove a node and its entire subtree rooted at the node from the tree. * @param n the node to remove * @return true if the node and its subtree is successfully removed, * false otherwise */ public boolean removeChild(Node n) { nodeCheck(n, true); return removeChild(n.getRow()); }
/** * Get the child node at the given index. * @param node the parent Node * @param idx the child index * @return the child Node */ public Node getChild(Node node, int idx) { int c = getChildRow(node.getRow(), idx); return ( c<0 ? null : getNode(c) ); }
/** * Remove a node from the graph, also removing all incident edges. * @param n the Node to remove from the graph * @return true if the node was successfully removed, false if the * node was not found in this graph */ public boolean removeNode(Node n) { nodeCheck(n, true); return removeNode(n.getRow()); }
/** * Add a child node to the given parent node. An edge between the two * will also be created. * @param parent the parent node * @return the added child node */ public Node addChild(Node parent) { nodeCheck(parent, true); return getNode(addChild(parent.getRow())); }
/** * Get an iterator over all in-linking edges to the given Node. * @param node a Node in the graph * @return an iterator over all in-linking edges to the input target node */ public Iterator inEdges(Node node) { nodeCheck(node, true); return m_edgeTuples.iterator(inEdgeRows(node.getRow())); }
/** * Get an iterator over all Edges connected to the given Node in the graph. * @param node a Node in the graph * @return an iterator over all Edges connected to the input node */ public Iterator edges(Node node) { nodeCheck(node, true); return m_edgeTuples.iterator(edgeRows(node.getRow(), UNDIRECTED)); }
/** * Get the edge to the given node's parent. * @param n a Node instance * @return the parent Edge connecting the given node to its parent */ public Edge getParentEdge(Node n) { nodeCheck(n, true); int pe = getParentEdge(n.getRow()); return ( pe < 0 ? null : getEdge(pe) ); }
/** * Get an iterator over all out-linking edges from the given Node. * @param node a Node in the graph * @return an iterator over all out-linking edges from the input source * node */ public Iterator outEdges(Node node) { nodeCheck(node, true); return m_edgeTuples.iterator(outEdgeRows(node.getRow())); }
/** * Given an Edge and an incident Node, return the other Node * connected to the edge. * @param e an Edge instance * @param n a Node instance. This node must * be connected to the edge * @return the adjacent Node */ public Node getAdjacentNode(Edge e, Node n) { edgeCheck(e, true); nodeCheck(n, true); return getNode(getAdjacentNode(e.getRow(), n.getRow())); }