Class EdgeSet

All Implemented Interfaces:
Serializable, Cloneable, Iterable<Edge>, Collection<Edge>, Set<Edge>

public class EdgeSet extends HashSet<Edge>
A set of edges in a graph. This is actually an extension of HashSet<Edge>.
Author:
Cristian Frăsinaru
See Also:
  • Field Details

    • graph

      protected Graph graph
  • Constructor Details

    • EdgeSet

      public EdgeSet(Graph graph)
      Constructs a new, empty set of edges.
      Parameters:
      graph - the graph the edges belong to.
    • EdgeSet

      public EdgeSet(Graph graph, int initialCapacity)
      Constructs a new, empty set of edges, with a specified initial capacity.
      Parameters:
      graph - the graph the edges belong to.
      initialCapacity - the initial capacity of this collection.
    • EdgeSet

      public EdgeSet(Graph graph, Collection<Edge> edges)
      Constructs a new set containing the elements in the specified collection.
      Parameters:
      graph - the graph the edges belong to.
      edges - the collection of edges whose elements are to be placed into this set.
    • EdgeSet

      public EdgeSet(Graph graph, Edge[] edges)
      Constructs a new set containing the elements in the specified array.
      Parameters:
      graph - the graph the edges belong to.
      edges - the array of edges whose elements are to be placed into this set.
  • Method Details

    • vertexSet

      public VertexSet vertexSet()
      Returns the vertices representing endpoints of the edges in this collection.
      Returns:
      the vertices representing endpoints of the edges in this collection.
    • add

      public boolean add(int v, int u)
      Adds the edge (v,u) to this set if it is not already present.
      Parameters:
      v - the source endpoint of the edge.
      u - the target endpoint of the edge.
      Returns:
      true if the set did not already contain the specified edge, false otherwise.
    • weight

      public double weight()
      Computes the sum of the weights associated with each edge in the collection.
      Returns:
      the sum of all weights of the edges in the collection, including duplicates.