Commit 38980367 authored by feng's avatar feng

Stripes 5

parent 45acd4ad
......@@ -2,9 +2,7 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="05d59ada-3cd7-4c26-9a9f-8ed545f37173" name="Default" comment="">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/main/java/fr/eurecom/dsg/mapreduce/StringToIntMapWritable.java" afterPath="$PROJECT_DIR$/src/main/java/fr/eurecom/dsg/mapreduce/StringToIntMapWritable.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/main/java/fr/eurecom/dsg/mapreduce/Stripes.java" afterPath="$PROJECT_DIR$/src/main/java/fr/eurecom/dsg/mapreduce/Stripes.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
</list>
<ignored path="labs.iws" />
<ignored path=".idea/workspace.xml" />
......@@ -30,8 +28,8 @@
<file leaf-file-name="Stripes.java" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/main/java/fr/eurecom/dsg/mapreduce/Stripes.java">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.53872436">
<caret line="121" column="52" selection-start-line="121" selection-start-column="52" selection-end-line="121" selection-end-column="52" />
<state vertical-scroll-proportion="0.6241458">
<caret line="130" column="5" selection-start-line="130" selection-start-column="5" selection-end-line="130" selection-end-column="5" />
<folding>
<element signature="imports" expanded="true" />
</folding>
......@@ -43,7 +41,7 @@
<entry file="file://$PROJECT_DIR$/src/main/java/fr/eurecom/dsg/mapreduce/StringToIntMapWritable.java">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="87" column="3" selection-start-line="87" selection-start-column="3" selection-end-line="87" selection-end-column="3" />
<caret line="63" column="8" selection-start-line="63" selection-start-column="8" selection-end-line="63" selection-end-column="8" />
<folding>
<element signature="imports" expanded="true" />
</folding>
......@@ -56,7 +54,9 @@
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="43" column="51" selection-start-line="43" selection-start-column="51" selection-end-line="43" selection-end-column="51" />
<folding />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
......@@ -150,7 +150,7 @@
<component name="ProjectFrameBounds">
<option name="x" value="-1" />
<option name="y" value="27" />
<option name="width" value="962" />
<option name="width" value="1922" />
<option name="height" value="1054" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
......@@ -476,7 +476,7 @@
<servers />
</component>
<component name="ToolWindowManager">
<frame x="-1" y="27" width="962" height="1054" extended-state="4" />
<frame x="-1" y="27" width="1922" height="1054" extended-state="6" />
<editor active="true" />
<layout>
<window_info id="UI Designer" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
......@@ -599,7 +599,9 @@
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="43" column="51" selection-start-line="43" selection-start-column="51" selection-end-line="43" selection-end-column="51" />
<folding />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
......@@ -677,7 +679,9 @@
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="46" column="43" selection-start-line="46" selection-start-column="43" selection-end-line="46" selection-end-column="43" />
<folding />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
......@@ -889,10 +893,10 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/fr/eurecom/dsg/mapreduce/Pair.java">
<entry file="file://$PROJECT_DIR$/src/main/java/fr/eurecom/dsg/mapreduce/WordCountCombiner.java">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="20" column="0" selection-start-line="20" selection-start-column="0" selection-end-line="20" selection-end-column="0" />
<caret line="43" column="51" selection-start-line="43" selection-start-column="51" selection-end-line="43" selection-end-column="51" />
<folding>
<element signature="imports" expanded="true" />
</folding>
......@@ -909,18 +913,20 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/fr/eurecom/dsg/mapreduce/WordCountCombiner.java">
<entry file="file://$PROJECT_DIR$/src/main/java/fr/eurecom/dsg/mapreduce/Pair.java">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="43" column="51" selection-start-line="43" selection-start-column="51" selection-end-line="43" selection-end-column="51" />
<folding />
<caret line="20" column="0" selection-start-line="20" selection-start-column="0" selection-end-line="20" selection-end-column="0" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/fr/eurecom/dsg/mapreduce/StringToIntMapWritable.java">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="87" column="3" selection-start-line="87" selection-start-column="3" selection-end-line="87" selection-end-column="3" />
<caret line="63" column="8" selection-start-line="63" selection-start-column="8" selection-end-line="63" selection-end-column="8" />
<folding>
<element signature="imports" expanded="true" />
</folding>
......@@ -929,8 +935,8 @@
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/fr/eurecom/dsg/mapreduce/Stripes.java">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.53872436">
<caret line="121" column="52" selection-start-line="121" selection-start-column="52" selection-end-line="121" selection-end-column="52" />
<state vertical-scroll-proportion="0.6241458">
<caret line="130" column="5" selection-start-line="130" selection-start-column="5" selection-end-line="130" selection-end-column="5" />
<folding>
<element signature="imports" expanded="true" />
</folding>
......
......@@ -118,26 +118,34 @@ class StripesReducer
Context context) throws IOException, InterruptedException {
// TODO: implement the reduce method
// the value to send in the end
StringToIntMapWritable stripe = new StringToIntMapWritable();
HashMap<Text, IntWritable> hashMap = stripe.getHashMap();
for (StringToIntMapWritable value : values) {
// get the stripe which is a AssociativeArray, inside in associative array, there's a hashmap
HashMap<Text, IntWritable> valueHashMap = value.getHashMap();
Iterator iterator = valueHashMap.keySet().iterator();
while (iterator.hasNext()) {
Text keyInner = (Text) iterator.next();
if (hashMap.containsKey(keyInner)) {
int sum = hashMap.get(keyInner).get();
sum += valueHashMap.get(keyInner).get();
//hashMap.remove(keyInner);
hashMap.put(keyInner, new IntWritable(sum));
addValue(hashMap, value.getHashMap());
}
stripe.setHashMap(hashMap);
context.write(key, stripe);
}
private void addValue(HashMap<Text, IntWritable> hashMap, HashMap<Text, IntWritable> valueHashMap) {
Iterator iterator = (Iterator) hashMap.keySet();
Iterator iteratorValue = (Iterator) valueHashMap.keySet();
while (iterator.hasNext()) {
Text key = (Text) iterator.next();
int sum = 0;
while (iteratorValue.hasNext()) {
Text keyValue = (Text)iteratorValue.next();
if (key == keyValue) {
int count = valueHashMap.get(keyValue).get();
sum += count;
hashMap.put(key, new IntWritable(sum));
} else {
hashMap.put(keyInner, valueHashMap.get(keyInner));
hashMap.put(keyValue, new IntWritable((int)1));
}
}
stripe.setHashMap(hashMap);
context.write(key, stripe);
}
}
}
\ No newline at end of file
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