diff options
author | 2021-03-14 19:49:07 +0200 | |
---|---|---|
committer | 2021-03-14 19:49:07 +0200 | |
commit | 111d08d814720966d12fd57b58331c149df7e6cf (patch) | |
tree | 8c838a937767decc16579a3a3550e91c996de276 /src | |
parent | 56f20e30636c16fd14205ba7c29cf8089caa1260 (diff) | |
download | algos-ld1-111d08d814720966d12fd57b58331c149df7e6cf.tar.gz algos-ld1-111d08d814720966d12fd57b58331c149df7e6cf.tar.bz2 algos-ld1-111d08d814720966d12fd57b58331c149df7e6cf.zip |
we can now print out stuff... things.
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'src')
-rw-r--r-- | src/defs.h | 9 | ||||
-rw-r--r-- | src/main.c | 28 | ||||
-rw-r--r-- | src/stream.c | 4 | ||||
-rw-r--r-- | src/util.c | 17 | ||||
-rw-r--r-- | src/util.h | 1 |
5 files changed, 50 insertions, 9 deletions
@@ -7,6 +7,7 @@ #include <stddef.h> #include <stdint.h> +#include <inttypes.h> #include <sys/types.h> #include <rin/diagnostic.h> #include <rin/definitions.h> @@ -28,26 +29,34 @@ #if entry_field_size == 8 # ifdef entry_field_signed typedef int8_t field; +# define fieldprint PRIi8 # else typedef uint8_t field; +# define fieldprint PRIu8 # endif #elif entry_field_size == 16 # ifdef entry_field_signed typedef int16_t field; +# define fieldprint PRIi16 # else typedef uint16_t field; +# define fieldprint PRIu16 # endif #elif entry_field_size == 32 # ifdef entry_field_signed typedef int32_t field; +# define fieldprint PRIi32 # else typedef uint32_t field; +# define fieldprint PRIu32 # endif #elif entry_field_size == 64 # ifdef entry_field_signed typedef int64_t field; +# define fieldprint PRIi64 # else typedef uint64_t field; +# define fieldprint PRIu64 # endif #endif @@ -14,6 +14,7 @@ #include "cache.h" #include "datagen.h" #include "mergesort.h" +#include "util.h" static struct settings settings = {0, 0, 0, NULL, NULL, mode_normal, array, cached}; @@ -53,7 +54,14 @@ int main(int argc, char **argv) file_out.name = settings.fileout ? settings.fileout : settings.filein; try_s((ret = stream_open(&file_in)), out); - file_out.n = settings.opmode == mode_normal ? file_in.n : file_in.n - settings.ss; + + if (settings.opmode == mode_fetch) { + settings.to = settings.to == settings.ss ? file_in.n : settings.to; + file_tmp.n = settings.to - settings.ss; + } else { + file_out.n = file_in.n; + } + try_s((ret = stream_open(&file_out)), out); load_io_functions(&settings, &file_out); @@ -64,11 +72,15 @@ int main(int argc, char **argv) switch (settings.opmode) { case mode_fetch: + stream_shallow_copy(&file_in, &file_tmp); if (settings.format == array) { - try_s((ret = cache_block_copy(&file_in, &file_out)), out); + try_s((ret = cache_block_copy(&file_in, &file_tmp)), out); } else { /* settings.format == list */ - try_s((ret = stream_copy_range(&file_in, &file_out)), out); + try_s((ret = stream_copy_range(&file_in, &file_tmp)), out); } + + print_data(&file_tmp); + break; case mode_generate: try_s((ret = cache_transfer(&file_in, &file_out)), out); @@ -191,11 +203,13 @@ static int parseargs(int argc, char **argv, struct settings * settings) } - if (s.opmode == mode_generate) { - /* we always generate in-memory for PERFORMANCE */ + if (s.opmode != mode_normal) { + /* we always generate and print out in-memory for PERFORMANCE */ s.access = cached; - } else if (s.opmode == mode_fetch) { - s.to = s.ss + s.to; + + if (s.opmode == mode_fetch) { + s.to = s.ss + s.to; + } } s.stride = s.format == list ? sizeof(struct entry_l) : sizeof(struct entry); diff --git a/src/stream.c b/src/stream.c index 6a84940..13df929 100644 --- a/src/stream.c +++ b/src/stream.c @@ -58,7 +58,7 @@ int stream_close(struct stream * const in) { int ret = 0; - if (in->type != stream_out) { + if (in->type != stream_out || in->settings->opmode == mode_fetch) { goto out; } @@ -233,7 +233,7 @@ int stream_shallow_copy(struct stream const * const restrict src, struct stream { int ret = 0; - dest->n = src->n; + dest->n = dest->n ? dest->n : src->n; dest->settings = src->settings; dest->index = 0; @@ -1,4 +1,5 @@ #include <errno.h> +#include <stdio.h> #include "defs.h" #include "util.h" #include "cache.h" @@ -70,3 +71,19 @@ int split(struct stream * const src, struct stream * const A, struct stream * co err: return ret; } + +int print_data(struct stream * const in) +{ + int ret = 0; + struct entry_l store; + size_t i; + + puts( " position | value |\n" + " | |"); + + for (i = 0; in->get(in, &store); ++i) { + printf(" %10lu | " "%20"fieldprint" |\n", in->settings->ss + i, store.val); + } + + return ret; +} @@ -9,5 +9,6 @@ int stream_rewind(struct stream * const restrict in); int split(struct stream * const src, struct stream * const A, struct stream * const B); +int print_data(struct stream * const in); #endif /* ALGOS_UTIL_H_INCLUDED */ |