diff options
author | 2021-02-21 13:16:54 +0200 | |
---|---|---|
committer | 2021-02-21 13:19:06 +0200 | |
commit | 29712a5098842ea3930ec00ddd1c0b9d264ba9b5 (patch) | |
tree | 3744b445acb971342be18fa6d2c9c4c20a470e1d /src/cache.c | |
parent | 26ab990a747ab675bcff32a40734dcb61468f652 (diff) | |
download | algos-ld1-29712a5098842ea3930ec00ddd1c0b9d264ba9b5.tar.gz algos-ld1-29712a5098842ea3930ec00ddd1c0b9d264ba9b5.tar.bz2 algos-ld1-29712a5098842ea3930ec00ddd1c0b9d264ba9b5.zip |
in-memory array sorting: GET!
lists need a bit more work and after that, in-file should shortly
follow.
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'src/cache.c')
-rw-r--r-- | src/cache.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/cache.c b/src/cache.c index f8a2026..19c5a92 100644 --- a/src/cache.c +++ b/src/cache.c @@ -8,8 +8,8 @@ #include <rin/definitions.h> #include <rin/diagnostic.h> #include "defs.h" - -static int cache_rewind(struct stream * const in); +#include "stream.h" +#include "cache.h" int cache_create(struct stream * const in) { @@ -34,6 +34,7 @@ int cache_populate(struct stream * const in) struct entry_l *tmp; try(in->settings->access != cached, err, EINVAL, "cannot populate cache: stream is uncached"); + try(!in->cache, err, EINVAL, "stream has no cache allocated"); /* if reading a a randstream, fall back to the one-element-at-a-time mode */ if (in->type == stream_randread) { @@ -48,7 +49,7 @@ int cache_populate(struct stream * const in) } } } else if (in->type == stream_in) { - try(1, err, ENOSYS, "populating cache from file is a TODO"); + try_s((ret == stream_readfile(in)), err); } else { try(1, err, EINVAL, "cannot populate a non-reading stream cache"); } @@ -94,7 +95,7 @@ int cache_block_copy(struct stream const * const src, struct stream * const dest try(src->settings->access != cached || dest->settings->access != cached, err, EINVAL, "cannot cache-copy between uncached streams"); try(!src->cache, err, EINVAL, "no cache to transfer"); - try(src->n > dest->settings->to, err, EINVAL, "invalid copy size"); + try(src->n < dest->settings->to, err, EINVAL, "invalid copy size"); try(!dest->cache, err, EINVAL, "no cache to transfer to"); memcpy(dest->cache, src->cache_a + dest->settings->ss, (dest->settings->to - dest->settings->ss) * dest->settings->stride); @@ -135,13 +136,13 @@ int cache_block_split(struct stream * const src, struct stream * const A, struct A->n = src->n / 2; B->n = src->n / 2 + (src->n & 1ul); A->index = B->index = 0; - A->parentid = B->parentid = random(); /* generate random parent ID that needs to match between children */ - A->type = B->type = stream_invalid; /* disallow any stream operations other than split/merge on children */ + A->type = B->type = stream_cache; /* disallow any stream operations other than split/merge on children */ A->fd = B->fd = -1; /* if we're splitting, these are for holding cache only */ /* we only care about these three functions for these temporary streams */ A->get_next_element_cache = B->get_next_element_cache = src->get_next_element_cache; A->place_next_element_cache = B->place_next_element_cache = src->place_next_element_cache; A->split = B->split = src->split; + A->rewind = B->rewind = src->rewind; tmp_settings = *src->settings; A->settings = B->settings = &tmp_settings; @@ -158,7 +159,7 @@ int cache_block_split(struct stream * const src, struct stream * const A, struct try_s((ret = cache_create(B)), err); try_s((ret = cache_block_copy(src, B)), err); - A->settings = B->settings = &tmp_settings; + A->settings = B->settings = src->settings; err: return ret; |