#include "../utils/timing.h"
#include <iostream>
#include <random>
#include <chrono>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;


size_t random_integer(int lower_bound, int upper_bound)
{
    unsigned seed = chrono::system_clock::now().time_since_epoch().count();

    minstd_rand0 generator (seed);

    return lower_bound + generator() % (upper_bound - lower_bound + 1);
}

int main(int argc, char **argv)
{
    // start with generating a sorted vector/list
    size_t n = 10000;
    vector<int> x_vec(n);
    list<int> x_list(n);
    for(size_t k = 0; k < n; ++k)
    {
        x_vec[k] = k + 1;
        x_list.push_back(k + 1);
    }


    // insert new random entries such that the container stays sorted
    tic();
    for(size_t i = 0; i < n; ++i)
    {
        size_t new_entry = random_integer(1,n);
        auto it = lower_bound(x_vec.begin(), x_vec.end(), new_entry);
        x_vec.insert(it, new_entry);
    }
    double time_1 = toc();

    tic();
    for(size_t i = 0; i < n; ++i)
    {
        size_t new_entry = random_integer(1,n);
        auto it = lower_bound(x_list.begin(), x_list.end(), new_entry);
        x_list.insert(it, new_entry);
    }
    double time_2 = toc();


    // check results
    cout << "New vector is sorted: " << std::boolalpha << is_sorted(x_vec.cbegin(), x_vec.cend()) << "\tsize: " << x_vec.size() << "\tduration: " << time_1 << endl;
    cout << "New list is sorted: " << std::boolalpha << is_sorted(x_list.cbegin(), x_list.cend()) << "\tsize: " << x_list.size() << "\tduration: " << time_2 << endl;

    // Vector stores 3 pointers
    // List stores two pointers for every element: one to the previous, one to the next element



    return 0;
}
