本文整理汇总了Java中org.apache.giraph.utils.WritableUtils类的典型用法代码示例。如果您正苦于以下问题:Java WritableUtils类的具体用法?Java WritableUtils怎么用?Java WritableUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WritableUtils类属于org.apache.giraph.utils包,在下文中一共展示了WritableUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import org.apache.giraph.utils.WritableUtils; //导入依赖的package包/类
@Override
public void initialize(Iterable<Edge<I, E>> edges) {
ExtendedDataOutput extendedOutputStream =
getConf().createExtendedDataOutput();
for (Edge<I, E> edge : edges) {
try {
WritableUtils.writeEdge(extendedOutputStream, edge);
} catch (IOException e) {
throw new IllegalStateException("initialize: Failed to serialize " +
edge);
}
++edgeCount;
}
serializedEdges = extendedOutputStream.getByteArray();
serializedEdgesBytesUsed = extendedOutputStream.getPos();
}
示例2: readFields
import org.apache.giraph.utils.WritableUtils; //导入依赖的package包/类
@Override
public void readFields(DataInput input) throws IOException {
super.readFields(input);
if (USE_OUT_OF_CORE_MESSAGES.get(getConf())) {
vertexMap = new ConcurrentSkipListMap<I, Vertex<I, V, E>>();
} else {
vertexMap = Maps.newConcurrentMap();
}
int vertices = input.readInt();
for (int i = 0; i < vertices; ++i) {
progress();
Vertex<I, V, E> vertex =
WritableUtils.readVertexFromDataInput(input, getConf());
if (vertexMap.put(vertex.getId(), vertex) != null) {
throw new IllegalStateException(
"readFields: " + this +
" already has same id " + vertex);
}
}
}
示例3: readFields
import org.apache.giraph.utils.WritableUtils; //导入依赖的package包/类
@Override
public void readFields(DataInput input) throws IOException {
addedVertexList.clear();
addedEdgeList.clear();
removedEdgeList.clear();
int addedVertexListSize = input.readInt();
for (int i = 0; i < addedVertexListSize; ++i) {
Vertex<I, V, E> vertex =
WritableUtils.readVertexFromDataInput(input, getConf());
addedVertexList.add(vertex);
}
removedVertexCount = input.readInt();
int addedEdgeListSize = input.readInt();
for (int i = 0; i < addedEdgeListSize; ++i) {
Edge<I, E> edge = conf.createEdge();
WritableUtils.readEdge(input, edge);
addedEdgeList.add(edge);
}
int removedEdgeListSize = input.readInt();
for (int i = 0; i < removedEdgeListSize; ++i) {
I removedEdge = conf.createVertexId();
removedEdge.readFields(input);
removedEdgeList.add(removedEdge);
}
}
示例4: write
import org.apache.giraph.utils.WritableUtils; //导入依赖的package包/类
@Override
public void write(DataOutput output) throws IOException {
output.writeInt(addedVertexList.size());
for (Vertex<I, V, E> vertex : addedVertexList) {
WritableUtils.writeVertexToDataOutput(output, vertex, getConf());
}
output.writeInt(removedVertexCount);
output.writeInt(addedEdgeList.size());
for (Edge<I, E> edge : addedEdgeList) {
edge.getTargetVertexId().write(output);
edge.getValue().write(output);
}
output.writeInt(removedEdgeList.size());
for (I removedEdge : removedEdgeList) {
removedEdge.write(output);
}
}
示例5: testVectorSerialize
import org.apache.giraph.utils.WritableUtils; //导入依赖的package包/类
@Test
public void testVectorSerialize() throws Exception {
int size = 100;
// Serialize from
IntVector from = new IntVector(size);
from.set(0, 10);
from.set(10, 5);
from.set(12, 1);
byte[] data = WritableUtils.writeToByteArray(from);
// De-serialize to
IntVector to = new IntVector();
WritableUtils.readFieldsFromByteArray(data, to);
// The vectors should be equal
for (int i = 0; i < size; ++i) {
assertEquals(from.get(i), to.get(i));
}
}
示例6: testVectorSerialize
import org.apache.giraph.utils.WritableUtils; //导入依赖的package包/类
@Test
public void testVectorSerialize() throws Exception {
int size = 100;
// Serialize from
FloatVector from = new FloatVector(size);
from.set(0, 10.0f);
from.set(10, 5.0f);
from.set(12, 1.0f);
byte[] data = WritableUtils.writeToByteArray(from);
// De-serialize to
FloatVector to = new FloatVector();
WritableUtils.readFieldsFromByteArray(data, to);
// The vectors should be equal
for (int i = 0; i < size; ++i) {
assertEquals(from.get(i), to.get(i), E);
}
}
示例7: testVectorSerialize
import org.apache.giraph.utils.WritableUtils; //导入依赖的package包/类
@Test
public void testVectorSerialize() throws Exception {
int size = 100;
// Serialize from
DoubleVector from = new DoubleVector(size);
from.set(0, 10.0);
from.set(10, 5.0);
from.set(12, 1.0);
byte[] data = WritableUtils.writeToByteArray(from);
// De-serialize to
DoubleVector to = new DoubleVector();
WritableUtils.readFieldsFromByteArray(data, to);
// The vectors should be equal
for (int i = 0; i < size; ++i) {
assertEquals(from.get(i), to.get(i), E);
}
}
示例8: testVectorSerialize
import org.apache.giraph.utils.WritableUtils; //导入依赖的package包/类
@Test
public void testVectorSerialize() throws Exception {
int size = 100;
// Serialize from
LongVector from = new LongVector(size);
from.set(0, 10);
from.set(10, 5);
from.set(12, 1);
byte[] data = WritableUtils.writeToByteArray(from);
// De-serialize to
LongVector to = new LongVector();
WritableUtils.readFieldsFromByteArray(data, to);
// The vectors should be equal
for (int i = 0; i < size; ++i) {
assertEquals(from.get(i), to.get(i));
}
}
示例9: readFields
import org.apache.giraph.utils.WritableUtils; //导入依赖的package包/类
@Override
public void readFields(DataInput input) throws IOException {
super.readFields(input);
if (USE_OUT_OF_CORE_MESSAGES.get(getConf())) {
vertexMap = new ConcurrentSkipListMap<I, Vertex<I, V, E, M>>();
} else {
vertexMap = Maps.newConcurrentMap();
}
int vertices = input.readInt();
for (int i = 0; i < vertices; ++i) {
progress();
Vertex<I, V, E, M> vertex =
WritableUtils.readVertexFromDataInput(input, getConf());
if (vertexMap.put(vertex.getId(), vertex) != null) {
throw new IllegalStateException(
"readFields: " + this +
" already has same id " + vertex);
}
}
}
示例10: readFields
import org.apache.giraph.utils.WritableUtils; //导入依赖的package包/类
@Override
public void readFields(DataInput input) throws IOException {
addedVertexList.clear();
addedEdgeList.clear();
removedEdgeList.clear();
int addedVertexListSize = input.readInt();
for (int i = 0; i < addedVertexListSize; ++i) {
Vertex<I, V, E, M> vertex =
WritableUtils.readVertexFromDataInput(input, getConf());
addedVertexList.add(vertex);
}
removedVertexCount = input.readInt();
int addedEdgeListSize = input.readInt();
for (int i = 0; i < addedEdgeListSize; ++i) {
Edge<I, E> edge = conf.createEdge();
WritableUtils.readEdge(input, edge);
addedEdgeList.add(edge);
}
int removedEdgeListSize = input.readInt();
for (int i = 0; i < removedEdgeListSize; ++i) {
I removedEdge = conf.createVertexId();
removedEdge.readFields(input);
removedEdgeList.add(removedEdge);
}
}
示例11: write
import org.apache.giraph.utils.WritableUtils; //导入依赖的package包/类
@Override
public void write(DataOutput output) throws IOException {
output.writeInt(addedVertexList.size());
for (Vertex<I, V, E, M> vertex : addedVertexList) {
WritableUtils.writeVertexToDataOutput(output, vertex, getConf());
}
output.writeInt(removedVertexCount);
output.writeInt(addedEdgeList.size());
for (Edge<I, E> edge : addedEdgeList) {
edge.getTargetVertexId().write(output);
edge.getValue().write(output);
}
output.writeInt(removedEdgeList.size());
for (I removedEdge : removedEdgeList) {
removedEdge.write(output);
}
}
示例12: add
import org.apache.giraph.utils.WritableUtils; //导入依赖的package包/类
@Override
public void add(Edge<I, E> edge) {
ExtendedDataOutput extendedDataOutput =
getConf().createExtendedDataOutput(
serializedEdges, serializedEdgesBytesUsed);
try {
WritableUtils.writeEdge(extendedDataOutput, edge);
} catch (IOException e) {
throw new IllegalStateException("add: Failed to write to the new " +
"byte array");
}
serializedEdges = extendedDataOutput.getByteArray();
serializedEdgesBytesUsed = extendedDataOutput.getPos();
++edgeCount;
}
示例13: next
import org.apache.giraph.utils.WritableUtils; //导入依赖的package包/类
@Override
public Edge<I, E> next() {
try {
WritableUtils.readEdge(extendedDataInput, representativeEdge);
} catch (IOException e) {
throw new IllegalStateException("next: Failed on pos " +
extendedDataInput.getPos() + " edge " + representativeEdge);
}
return representativeEdge;
}
示例14: readFields
import org.apache.giraph.utils.WritableUtils; //导入依赖的package包/类
@Override
public void readFields(DataInput in) throws IOException {
int numEdges = in.readInt();
initialize(numEdges);
for (int i = 0; i < numEdges; ++i) {
Edge<I, E> edge = getConf().createEdge();
WritableUtils.readEdge(in, edge);
edgeList.add(edge);
}
}
示例15: write
import org.apache.giraph.utils.WritableUtils; //导入依赖的package包/类
@Override
public void write(DataOutput output) throws IOException {
super.write(output);
output.writeInt(vertexMap.size());
for (Vertex<I, V, E> vertex : vertexMap.values()) {
progress();
WritableUtils.writeVertexToDataOutput(output, vertex, getConf());
}
}