Created
March 25, 2011 23:14
-
-
Save stucchio/887832 to your computer and use it in GitHub Desktop.
A specialized map to save overhead in hadoop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package stylewok.utils.writable; | |
import org.apache.hadoop.io.*; | |
import java.util.*; | |
import java.io.*; | |
public class UUIDToDoubleMapWritable extends HashMap<UUIDWritable,Double> implements Writable { | |
public UUIDToDoubleMapWritable() { } | |
//Implementation of WritableComparable | |
@Override | |
public void write(DataOutput out) throws IOException { | |
out.writeInt(size()); | |
for (UUIDWritable k : keySet()) { | |
k.write(out); | |
out.writeDouble(get(k)); | |
} | |
} | |
@Override | |
public void readFields(DataInput in) throws IOException { | |
clear(); | |
int size = in.readInt(); | |
for (int i=0;i<size;i++) { | |
UUIDWritable k = UUIDWritable.read(in); | |
double v = in.readDouble(); | |
put(k,v); | |
} | |
} | |
public static UUIDToDoubleMapWritable read(DataInput in) throws IOException { | |
UUIDToDoubleMapWritable result = new UUIDToDoubleMapWritable(); | |
result.readFields(in); | |
return result; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment