Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/vowpal_wabbit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/io.cc
diff options
context:
space:
mode:
authorGordon Rios <gparker@gmail.com>2009-04-30 03:16:59 +0400
committerGordon Rios <gparker@gmail.com>2009-04-30 03:16:59 +0400
commit89b6cd6a38264153ae425117e09ceff3d4d92b3e (patch)
tree86fd8a4de189f7fd09c414f5d82d7f583f97c792 /io.cc
initial check in
Diffstat (limited to 'io.cc')
-rw-r--r--io.cc46
1 files changed, 46 insertions, 0 deletions
diff --git a/io.cc b/io.cc
new file mode 100644
index 00000000..b30acd22
--- /dev/null
+++ b/io.cc
@@ -0,0 +1,46 @@
+/*
+Copyright (c) 2007 Yahoo! Inc. All rights reserved. The copyrights
+embodied in the content of this file are licensed under the BSD
+(revised) open source license
+ */
+
+#include "io.h"
+
+unsigned int buf_read(io_buf &i, char* &pointer, int n)
+{//return a pointer to the next n bytes. n must be smaller than 2^24.
+ if (i.space.end + n <= i.space.end_array)
+ {
+ pointer = i.space.end;
+ i.space.end += n;
+ return n;
+ }
+ else if (n > (i.space.end_array - i.space.begin)) // the file is ending or ended.
+ {
+ pointer = i.space.end;
+ int ret = i.space.end_array - i.space.end;
+ i.space.end = i.space.end_array;
+ return ret;
+ }
+ else // Change locations and refill buffer.
+ {
+ int left = i.space.end_array - i.space.end;
+ memmove(i.space.begin, i.space.end, left);
+ i.fill(left);
+ i.space.end = i.space.begin;
+ return buf_read(i,pointer,n);
+ }
+}
+
+void buf_write(io_buf &o, char* &pointer, int n)
+{//return a pointer to the next n bytes to write into.
+ if (o.space.end + n <= o.space.end_array)
+ {
+ pointer = o.space.end;
+ o.space.end += n;
+ }
+ else // Time to dump the file
+ {
+ o.flush();
+ buf_write (o, pointer,n);
+ }
+}