changeset 24:64d2dfde95a5

Add KVReadIterator
author Lewin Bormann <lbo@spheniscida.de>
date Sun, 31 Jan 2016 15:00:03 +0000
parents 0620fcdadb9b
children 68f181727187
files src/formats/util.rs src/lib.rs
diffstat 2 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/formats/util.rs	Sun Jan 31 14:28:07 2016 +0000
+++ b/src/formats/util.rs	Sun Jan 31 15:00:03 2016 +0000
@@ -39,6 +39,31 @@
     }
 }
 
+/// Another transformation of [string] -> [(string,string)]; however,
+/// this one always reads one value, treats it as key, and another one,
+/// treated as value.
+pub struct KVReadIterator<I: Iterator<Item = String>> {
+    i: I,
+}
+
+impl<I: Iterator<Item = String>> KVReadIterator<I> {
+    pub fn new(it: I) -> KVReadIterator<I> {
+        KVReadIterator { i: it }
+    }
+}
+
+impl<I: Iterator<Item = String>> Iterator for KVReadIterator<I> {
+    type Item = Record;
+    fn next(&mut self) -> Option<Record> {
+        let (k, v) = (self.i.next(), self.i.next());
+        match (k, v) {
+            (None, _) => None,
+            (_, None) => None,
+            (Some(k_), Some(v_)) => Some(Record { key: k_, value: v_ }),
+        }
+    }
+}
+
 /// A type implementing MRSinkGenerator is used at the end of the reducer
 /// phase to write the output. Given a name, new() should return a new object
 /// that can be used to write the output of a reduce partition.
--- a/src/lib.rs	Sun Jan 31 14:28:07 2016 +0000
+++ b/src/lib.rs	Sun Jan 31 15:00:03 2016 +0000
@@ -1,6 +1,12 @@
+//! Implements a mapreduce process bounded to one machine;
+//! this is supposed to result in better data parallelization.
+//!
+
 pub mod closure_mr;
 pub mod formats;
 pub mod mapreducer;
 
+
+
 #[test]
 fn it_works() {}