Commit 0eed8a42 authored by dangq's avatar dangq

dsaf

parent ceef2947
......@@ -2,101 +2,54 @@ package fr.eurecom.dsg.mapreduce;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
<<<<<<< HEAD
import java.util.Iterator;
import java.util.List;
=======
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
>>>>>>> 8f49318439a759e7c34a55774d8d33aa3a91a874
import java.util.Map.Entry;
import java.util.Set;
import java.util.ArrayList;
import org.apache.hadoop.io.Writable;
/*
* Very simple (and scholastic) implementation of a Writable associative array for String to Int
* Very simple (and scholastic) implementation of a Writable associative array for String to Int
*
**/
public class StringToIntMapWritable implements Writable {
private HashMap<String, Integer> hm = new HashMap<String, Integer>();
// TODO: add an internal field that is the real associative array
private HashMap<String, Integer> hm = new HashMap<String,Integer>();
<<<<<<< HEAD
@Override
public void readFields(DataInput in) throws IOException {
// TODO: implement deserialization
int len =in.readInt();
int len = in.readInt();
hm.clear();
for (int i=0;i<len;i++){
int l=in.readInt();
byte[] ba =new byte[l];
for (int i = 0; i < len; i++) {
int l = in.readInt();
byte[] ba = new byte[l];
in.readFully(ba);
String key=new String(ba);
Integer value=in.readInt();
hm.put(key,value);
}
String key = new String(ba);
Integer value = in.readInt();
hm.put(key, value);
}
public StringToIntMapWritable(){
// TODO: implement deserialization
// Warning: for efficiency reasons, Hadoop attempts to re-use old instances of
// StringToIntMapWritable when reading new records. Remember to initialize your variables
// inside this function, in order to get rid of old data.
}
public StringToIntMapWritable(String key, Integer value){
hm.put(key,value);
}
public List<StringToIntMapWritable> getElements(){
List<StringToIntMapWritable> result = new ArrayList<StringToIntMapWritable>();
for (String key : hm.keySet()) {
result.add(new StringToIntMapWritable(key, hm.get(key)));
}
return result;
}
=======
>>>>>>> 8f49318439a759e7c34a55774d8d33aa3a91a874
public Set<String> getKeySet() {
return hm.keySet();
public StringToIntMapWritable() {
}
<<<<<<< HEAD
public Integer getValue(String key) {
return hm.get(key);
=======
// TODO: implement deserialization
int len =in.readInt();
hm.clear();
for (int i=0;i<len;i++){
int l=in.readInt();
byte[] ba =new byte[l];
in.readFully(ba);
String key=new String(ba);
Integer value=in.readInt();
hm.put(key,value);
}
>>>>>>> 8f49318439a759e7c34a55774d8d33aa3a91a874
public StringToIntMapWritable(String key, Integer value) {
hm.put(key, value);
}
public StringToIntMapWritable(){
<<<<<<< HEAD
=======
}
public StringToIntMapWritable(String key, Integer value){
hm.put(key,value);
}
public List<StringToIntMapWritable> getElements(){
public List<StringToIntMapWritable> getElements() {
List<StringToIntMapWritable> result = new ArrayList<StringToIntMapWritable>();
for (String key : hm.keySet()) {
result.add(new StringToIntMapWritable(key, hm.get(key)));
......@@ -112,31 +65,30 @@ public class StringToIntMapWritable implements Writable {
return hm.get(key);
}
>>>>>>> 8f49318439a759e7c34a55774d8d33aa3a91a874
@Override
public String toString() {
return hm.keySet().iterator().next() + " " + hm.values().iterator().next();
}
// Warning: for efficiency reasons, Hadoop attempts to re-use old instances of
// StringToIntMapWritable when reading new records. Remember to initialize your variables
// inside this function, in order to get rid of old data.
@Override
public void write(DataOutput out) throws IOException {
// TODO: implement serialization
out.write(hm.size());
Iterator<Entry<String,Integer>> it = hm.entrySet().iterator();
while (it.hasNext()){
Map.Entry<String,Integer> pairs = (Map.Entry<String,Integer>)it.next();
String k=(String) pairs.getKey();
Integer v =(Integer) pairs.getValue();
out.writeInt(hm.size());
Iterator<Entry<String, Integer>> it = hm.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Integer> pairs = (Map.Entry<String, Integer>) it
.next();
String k = (String) pairs.getKey();
Integer v = (Integer) pairs.getValue();
out.writeInt(k.length());
out.writeBytes(k);
out.writeInt(v);
}
// TODO: implement serialization
}
}
public void clear() {
hm.clear();
}
......@@ -167,5 +119,4 @@ public class StringToIntMapWritable implements Writable {
increment(k, v);
}
}
}
......@@ -131,8 +131,4 @@ class StripesReducer extends Reducer<Text, // input key type
}
}
<<<<<<< HEAD
}
=======
}
>>>>>>> 8f49318439a759e7c34a55774d8d33aa3a91a874
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment