diff options
author | 2020-03-27 14:40:33 +0200 | |
---|---|---|
committer | 2020-03-27 14:40:33 +0200 | |
commit | 7754455c48c50764ad7291ea508109c53b60517f (patch) | |
tree | f8b3f0fe7ad2509ff8c40a998cde91f8f7353f80 /src/main.c | |
parent | 8b4c2c3194dbf9b18ecf475597d257ee7125a1e1 (diff) | |
download | algos-ld1-7754455c48c50764ad7291ea508109c53b60517f.tar.gz algos-ld1-7754455c48c50764ad7291ea508109c53b60517f.tar.bz2 algos-ld1-7754455c48c50764ad7291ea508109c53b60517f.zip |
cache I/O implementation and fixes.
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 73 |
1 files changed, 73 insertions, 0 deletions
@@ -10,6 +10,8 @@ #include <rin/diagnostic.h> #include "io.h" #include "defs.h" +#include "cache.h" +#include "datagen.h" static char randfile[] = "/dev/urandom"; @@ -19,7 +21,10 @@ static struct stream file_in = {.prev_idx = -1, .fd = -1}; static struct stream file_out = {.prev_idx = -1, .fd = -1, .out = 1}; static int parseargs(int argc, char **argv, struct settings * settings); +int prime_io_functions(struct settings const * const s, struct stream * const in); void printhelp(const char * const name); +static int stub_get(struct stream * const restrict in, ssize_t idx, struct entry_l * const data); +static int stub_put(struct stream * const restrict in, ssize_t idx, struct entry_l const * const data); int main(int argc, char **argv) { @@ -36,6 +41,9 @@ int main(int argc, char **argv) file_in.name = settings.filein; } + ret = prime_io_functions(&settings, &file_in); + ret = prime_io_functions(&settings, &file_out); + file_out.name = settings.fileout ? settings.fileout : settings.filein; try_s((ret = stream_open(&file_in, &settings)), out); file_out.n = file_in.n; @@ -131,6 +139,51 @@ err: return ret; } +int prime_io_functions(struct settings const * const s, struct stream * const in) +{ + int ret = 0; + + if (in->out == 1) { + if (s->format == array) { + in->get_element = stub_get; + in->put_element = stub_put; + in->get_element_cache = cached_get_array; + in->put_element_cache = cached_put_array; + } else { + in->get_element = stub_get; + in->put_element = stub_put; + in->get_element_cache = cached_get_list; + in->put_element_cache = cached_put_list; + } + } else if (!in->out) { /* reading streams do not support dumping */ + if (s->format == array) { + in->get_element = stub_get; + in->put_element = stub_put; + in->get_element_cache = stub_get; + in->put_element_cache = stub_put; + } else { + in->get_element = stub_get; + in->put_element = stub_put; + in->get_element_cache = stub_get; + in->put_element_cache = stub_put; + } + } else { /* data generation streams do not support dumping nor any cache I/O beyond initial data generation */ + if (s->format == array) { + in->get_element = gen_get_array; + in->put_element = stub_put; + in->get_element_cache = stub_get; + in->put_element_cache = stub_put; + } else { + in->get_element = gen_get_list; + in->put_element = stub_put; + in->get_element_cache = stub_get; + in->put_element_cache = stub_put; + } + } + + return ret; +} + void printhelp(const char * const name) { printf( "This is a mergesort program and such\n" @@ -153,3 +206,23 @@ void printhelp(const char * const name) name); return; } + +static int stub_get(struct stream * const restrict in, ssize_t idx, struct entry_l * const data) +{ + (void) in; + (void) idx; + (void) data; + + rin_warn("stub!"); + return ENOSYS; +} + +static int stub_put(struct stream * const restrict in, ssize_t idx, struct entry_l const * const data) +{ + (void) in; + (void) idx; + (void) data; + + rin_warn("stub!"); + return ENOSYS; +} |