* Initializes the vertex-data file. Similar process as sharding for edges.
* @param sparse
* @throws IOException
*/
private void processVertexValues(boolean sparse) throws IOException {
DataBlockManager dataBlockManager = new DataBlockManager();
VertexData<VertexValueType> vertexData = new VertexData<VertexValueType>(maxVertexId + 1, baseFilename,
vertexValueTypeBytesToValueConverter, sparse);
vertexData.setBlockManager(dataBlockManager);
for(int p=0; p < numShards; p++) {
int intervalSt = p * finalIdTranslate.getVertexIntervalLength();
int intervalEn = (p + 1) * finalIdTranslate.getVertexIntervalLength() - 1;
if (intervalEn > maxVertexId) intervalEn = maxVertexId;
vertexShovelStreams[p].close();
/* Read shovel and sort */
File shovelFile = new File(vertexShovelFileName(p));
BufferedDataInputStream in = new BufferedDataInputStream(new FileInputStream(shovelFile));
int sizeOf = vertexValueTypeBytesToValueConverter.sizeOf();
long[] vertexIds = new long[(int) (shovelFile.length() / (4 + sizeOf))];
if (vertexIds.length == 0) continue;
byte[] vertexValues = new byte[vertexIds.length * sizeOf];
for(int i=0; i<vertexIds.length; i++) {
int vid = in.readInt();
int transVid = finalIdTranslate.forward(preIdTranslate.backward(vid));
vertexIds[i] = transVid;
in.readFully(vertexValueTemplate);
int valueIdx = i * sizeOf;
System.arraycopy(vertexValueTemplate, 0, vertexValues, valueIdx, sizeOf);
}
/* Sort */
sortWithValues(vertexIds, vertexValues, sizeOf); // The source id is higher order, so sorting the longs will produce right result
int SUBINTERVAL = 2000000;
int iterIdx = 0;
/* Insert into data */
for(int subIntervalSt=intervalSt; subIntervalSt < intervalEn; subIntervalSt += SUBINTERVAL) {
int subIntervalEn = subIntervalSt + SUBINTERVAL - 1;
if (subIntervalEn > intervalEn) subIntervalEn = intervalEn;
int blockId = vertexData.load(subIntervalSt, subIntervalEn);
Iterator<Integer> iterator = vertexData.currentIterator();
while(iterator.hasNext()) {
int curId = iterator.next();
while(iterIdx < vertexIds.length && vertexIds[iterIdx] < curId) {
iterIdx++;
}
if (iterIdx >= vertexIds.length) break;
if (curId == (int) vertexIds[iterIdx]) {
ChiPointer pointer = vertexData.getVertexValuePtr(curId, blockId);
System.arraycopy(vertexValues, iterIdx * sizeOf, vertexValueTemplate, 0, sizeOf);
dataBlockManager.writeValue(pointer, vertexValueTemplate);
} else {
// No vertex data for that vertex.
}
}