use of com.baidu.hugegraph.computer.core.io.BytesOutput in project hugegraph-computer by hugegraph.
the class SorterTestUtil method writeSubKvMapToOutput.
public static BytesOutput writeSubKvMapToOutput(List<List<Integer>> data) throws IOException {
BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
for (List<Integer> entry : data) {
Integer key = entry.get(0);
// Write key
writeData(output, key);
// Write subKv
long position = output.position();
int count = 0;
// Write value length placeholder
output.writeFixedInt(0);
// Write subKv count placeholder
output.writeFixedInt(0);
for (int i = 1; i < entry.size(); ) {
Integer subKey = entry.get(i++);
Integer subValue = entry.get(i++);
writeData(output, subKey);
writeData(output, subValue);
count++;
}
long currentPosition = output.position();
output.seek(position);
output.writeFixedInt((int) (currentPosition - position - 4));
output.writeFixedInt(count);
output.seek(currentPosition);
}
return output;
}
use of com.baidu.hugegraph.computer.core.io.BytesOutput in project hugegraph-computer by hugegraph.
the class EntryOutputTest method inputFromEntries.
private static BytesInput inputFromEntries(List<Integer> entries, boolean needSort) throws IOException {
/*
* All integer data will convert to Id type, so upper layer also
* needs to use the Id type to make a judgment
*/
List<Id> data = intListToLongIds(entries);
BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
EntryOutput entryOutput = new EntryOutputImpl(output, needSort);
int index = 0;
KvEntryWriter entry1 = entryOutput.writeEntry(data.get(index++));
entry1.writeSubKv(data.get(index++), data.get(index++));
entry1.writeSubKv(data.get(index++), data.get(index++));
entry1.writeSubKv(data.get(index++), data.get(index++));
entry1.writeFinish();
KvEntryWriter entry2 = entryOutput.writeEntry(data.get(index++));
entry2.writeSubKv(data.get(index++), data.get(index++));
entry2.writeSubKv(data.get(index++), data.get(index));
entry2.writeFinish();
return EntriesUtil.inputFromOutput(output);
}
use of com.baidu.hugegraph.computer.core.io.BytesOutput in project hugegraph-computer by hugegraph.
the class EntryOutputTest method testWriteKvEntry.
@Test
public void testWriteKvEntry() throws Exception {
List<Integer> entries = ImmutableList.of(1, 5, 6, 6, 2, 1, 4, 8);
List<Id> data = intListToLongIds(entries);
BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
EntryOutput entryOutput = new EntryOutputImpl(output);
for (int i = 0; i < data.size(); ) {
Id id = data.get(i++);
Writable value = data.get(i++);
entryOutput.writeEntry(id, value);
}
// Assert result
BytesInput input = EntriesUtil.inputFromOutput(output);
EntryIterator iter = new KvEntriesInput(input);
SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(1), BytesId.of(5));
SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(6), BytesId.of(6));
SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(2), BytesId.of(1));
SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(4), BytesId.of(8));
iter.close();
}
use of com.baidu.hugegraph.computer.core.io.BytesOutput in project hugegraph-computer by hugegraph.
the class ComputeManagerTest method writeEdges.
private static byte[] writeEdges(Vertex vertex, EdgeFrequency freq) throws IOException {
BytesOutput bytesOutput = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
EntryOutput entryOutput = new EntryOutputImpl(bytesOutput);
GraphComputeOutput output = new StreamGraphOutput(context(), entryOutput);
Whitebox.setInternalState(output, "frequency", freq);
output.writeEdges(vertex);
return bytesOutput.toByteArray();
}
use of com.baidu.hugegraph.computer.core.io.BytesOutput in project hugegraph-computer by hugegraph.
the class EdgesInputTest method writeEdges.
private static byte[] writeEdges(Vertex vertex, EdgeFrequency freq) throws IOException {
BytesOutput bytesOutput = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
EntryOutput entryOutput = new EntryOutputImpl(bytesOutput);
GraphComputeOutput output = new StreamGraphOutput(context(), entryOutput);
Whitebox.setInternalState(output, "frequency", freq);
output.writeEdges(vertex);
return bytesOutput.toByteArray();
}
Aggregations