Class FastTree<U>
java.lang.Object
es.uam.eps.ir.relison.graph.fast.AbstractFastGraph<U>
es.uam.eps.ir.relison.graph.tree.fast.FastTree<U>
- Type Parameters:
U
- Type of the nodes of the tree
- All Implemented Interfaces:
DirectedGraph<U>
,FastGraph<U>
,Graph<U>
,Tree<U>
,ReducedIndex<U>
,java.io.Serializable
- Direct Known Subclasses:
FastUnweightedTree
,FastWeightedTree
public abstract class FastTree<U> extends AbstractFastGraph<U> implements Tree<U>
Fast implementation of the tree.
- See Also:
- Serialized Form
-
Field Summary
-
Constructor Summary
Constructors Constructor Description FastTree(DirectedEdges edges)
Constructor. -
Method Summary
Modifier and Type Method Description boolean
addChild(U parent, U child, double weight, int type)
Adds a child to a given node.boolean
addEdge(U nodeA, U nodeB, double weight, int type, boolean insertNodes)
Adds a weighted edge to the graph.boolean
addNode(U node)
Adds a new node to the graph.boolean
addRoot(U root)
Adds a root to the tree.Index<U>
getAdjacencyMatrixMap()
For an adjacency matrix, obtains the mapping between indexes and nodes.java.util.stream.Stream<U>
getChildren(U u)
Obtains the direct children of a node.long
getChildrenCount(U u)
Gets the number of children of a node.java.util.stream.Stream<Weight<U,java.lang.Double>>
getChildrenWeights(U u)
Obtains the weights of the children of a node.java.util.stream.Stream<U>
getLeaves()
Obtain the leaves of the tree.java.util.stream.Stream<U>
getLeaves(U u)
Obtains the leaves of a tree that come from a certain nodejava.util.stream.Stream<U>
getLevel(int level)
Obtains all the nodes in a given level of the tree.java.util.Map<java.lang.Integer,java.util.Set<U>>
getLevels()
Obtains all the nodes on each level.U
getParent(U u)
Obtains the parent of a node.double
getParentWeight(U u)
Obtains the weight of the edge between a node and its parentU
getRoot()
Obtains the root of the graph.boolean
isAscendant(U parent, U child)
Checks if a node is ascendant of another oneboolean
isLeaf(U u)
Indicates if the node is a leaf or not.boolean
isParent(U parent, U child)
Checks if a node is the parent of another one.boolean
isRoot(U u)
Indicates if the node is the root node or not.Methods inherited from class es.uam.eps.ir.relison.graph.fast.AbstractFastGraph
addEdge, complement, containsEdge, containsEdge, containsVertex, getAdjacentEdgesCount, getAdjacentMutualNodesTypes, getAdjacentMutualNodesWeights, getAdjacentNodes, getAdjacentNodesTypes, getAdjacentNodesWeights, getAllNodes, getAllNodesIds, getEdgeCount, getEdgeType, getEdgeWeight, getEdgeWeight, getIncidentEdgesCount, getIncidentMutualNodesTypes, getIncidentMutualNodesWeights, getIncidentNodes, getIncidentNodesTypes, getIncidentNodesWeights, getIndex, getIsolatedNodeIds, getIsolatedNodes, getMutualEdgesCount, getMutualNodes, getMutualNodesTypes, getMutualNodesWeights, getNeighborhood, getNeighborhoodTypes, getNeighborhoodWeights, getNeighbourhood, getNeighbourNodes, getNeighbourNodesTypes, getNeighbourNodesWeights, getNodesIdsWithEdges, getNodesWithAdjacentNeighbors, getNodesWithIncidentNeighbors, getNodesWithMutualNeighbors, getNodesWithNeighbors, getNodesWithNeighbors, getVertexCount, hasAdjacentNeighbors, hasIncidentNeighbors, hasMutualNeighbors, hasNeighbors, idx2object, object2idx, removeEdge, removeNode, updateEdgeType, updateEdgeWeight, updateEdgeWeight
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface es.uam.eps.ir.relison.graph.DirectedGraph
degree, degree, getNeighbourEdgesCount, getNeighbourhood, getNeighbourhoodSize, getNeighbourhoodTypes, getNeighbourhoodWeights, getSinks, getSources, inDegree, isDirected, mutualDegree, outDegree
Methods inherited from interface es.uam.eps.ir.relison.graph.Graph
addEdge, addEdge, addEdge, addEdge, addEdge, complement, containsEdge, containsVertex, getAdjacencyMatrix, getAdjacentEdgesCount, getAdjacentMutualNodesTypes, getAdjacentMutualNodesWeights, getAdjacentNodes, getAdjacentNodesCount, getAdjacentNodesTypes, getAdjacentNodesWeights, getAllNodes, getEdgeCount, getEdgeType, getEdgeWeight, getIncidentEdgesCount, getIncidentMutualNodesTypes, getIncidentMutualNodesWeights, getIncidentNodes, getIncidentNodesCount, getIncidentNodesTypes, getIncidentNodesWeights, getIsolatedNodes, getMutualEdgesCount, getMutualNodes, getMutualNodesCount, getMutualNodesTypes, getMutualNodesWeights, getNeighbourNodes, getNeighbourNodesCount, getNeighbourNodesTypes, getNeighbourNodesWeights, getNodesWithAdjacentNeighbors, getNodesWithIncidentNeighbors, getNodesWithMutualNeighbors, getNodesWithNeighbors, getNodesWithNeighbors, getVertexCount, hasAdjacentNeighbors, hasIncidentNeighbors, hasMutualNeighbors, hasNeighbors, hasNeighbors, isMultigraph, isMutual, isWeighted, removeEdge, removeNode, updateEdgeType, updateEdgeWeight
Methods inherited from interface es.uam.eps.ir.relison.graph.tree.Tree
addChild, addChild, getDescendants, isChild, isDescendant
-
Constructor Details
-
FastTree
Constructor.- Parameters:
edges
- The edges of the tree.
-
-
Method Details
-
getRoot
Description copied from interface:Tree
Obtains the root of the graph. -
getLeaves
Description copied from interface:Tree
Obtain the leaves of the tree. -
getLeaves
Description copied from interface:Tree
Obtains the leaves of a tree that come from a certain node -
getLevel
Description copied from interface:Tree
Obtains all the nodes in a given level of the tree. Root equal to 0. -
getLevels
Description copied from interface:Tree
Obtains all the nodes on each level. -
getChildren
Description copied from interface:Tree
Obtains the direct children of a node.- Specified by:
getChildren
in interfaceTree<U>
- Parameters:
u
- the parent node- Returns:
- A stream containing the children of a node. If it is a leaf, an empty stream is returned. If the node does not exist, null.
-
getChildrenCount
Description copied from interface:Tree
Gets the number of children of a node.- Specified by:
getChildrenCount
in interfaceTree<U>
- Parameters:
u
- the node.- Returns:
- the number of children, -1 if the node does not exist.
-
getParent
Description copied from interface:Tree
Obtains the parent of a node. -
isLeaf
Description copied from interface:Tree
Indicates if the node is a leaf or not. -
isRoot
Description copied from interface:Tree
Indicates if the node is the root node or not. -
addRoot
Description copied from interface:Tree
Adds a root to the tree. -
addChild
Description copied from interface:Tree
Adds a child to a given node. -
isParent
Description copied from interface:Tree
Checks if a node is the parent of another one. -
isAscendant
Description copied from interface:Tree
Checks if a node is ascendant of another one- Specified by:
isAscendant
in interfaceTree<U>
- Parameters:
parent
- the first node (the possible ascendant)child
- the second node (the possible descendant)- Returns:
- true if the second node descends from the first, false if not.
-
addNode
Description copied from interface:Graph
Adds a new node to the graph. -
addEdge
Description copied from interface:Graph
Adds a weighted edge to the graph.- Specified by:
addEdge
in interfaceGraph<U>
- Specified by:
addEdge
in interfaceTree<U>
- Overrides:
addEdge
in classAbstractFastGraph<U>
- Parameters:
nodeA
- The incident node.nodeB
- The adjacent node.weight
- The weight.type
- The edge type.insertNodes
- If true, nodes will be inserted if they do not exist. If false, the edge will only be added if both nodes are inserted.- Returns:
- if the edge is correctly added, false if not.
-
getChildrenWeights
Description copied from interface:Tree
Obtains the weights of the children of a node.- Specified by:
getChildrenWeights
in interfaceTree<U>
- Parameters:
u
- The parent node.- Returns:
- A stream containing the children of the node if it exists, null if not.
-
getParentWeight
Description copied from interface:Tree
Obtains the weight of the edge between a node and its parent- Specified by:
getParentWeight
in interfaceTree<U>
- Parameters:
u
- The child node- Returns:
- The weight if the node exists and it is not the root, NaN otherwise.
-
getAdjacencyMatrixMap
Description copied from interface:Graph
For an adjacency matrix, obtains the mapping between indexes and nodes.- Specified by:
getAdjacencyMatrixMap
in interfaceGraph<U>
- Overrides:
getAdjacencyMatrixMap
in classAbstractFastGraph<U>
- Returns:
- the mapping between indexes and nodes.
-