1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.apache.giraph.utils; 20 21 import org.apache.giraph.conf.ImmutableClassesGiraphConfigurable; 22 import org.apache.hadoop.io.Writable; 23 import org.apache.hadoop.io.WritableComparable; 24 25 import java.io.IOException; 26 27 /** 28 * Stores vertex ids and data associated with a vertex 29 * 30 * @param <I> vertexId type parameter 31 * @param <T> vertexData type parameter 32 */ 33 public interface VertexIdData<I extends WritableComparable, T> 34 extends ImmutableClassesGiraphConfigurable, Writable { 35 /** 36 * Create a new data object. 37 * 38 * @return Newly-created data object. 39 */ 40 T createData(); 41 42 /** 43 * Write a data object to an {@link ExtendedDataOutput}. 44 * 45 * @param out {@link ExtendedDataOutput} 46 * @param data Data object to write 47 * @throws IOException 48 */ 49 void writeData(ExtendedDataOutput out, T data) throws IOException; 50 51 /** 52 * Read a data object's fields from an {@link ExtendedDataInput}. 53 * 54 * @param in {@link ExtendedDataInput} 55 * @param data Data object to fill in-place 56 * @throws IOException 57 */ 58 void readData(ExtendedDataInput in, T data) throws IOException; 59 60 /** 61 * Initialize the inner state. Must be called before {@code add()} is 62 * called. 63 */ 64 void initialize(); 65 66 /** 67 * Initialize the inner state, with a known size. Must be called before 68 * {@code add()} is called. 69 * 70 * @param expectedSize Number of bytes to be expected 71 */ 72 void initialize(int expectedSize); 73 74 /** 75 * Add a vertex id and data pair to the collection. 76 * 77 * @param vertexId Vertex id 78 * @param data Data 79 */ 80 void add(I vertexId, T data); 81 82 /** 83 * Add a serialized vertex id and data. 84 * 85 * @param serializedId The bye array which holds the serialized id. 86 * @param idPos The end position of the serialized id in the byte array. 87 * @param data Data 88 */ 89 void add(byte[] serializedId, int idPos, T data); 90 91 /** 92 * Get the number of bytes used. 93 * 94 * @return Bytes used 95 */ 96 int getSize(); 97 98 /** 99 * Get the size of this object in serialized form. 100 * 101 * @return The size (in bytes) of the serialized object 102 */ 103 int getSerializedSize(); 104 105 /** 106 * Check if the list is empty. 107 * 108 * @return Whether the list is empty 109 */ 110 boolean isEmpty(); 111 112 /** 113 * Clear the list. 114 */ 115 void clear(); 116 117 /** 118 * Get an iterator over the pairs. 119 * 120 * @return Iterator 121 */ 122 VertexIdDataIterator<I, T> getVertexIdDataIterator(); 123 }