fix hang on small files

lean
Avril 4 years ago
parent d2681629d1
commit a2167bd106
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -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

@ -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];
}

@ -9,6 +9,7 @@ namespace rng {
template<typename T, typename R>
inline void shuffle(R& rng, span<T> 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<typename T, typename R>
inline void unshuffle(R& rng, span<T> span)
{
if(!span.size()) return;
std::vector<std::size_t> rng_values;
fmt::print(" -> unshuffling {} objects...", span.size());

@ -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);

@ -15,18 +15,16 @@
template<typename T, typename Fn>
std::tuple<T, T> minmax_t(const span<T>& array, Fn keep)
{
T lowest;
T highest;
T lowest;
for(std::size_t i=0;i<array.size();i++)
{
if(!keep(array[i])) continue;
if(!i) lowest = highest = array[i];
else {
auto item = array[i];
if(item < lowest) lowest = item;
if(item > highest) highest = item;
}
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};

Loading…
Cancel
Save