Package com.phasmidsoftware.gryphon.java
Class WeightedEdge<V,E>
java.lang.Object
com.phasmidsoftware.gryphon.java.Edge<V>
com.phasmidsoftware.gryphon.java.WeightedEdge<V,E>
- Type Parameters:
V- the vertex type.E- the attribute (weight) type.
Represents a weighted edge between two vertices, carrying an attribute of type
E.
Extends Edge<V> with an additional weight (or attribute).
Used wherever edge attributes matter — shortest paths (Dijkstra), minimum
spanning trees (Prim, Kruskal), and any other algorithm that discriminates
between edges by weight.
The attribute type E is intentionally general: it may be
Double for a numeric weight, String for a label,
or any other domain-specific type. Use Void (with null
attribute) to represent an explicitly unweighted edge in a context
that requires the WeightedEdge type.
Edges are immutable. Equality is based on both endpoints and the attribute.
Usage example:
WeightedEdge<String, Double> e = new WeightedEdge<>("A", "B", 3.7);
String from = e.from(); // "A"
String to = e.to(); // "B"
double weight = e.attribute(); // 3.7
WeightedEdge<String, Double> rev = e.reverse(); // WeightedEdge("B", "A", 3.7)
-
Constructor Summary
ConstructorsConstructorDescriptionWeightedEdge(V from, V to, E attribute) Constructs a weighted edge fromfromtotowith the givenattribute. -
Method Summary
Modifier and TypeMethodDescriptionReturns the attribute (weight) of this edge.booleaninthashCode()static <V,E> WeightedEdge <V, E> of(V from, V to, E attribute) Creates a newWeightedEdge.reverse()Returns aWeightedEdgewith the endpoints swapped, preserving the attribute.toString()
-
Constructor Details
-
WeightedEdge
Constructs a weighted edge fromfromtotowith the givenattribute.- Parameters:
from- the source vertex.to- the target vertex.attribute- the edge attribute (weight).
-
-
Method Details
-
of
Creates a newWeightedEdge.- Type Parameters:
V- the vertex type.E- the attribute type.- Parameters:
from- the source vertex.to- the target vertex.attribute- the edge attribute (weight).- Returns:
- a new
WeightedEdge.
-
attribute
Returns the attribute (weight) of this edge.- Returns:
- the edge attribute.
-
reverse
Returns aWeightedEdgewith the endpoints swapped, preserving the attribute. -
equals
-
hashCode
public int hashCode() -
toString
-