當前位置: 首頁>>代碼示例>>Java>>正文


Java WritableUtils類代碼示例

本文整理匯總了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();
}
 
開發者ID:renato2099,項目名稱:giraph-gora,代碼行數:17,代碼來源:ByteArrayEdges.java

示例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);
    }
  }
}
 
開發者ID:renato2099,項目名稱:giraph-gora,代碼行數:21,代碼來源:SimplePartition.java

示例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);
  }
}
 
開發者ID:renato2099,項目名稱:giraph-gora,代碼行數:27,代碼來源:VertexMutations.java

示例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);
  }
}
 
開發者ID:renato2099,項目名稱:giraph-gora,代碼行數:18,代碼來源:VertexMutations.java

示例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));
  }
}
 
開發者ID:renato2099,項目名稱:giraph-gora,代碼行數:21,代碼來源:TestIntMatrix.java

示例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);
  }
}
 
開發者ID:renato2099,項目名稱:giraph-gora,代碼行數:21,代碼來源:TestFloatMatrix.java

示例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);
  }
}
 
開發者ID:renato2099,項目名稱:giraph-gora,代碼行數:21,代碼來源:TestDoubleMatrix.java

示例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));
  }
}
 
開發者ID:renato2099,項目名稱:giraph-gora,代碼行數:21,代碼來源:TestLongMatrix.java

示例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);
    }
  }
}
 
開發者ID:zfighter,項目名稱:giraph-research,代碼行數:21,代碼來源:SimplePartition.java

示例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);
  }
}
 
開發者ID:zfighter,項目名稱:giraph-research,代碼行數:27,代碼來源:VertexMutations.java

示例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);
  }
}
 
開發者ID:zfighter,項目名稱:giraph-research,代碼行數:18,代碼來源:VertexMutations.java

示例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;
}
 
開發者ID:renato2099,項目名稱:giraph-gora,代碼行數:16,代碼來源:ByteArrayEdges.java

示例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;
}
 
開發者ID:renato2099,項目名稱:giraph-gora,代碼行數:11,代碼來源:ByteArrayEdges.java

示例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);
  }
}
 
開發者ID:renato2099,項目名稱:giraph-gora,代碼行數:11,代碼來源:ArrayListEdges.java

示例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());
  }
}
 
開發者ID:renato2099,項目名稱:giraph-gora,代碼行數:10,代碼來源:SimplePartition.java


注:本文中的org.apache.giraph.utils.WritableUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。