- Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLabeledGraph.java
More file actions
Latest commit
107 lines (92 loc) · 2.84 KB
/
Copy pathLabeledGraph.java
File metadata and controls
107 lines (92 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
packagegraph;
/* See restrictions in Graph.java. */
importjava.util.ArrayList;
/** A Graph whose vertices are labeled with type VL and whose edges are
* labeled with type EL.
* @author P. N. Hilfinger
*/
publicclassLabeledGraph<VL, EL> extendsGraphFilter {
/** A labeling of the graph G. Accessors and modifiers of the graph
* act upon G. Attempts to modify the graph structure directly through
* G have undefined effects upon the labeled version created by this
* constructor. */
publicLabeledGraph(GraphG) {
super(G);
}
/** Returns the label on vertex V, which must be one of my
* vertices. */
publicVLgetLabel(intv) {
checkMyVertex(v);
return_vlabel.get(v);
}
/** Returns the label on the edge (U, V), which must be one of my edges. */
publicELgetLabel(intu, intv) {
inte = edgeId(u, v);
if (e == 0) {
thrownewIllegalArgumentException("no such edge");
}
return_elabel.get(e);
}
/** Set getVertexLabel(V) to LAB, returning V. V must be one of
* my vertices. */
publicintsetLabel(intv, VLlab) {
checkMyVertex(v);
_vlabel.set(v, lab);
returnv;
}
/** Set getEdgeLabel(U, V) to LAB, returning U. (U, V) must be one
* of my edges. */
publicintsetLabel(intu, intv, ELlab) {
inte = edgeId(u, v);
if (e == 0) {
thrownewIllegalArgumentException("no such edge");
}
_elabel.set(e, lab);
returnu;
}
@Override
publicintadd() {
intv = super.add();
while (v >= _vlabel.size()) {
_vlabel.add(null);
}
returnv;
}
@Override
publicintadd(intu, intv) {
super.add(u, v);
inte = edgeId(u, v);
while (e >= _elabel.size()) {
_elabel.add(null);
}
returnu;
}
/** Returns a new vertex labeled LAB, and adds it to me with no
* incident edges. */
publicintadd(VLlab) {
returnsetLabel(add(), lab);
}
/** Adds an edge incident on U and V, labeled with LAB and returns U.
* If I am directed, the edge is directed (leaves U and enters V). */
publicintadd(intu, intv, ELlab) {
add(u, v);
returnsetLabel(u, v, lab);
}
@Override
publicvoidremove(intv) {
super.remove(v);
_vlabel.set(v, null);
}
@Override
publicvoidremove(intu, intv) {
inte = edgeId(u, v);
if (e != 0) {
super.remove(u, v);
_elabel.set(e, null);
}
}
/** Mapping of vertex numbers to vertex labels. */
privatefinalArrayList<VL> _vlabel = newArrayList<>();
/** Mapping of unique edge ids to edge labels. */
privatefinalArrayList<EL> _elabel = newArrayList<>();
}