public class SparseWeightedEdgeSet extends AbstractSet<WeightedEdge> implements EdgeSet<WeightedEdge>, Serializable
WeightedEdge
instances. Note that the equality
condition for WeightedEdge
is treated specially in this set such that
two vertices will only have at most one edge between them. If an edge exists
for vertices i
and j
with weight w
1, then
adding a new edge to the same vertices with weight w
2 will
not add a parallel edge and increase the size of this set, even though the
edges are not equal. Rather, the weight on the edge between the two vertices
is changed to w
2. Similarly, any contains or removal
operation will return its value based on the WeightedEdge
's vertices
but not on the weight of the edge itself.Constructor and Description |
---|
SparseWeightedEdgeSet(int rootVertex)
Creates a new
SparseWeightedEdgeSet where all edges in this set
must connect to rootVertex . |
Modifier and Type | Method and Description |
---|---|
boolean |
add(WeightedEdge e)
Adds the edge to this set if one of the vertices is the root vertex.
|
IntSet |
connected()
Returns the set of vertices connected to the root edges.
|
boolean |
connects(int vertex)
Returns true if the root vertex is connected to the provided vertex.
|
boolean |
contains(Object o) |
SparseWeightedEdgeSet |
copy(IntSet vertices)
Copies the edges in this set that are connected to any of the vertices in
the provided set.
|
int |
disconnect(int vertex)
Removes all edges instances that connect to the specified vertex,
returning the number of edges that were removed, if any.
|
Set<WeightedEdge> |
getEdges(int vertex)
Returns the set of
Edge instances that connect the root vertex
with this vertex or an empty set if no such edges exist. |
int |
getRoot()
Returns the vertex to which all edges in this set are connected.
|
Iterator<WeightedEdge> |
iterator() |
boolean |
remove(Object o) |
int |
size() |
double |
sum()
Returns the sum of the weights of the edges contained in this set.
|
equals, hashCode, removeAll
addAll, clear, containsAll, isEmpty, retainAll, toArray, toArray, toString
public SparseWeightedEdgeSet(int rootVertex)
SparseWeightedEdgeSet
where all edges in this set
must connect to rootVertex
.public boolean add(WeightedEdge e)
add
in interface EdgeSet<WeightedEdge>
add
in interface Collection<WeightedEdge>
add
in interface Set<WeightedEdge>
add
in class AbstractCollection<WeightedEdge>
true
if e was added or if the weight was changed for the
conenction between an existing edge that matchedpublic IntSet connected()
connected
in interface EdgeSet<WeightedEdge>
public boolean connects(int vertex)
connects
in interface EdgeSet<WeightedEdge>
public boolean contains(Object o)
contains
in interface Collection<WeightedEdge>
contains
in interface Set<WeightedEdge>
contains
in class AbstractCollection<WeightedEdge>
public SparseWeightedEdgeSet copy(IntSet vertices)
copy
in interface EdgeSet<WeightedEdge>
public int disconnect(int vertex)
disconnect
in interface EdgeSet<WeightedEdge>
public Set<WeightedEdge> getEdges(int vertex)
Edge
instances that connect the root vertex
with this vertex or an empty set if no such edges exist.getEdges
in interface EdgeSet<WeightedEdge>
public int getRoot()
getRoot
in interface EdgeSet<WeightedEdge>
public Iterator<WeightedEdge> iterator()
iterator
in interface Iterable<WeightedEdge>
iterator
in interface Collection<WeightedEdge>
iterator
in interface Set<WeightedEdge>
iterator
in class AbstractCollection<WeightedEdge>
public boolean remove(Object o)
remove
in interface Collection<WeightedEdge>
remove
in interface Set<WeightedEdge>
remove
in class AbstractCollection<WeightedEdge>
public int size()
size
in interface Collection<WeightedEdge>
size
in interface Set<WeightedEdge>
size
in class AbstractCollection<WeightedEdge>
public double sum()
Copyright © 2012. All Rights Reserved.