1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
package org.apache.giraph.edge; |
19 | |
|
20 | |
import java.io.DataInput; |
21 | |
import java.io.DataOutput; |
22 | |
import java.io.IOException; |
23 | |
import java.util.Iterator; |
24 | |
|
25 | |
import javax.annotation.concurrent.NotThreadSafe; |
26 | |
|
27 | |
import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration; |
28 | |
import org.apache.giraph.utils.EdgeIterables; |
29 | |
import org.apache.giraph.utils.Trimmable; |
30 | |
import org.apache.hadoop.io.LongWritable; |
31 | |
import org.apache.hadoop.io.NullWritable; |
32 | |
import org.apache.hadoop.io.Writable; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | @NotThreadSafe |
47 | 0 | public class LongDiffNullArrayEdges |
48 | |
extends ConfigurableOutEdges<LongWritable, NullWritable> |
49 | |
implements ReuseObjectsOutEdges<LongWritable, NullWritable>, |
50 | |
MutableOutEdges<LongWritable, NullWritable>, Trimmable { |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | 0 | private LongDiffArray edges = new LongDiffArray(); |
56 | |
|
57 | |
@Override |
58 | |
public void setConf(ImmutableClassesGiraphConfiguration |
59 | |
<LongWritable, Writable, NullWritable> conf) { |
60 | 0 | super.setConf(conf); |
61 | 0 | edges.setUseUnsafeSerialization(conf.getUseUnsafeSerialization()); |
62 | 0 | } |
63 | |
|
64 | |
@Override |
65 | |
public void initialize( |
66 | |
Iterable<Edge<LongWritable, NullWritable>> edgeIterator |
67 | |
) { |
68 | 0 | edges.initialize(); |
69 | 0 | EdgeIterables.initialize(this, edgeIterator); |
70 | 0 | edges.trim(); |
71 | 0 | } |
72 | |
|
73 | |
@Override |
74 | |
public void initialize(int capacity) { |
75 | 0 | edges.initialize(capacity); |
76 | 0 | } |
77 | |
|
78 | |
@Override |
79 | |
public void initialize() { |
80 | 0 | edges.initialize(); |
81 | 0 | } |
82 | |
|
83 | |
@Override |
84 | |
public void add(Edge<LongWritable, NullWritable> edge) { |
85 | 0 | edges.add(edge.getTargetVertexId().get()); |
86 | 0 | } |
87 | |
|
88 | |
|
89 | |
@Override |
90 | |
public void remove(LongWritable targetVertexId) { |
91 | 0 | edges.remove(targetVertexId.get()); |
92 | 0 | } |
93 | |
|
94 | |
@Override |
95 | |
public int size() { |
96 | 0 | return edges.size(); |
97 | |
} |
98 | |
|
99 | |
@Override |
100 | |
public Iterator<Edge<LongWritable, NullWritable>> iterator() { |
101 | |
|
102 | |
|
103 | |
|
104 | 0 | return (Iterator) mutableIterator(); |
105 | |
} |
106 | |
|
107 | |
@Override |
108 | |
public Iterator<MutableEdge<LongWritable, NullWritable>> mutableIterator() { |
109 | 0 | trim(); |
110 | 0 | return new Iterator<MutableEdge<LongWritable, NullWritable>>() { |
111 | 0 | private final Iterator<LongWritable> reader = edges.iterator(); |
112 | |
|
113 | |
|
114 | 0 | private final MutableEdge<LongWritable, NullWritable> representativeEdge = |
115 | 0 | EdgeFactory.createReusable(new LongWritable()); |
116 | |
|
117 | |
@Override |
118 | |
public boolean hasNext() { |
119 | 0 | return reader.hasNext(); |
120 | |
} |
121 | |
|
122 | |
@Override |
123 | |
public MutableEdge<LongWritable, NullWritable> next() { |
124 | 0 | representativeEdge.getTargetVertexId().set(reader.next().get()); |
125 | 0 | return representativeEdge; |
126 | |
} |
127 | |
|
128 | |
@Override |
129 | |
public void remove() { |
130 | 0 | reader.remove(); |
131 | 0 | } |
132 | |
}; |
133 | |
} |
134 | |
|
135 | |
@Override |
136 | |
public void write(DataOutput out) throws IOException { |
137 | 0 | edges.write(out); |
138 | 0 | } |
139 | |
|
140 | |
@Override |
141 | |
public void readFields(DataInput in) throws IOException { |
142 | 0 | edges.readFields(in); |
143 | 0 | } |
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
@Override |
150 | |
public void trim() { |
151 | 0 | edges.trim(); |
152 | 0 | } |
153 | |
} |