@@ -98,9 +98,9 @@ class EdgePartition[
98
98
activeSet)
99
99
}
100
100
101
- def srcIds (i : Int ): VertexId = local2global(localSrcIds(i ))
101
+ private def srcIds (pos : Int ): VertexId = local2global(localSrcIds(pos ))
102
102
103
- def dstIds (i : Int ): VertexId = local2global(localDstIds(i ))
103
+ private def dstIds (pos : Int ): VertexId = local2global(localDstIds(pos ))
104
104
105
105
/** Look up vid in activeSet, throwing an exception if it is None. */
106
106
def isActive (vid : VertexId ): Boolean = {
@@ -231,23 +231,34 @@ class EdgePartition[
231
231
global2local, local2global, vertexAttrs)
232
232
var currSrcId : VertexId = null .asInstanceOf [VertexId ]
233
233
var currDstId : VertexId = null .asInstanceOf [VertexId ]
234
+ var currLocalSrcId = - 1
235
+ var currLocalDstId = - 1
234
236
var currAttr : ED = null .asInstanceOf [ED ]
237
+ // Iterate through the edges, accumulating runs of identical edges using the curr* variables and
238
+ // releasing them to the builder when we see the beginning of the next run
235
239
var i = 0
236
240
while (i < size) {
237
241
if (i > 0 && currSrcId == srcIds(i) && currDstId == dstIds(i)) {
242
+ // This edge should be accumulated into the existing run
238
243
currAttr = merge(currAttr, data(i))
239
244
} else {
245
+ // This edge starts a new run of edges
240
246
if (i > 0 ) {
241
- builder.add(currSrcId, currDstId, localSrcIds(i - 1 ), localDstIds(i - 1 ), currAttr)
247
+ // First release the existing run to the builder
248
+ builder.add(currSrcId, currDstId, currLocalSrcId, currLocalDstId, currAttr)
242
249
}
250
+ // Then start accumulating for a new run
243
251
currSrcId = srcIds(i)
244
252
currDstId = dstIds(i)
253
+ currLocalSrcId = localSrcIds(i)
254
+ currLocalDstId = localDstIds(i)
245
255
currAttr = data(i)
246
256
}
247
257
i += 1
248
258
}
259
+ // Finally, release the last accumulated run
249
260
if (size > 0 ) {
250
- builder.add(currSrcId, currDstId, localSrcIds(i - 1 ), localDstIds(i - 1 ) , currAttr)
261
+ builder.add(currSrcId, currDstId, currLocalSrcId, currLocalDstId , currAttr)
251
262
}
252
263
builder.toEdgePartition.withActiveSet(activeSet)
253
264
}
0 commit comments