public MultiTree() { super(); nodes = new FixedIndexList<MultiNode>(); }
/** * Removes vertex from the list. This checks if the list really contains the * given {@link IndexedElement}. If you are sure that the element is contained in * the list, directly call {@link #remove(int)} using teh index of the element and * avoid the contains check. * * @param v {@link IndexedElement} to remove * @return true if removal was successful */ public boolean remove(N v) { if (!contains(v)) return false; return remove(v.getIndex()) != null; }
/** * Returns the {@link TreeNode} at given index or null of no such node exists. */ public TreeNode getVertex(int index) { return nodes.get(index); }
/** * Create a new {@link Tree} that represents the subtree of this tree rooted at the given * node and removes this subtree from this tree. The returned tree is a new tree that contains the original {@link TreeNode}s of this tree. * <p> * If this tree does not contain the given node, null is returned. * * @param n the root node of the subtree * @return subtree rooted at the given node or null */ public List<TreeNode> removeSubtree(TreeNode n) { if (n == null) throw new NullPointerException(); if (nodes.get(n.getIndex()) != n) { return null; } LinkedList<TreeNode> nodes = new LinkedList<>(); for (TreeNode node : n.depthFirstIterator()) { nodes.push(node); this.nodes.remove(node.getIndex()); } if (n.incompingEdge != null) { n.incompingEdge.getSource().removeEdge(n.incompingEdge); n.incompingEdge = null; } nodes.push(n); this.nodes.remove(n.getIndex()); return nodes; }
/** * Removes {@link TreeNode} with given index. */ public void removeVertex(int index) { TreeNode n = nodes.remove(index); if (n != null) n.clear(); }
/** * Adds a vertex to the list. {@link Vertex} is used as the insertion index * and the call is delegated to @see phylo.tree.model.graph.FixedIndexList#put(int, N). * * @param o the vertex * @return true if vertex was successfully added */ public boolean put(N o) { return put(o.getIndex(), o); }
/** * Returns the maximal index over all nodes */ public int getMaxIndex() { return nodes.getMaximalIndex(); }
public int vertexCount() { return nodes.size(); }
public TypedVertexIterable(EdgeType type) { this.type = type; it = nodes.iterator(); if (it.hasNext()) { while (it.hasNext()) { next = it.next(); if (next.degree(type) > 0) break; } if (next.degree(type) <= 0) next = null; } else { next = null; } }
/** * Returns true if the list contains all nodes in the Collection * * @param c * @return */ public boolean containsAll(Collection<N> c) { for (N object : c) { if (!contains(object)) return false; } return true; }
index = assignNextIndex(); extendArray(index - elements.length + loadFactor); } else {
/** * Removes given {@link TreeNode} from this tree. */ public void removeVertex(TreeNode n) { if (n == null) return; if (nodes.remove(n)) { n.clear(); } }
/** * Adds the given vertex to the set of vertices */ public int addVertex(MultiNode n) { nodes.put(n); return n.getIndex(); }
public int getMaxIndex() { return nodes.getMaximalIndex(); }
/** * Returns the number of vertices */ public int vertexCount() { return nodes.size(); }
public MultiNode getVertex(int index) { return nodes.get(index); }
/** * Removes a vertex and all its edges */ public void removeVertex(MultiNode n) { if (n == null) return; // clear must ensure that all edges of the vertex are removed n.clear(); nodes.remove(n); }
public int addVertex(N n) { nodes.put(n); n.setGraph(this); return n.getIndex(); }
public SimpleGraph() { super(); nodes = new FixedIndexList<N>(10); edgeFactories = new HashMap<EdgeType, EdgeFactory<? extends E, N>>(); //addEdgeFactory((EdgeFactory<? extends E, N>) new DefaultEdgeFactory<N>(EdgeType.UNDIRECTED)); }
public int getMaxIndex() { return nodes.getMaximalIndex(); }