diff --git a/.clang-format b/.clang-format deleted file mode 100644 index 11d0dcd..0000000 --- a/.clang-format +++ /dev/null @@ -1 +0,0 @@ -BasedOnStyle: WebKit diff --git a/.clangd b/.clangd deleted file mode 100644 index 293cc69..0000000 --- a/.clangd +++ /dev/null @@ -1,5 +0,0 @@ -CompileFlags: - Add: - - "-std=c++20" - - "-I./include" - CompilationDatabase: build diff --git a/TODO.md b/TODO.md deleted file mode 100644 index f065214..0000000 --- a/TODO.md +++ /dev/null @@ -1,37 +0,0 @@ -- [x] file operations - - [x] write to file (at index) - - [x] read file -- [x] a tape type - representing a file? -- [x] a record type - x1,x2,x3,x4,x5 - - [x] comparing records -- [x] buffer quick sort -- [x] configuration - - [x] cmd args - man getopts -- [x] file input -- [ ] keyboard input -- [x] stage 1 - - [x] reading chunks - - [x] sorting - - [x] writing runs -- [ ] stage 2 - - [ ] implement a min heap with following operations - - [ ] pop - - [ ] push - - [ ] step 4 - - [ ] split the buffer into chunks of size n, and (b-1)n - - [ ] create a min heap of size (b-1)n - - [ ] populate the heap with (b-1) runs of n elements (each from a different file) - - [ ] find a way to mark if a last element from a certain file has been popped - - [ ] when a merged buffer is full, write it to file - - [ ] pop off the top element until there are no more elements from a certain array - - [ ] load another run from that file, and rehapify - - [ ] repeat untill all files empty - - [ ] the resulting file should get the new smallest filename in tmp dir - - - [ ] multiway merge - - [ ] writing larger runs - - [ ] repeat untill done - -- [ ] counting read, and write operations -- [ ] testing -- [ ] report diff --git a/include/merge_sorter.hpp b/include/merge_sorter.hpp index 361eeda..1bf5a21 100644 --- a/include/merge_sorter.hpp +++ b/include/merge_sorter.hpp @@ -6,24 +6,27 @@ class MergeSorter { private: - std::vector buffer_; - const std::string& tmp_dir_; - size_t buffer_rows_ = 0; - size_t disk_reads_ = 0; - size_t disk_writes_ = 0; - size_t phases_ = 0; + std::vector buffer_; + const std::string &tmp_dir_; + size_t buffer_rows_ = 0; + size_t disk_reads_ = 0; + size_t disk_writes_ = 0; + size_t phases_ = 0; - std::span get_chunk_span(size_t chunk_index); - size_t create_initial_runs(const std::string& input_file, const std::string& next_dir); - size_t merge_pass(const std::string& current_dir, const std::string& next_dir, size_t run_count); - void perform_k_way_merge(std::vector>& readers, - FileWriter& writer); + std::span get_chunk_span(size_t chunk_index); + size_t create_initial_runs(const std::string &input_file, + const std::string &next_dir); + size_t merge_pass(const std::string ¤t_dir, const std::string &next_dir, + size_t run_count); + void perform_k_way_merge(std::vector> &readers, + FileWriter &writer); public: - MergeSorter(size_t buffer_rows, size_t buffer_cols, const std::string& tmp_dir); - void sort_file(const std::string& input_file, const std::string& output_file); + MergeSorter(size_t buffer_rows, size_t buffer_cols, + const std::string &tmp_dir); + void sort_file(const std::string &input_file, const std::string &output_file); - size_t disk_reads(); - size_t disk_writes(); - size_t phases(); + size_t disk_reads(); + size_t disk_writes(); + size_t phases(); }; diff --git a/script.sh b/script.sh deleted file mode 100755 index a8aacb0..0000000 --- a/script.sh +++ /dev/null @@ -1,41 +0,0 @@ -# Generate 5 significantly different file sizes - -echo "./build/main -g 1000 -o build/run/tests/test_1k.in" -./build/main -g 1000 -o build/run/tests/test_1k.in -d build/run/tmp -echo "./build/main -g 5000 -o build/run/tests/test_5k.in" -./build/main -g 5000 -o build/run/tests/test_5k.in -d build/run/tmp -echo "./build/main -g 10000 -o build/run/tests/test_10k.in" -./build/main -g 10000 -o build/run/tests/test_10k.in -d build/run/tmp -echo "./build/main -g 50000 -o build/run/tests/test_50k.in" -./build/main -g 50000 -o build/run/tests/test_50k.in -d build/run/tmp -echo "./build/main -g 100000 -o build/run/tests/test_100k.in" -./build/main -g 100000 -o build/run/tests/test_100k.in -d build/run/tmp - -# Sort each test file and capture statistics - -echo "./build/main -i build/run/tests/test_1k.in -o build/run/tests/test_1k.out -n 4 -b 100" -./build/main -i build/run/tests/test_1k.in -o build/run/tests/test_1k.out -n 4 -b 100 -d build/run/tmp -echo "./build/main -i build/run/tests/test_5k.in -o build/run/tests/test_5k.out -n 4 -b 100" -./build/main -i build/run/tests/test_5k.in -o build/run/tests/test_5k.out -n 4 -b 100 -d build/run/tmp -echo "./build/main -i build/run/tests/test_10k.in -o build/run/tests/test_10k.out -n 4 -b 100" -./build/main -i build/run/tests/test_10k.in -o build/run/tests/test_10k.out -n 4 -b 100 -d build/run/tmp -echo "./build/main -i build/run/tests/test_50k.in -o build/run/tests/test_50k.out -n 4 -b 100" -./build/main -i build/run/tests/test_50k.in -o build/run/tests/test_50k.out -n 4 -b 100 -d build/run/tmp -echo "./build/main -i build/run/tests/test_100k.in -o build/run/tests/test_100k.out -n 4 -b 100" -./build/main -i build/run/tests/test_100k.in -o build/run/tests/test_100k.out -n 4 -b 100 -d build/run/tmp - -# Display first/last records to verify sorting - -echo "./build/main -e -i build/run/tests/test_1k.out | less" -./build/main -e -i build/run/tests/test_1k.out | less -d build/run/tmp -echo "./build/main -e -i build/run/tests/test_100k.out | less" -./build/main -e -i build/run/tests/test_100k.out | less -d build/run/tmp - -# Test with different K values (buffer rows) - -echo "./build/main -i build/run/tests/test_10k.in -o build/run/tests/test_10k_k2.out -n 3 -b 100 # K=2" -./build/main -i build/run/tests/test_10k.in -o build/run/tests/test_10k_k2.out -n 3 -b 100 # K=2 -d build/run/tmp -echo "./build/main -i build/run/tests/test_10k.in -o build/run/tests/test_10k_k4.out -n 5 -b 100 # K=4" -./build/main -i build/run/tests/test_10k.in -o build/run/tests/test_10k_k4.out -n 5 -b 100 # K=4 -d build/run/tmp -echo "./build/main -i build/run/tests/test_10k.in -o build/run/tests/test_10k_k8.out -n 9 -b 100 # K=8" -./build/main -i build/run/tests/test_10k.in -o build/run/tests/test_10k_k8.out -n 9 -b 100 # K=8 -d build/run/tmp