目前,我正在将普通java代码转换为 MapReduce
上的结构 Hadoop
.
我想修改这个类 Graph
像下面一样,我仍然不知道如何序列化和反序列化 HashMap
以及 float[]
类型。代码部分如下。
代码:
public class Graph implements WritableComparable, Cloneable {
private static long serialVersionUID = 3L;
public static int MAX_FREQUENCY = 3;
public static float[] freqWeight = { 1.0F, 1.6F, 2.0F };
int nNodes;
int nEdges;
String strName;
HashMap<String, Node> nodes;
boolean isMCS;
String taxonomyName;
@Override
public void write(DataOutput out) throws IOException {
// TODO Auto-generated method stub
out.writeBoolean(isMCS);
out.writeInt(nEdges);
out.writeInt(nNodes);
out.writeLong(serialVersionUID);
out.writeInt(MAX_FREQUENCY);
out.writeBytes(strName);
out.writeBytes(taxonomyName);
//ArrayWritable a=new ArrayWritable(FloatWritable.class);
//HashMap
//float[]
}
@Override
public void readFields(DataInput in) throws IOException {
// TODO Auto-generated method stub
isMCS=in.readBoolean();
nEdges=in.readInt();
nNodes=in.readInt();
serialVersionUID=in.readLong();
MAX_FREQUENCY=in.readInt();
strName=in.readLine();
taxonomyName=in.readLine();
//HashMap
//float[]
}
@Override
public int compareTo(Graph graph) {
// TODO Auto-generated method stub
return 0;
}
.........
1条答案
按热度按时间mfpqipee1#
使用arrayprimitivewritable:
对Map使用mapwritable。mapwritable基本上是一个键和值类型都是可写的Map。与ArrayPrimiveWritable类似,mapwritable实现readfiles()和write()方法进行序列化。