From a2167bd10693a9b92445baf2ed07186170f836be Mon Sep 17 00:00:00 2001 From: Avril Date: Thu, 26 Nov 2020 22:04:22 +0000 Subject: [PATCH] fix hang on small files --- lean/TODO.org | 5 +++++ lean/include/reinterpret.hpp | 4 ++-- lean/include/shuffle.hpp | 2 ++ lean/src/main.c | 6 +++--- lean/src/work.cpp | 12 +++++------- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lean/TODO.org b/lean/TODO.org index 630fb1f..7cf04dc 100644 --- a/lean/TODO.org +++ b/lean/TODO.org @@ -1,3 +1,8 @@ + +* Improvements + - *~70-80x* speedup from shuffle3 1.0 + - Can properly handle large files without core dumping + * Todo - [X] impl rng - [X] impl shuffling diff --git a/lean/include/reinterpret.hpp b/lean/include/reinterpret.hpp index 4e75669..68646c8 100644 --- a/lean/include/reinterpret.hpp +++ b/lean/include/reinterpret.hpp @@ -28,12 +28,12 @@ struct span { inline const T& operator[](std::size_t i) const { - if (i >= len) panic("Out of bounds access"); + if (i >= len) panic("Out of bounds access: %lu >= %lu", i, len); return ptr[i]; } inline T& operator[](std::size_t i) { - if(i >= len) panic("Out of bounds access"); + if (i >= len) panic("Out of bounds access: %lu >= %lu", i, len); return ptr[i]; } diff --git a/lean/include/shuffle.hpp b/lean/include/shuffle.hpp index f56724f..099f433 100644 --- a/lean/include/shuffle.hpp +++ b/lean/include/shuffle.hpp @@ -9,6 +9,7 @@ namespace rng { template inline void shuffle(R& rng, span span) { + if(!span.size()) return; fmt::print(" -> shuffling {} objects...", span.size()); for(std::size_t i=span.size()-1;i>0;i--) { @@ -21,6 +22,7 @@ namespace rng { template inline void unshuffle(R& rng, span span) { + if(!span.size()) return; std::vector rng_values; fmt::print(" -> unshuffling {} objects...", span.size()); diff --git a/lean/src/main.c b/lean/src/main.c index ae7e57f..311a097 100644 --- a/lean/src/main.c +++ b/lean/src/main.c @@ -47,9 +47,9 @@ int main(int argc, char** argv) //rng_test(); - rng_t r = rng_new(RNG_INIT(RNG_KIND_FRNG, frng = { { 1.0, 2.0 } })); - rng_test_spec(r); - rng_free(r); + //rng_t r = rng_new(RNG_INIT(RNG_KIND_FRNG, frng = { { 1.0, 2.0 } })); + //rng_test_spec(r); + //rng_free(r); if( argv[1] ) { //map_and_then(argv[1], &map_callback, &args); diff --git a/lean/src/work.cpp b/lean/src/work.cpp index cda07b3..758a45b 100644 --- a/lean/src/work.cpp +++ b/lean/src/work.cpp @@ -15,18 +15,16 @@ template std::tuple minmax_t(const span& array, Fn keep) { - T lowest; T highest; + T lowest; for(std::size_t i=0;i highest) highest = item; - } + auto item = array[i]; + if(!i) lowest = highest = item; + else if(item < lowest) lowest = item; + else if(item > highest) highest = item; } //fmt::print("MMX {}, {}\n", lowest, highest); return {lowest, highest};