yadro-task/include/tapelib/tape_util.h
erius ad976a5a9e Added using directives to avoid excessive namespaecs
Added explicit include directories to each file, even if an already included header defined them
Removed using directives from header files
2024-10-28 12:32:14 +02:00

45 lines
1.4 KiB
C++

#ifndef TAPE_UTIL_H
#define TAPE_UTIL_H
#include "filetape.h"
#include "tape.h"
#include <cstddef>
#include <cstdint>
#include <functional>
#include <memory>
namespace tape {
/**
* Lambda, which takes the amount of cells a tape should have and returns
* a unique pointer to a temporary Tape with the specified amount of cells
*/
using TempTapeFactory = std::function<std::unique_ptr<Tape>(size_t)>;
/**
* TempTapeFactory that creates a new temporary FileTape
*/
const static inline TempTapeFactory FILETAPE_FACTORY =
[](size_t cells) -> std::unique_ptr<Tape> {
return std::make_unique<FileTape>(FileTape(cells));
};
/**
* External sort for Tape. Reads *ram_limit* cells into memory, sorts them,
* writes them to a temporary Tape, does this until all data from input Tape is
* sorted and put into temporary Tapes, then merges temporary Tapes sorted data
* into output Tape. Heap sort is preffered due to reduction in seek operations.
*
* @param input Tape, data of which should be sorted
* @param output Tape, where the sorted data is going to be written
* @param tmp_tape_factory Lambda expression that defines how new temporary
* Tapes are created
* @param sort_limit Max amount of cells that can be loaded into memory to use
* while sorting. Set to SIZE_MAX by default
*/
void external_sort(Tape &input, Tape &output, TempTapeFactory tmp_tape_factory,
size_t sort_limit = SIZE_MAX);
} // namespace tape
#endif // !TAPE_UTIL_H