1 #ifndef SORT_EXTERNALSORT_H
2 #define SORT_EXTERNALSORT_H
24 typedef std::function<int(
const char *item1,
const char *item2)>
43 static std::unique_ptr<ExternalSort>
114 void Rewind(uint64_t pos)
override;
The output operator that can used to scan through the output of this ExternalSort instance in ascendi...
Definition: ExternalSort.h:65
void EndScan() override
Ends the scan.
Definition: ExternalSort.cpp:70
~OutputIterator() override
Deconstructor to clean all the states.
Definition: ExternalSort.cpp:48
void Rewind(uint64_t pos) override
Rewind to a particular position saved before.
Definition: ExternalSort.cpp:65
uint64_t SavePosition() const override
Save the position of current iterator so that later on can be rewind to this position.
Definition: ExternalSort.h:102
bool Next() override
Move the iterator to next output record.
Definition: ExternalSort.cpp:53
bool SupportsRewind() const override
Indicate if this iterator supports rewind.
Definition: ExternalSort.h:97
OutputIterator(const File *tmpfile, PageNumber final_num_pages)
Construct an iterator from the tmp file containing the final sorted items.
Definition: ExternalSort.cpp:42
const char * GetCurrentItem(FieldOffset &p_reclen) override
Return the item pointed by this iterator.
Definition: ExternalSort.cpp:59
ExternalSort is a general utility class to do external sorting on any number of general bytes.
Definition: ExternalSort.h:35
ExternalSort(const SortCompareFunction &comp, size_t merge_ways)
Definition: ExternalSort.cpp:6
size_t m_merge_ways
how many ways of merge this operator allows, implicitly define memory budget as (m_merge_ways + 1) pa...
Definition: ExternalSort.h:164
void SortInitialRuns(ItemIterator *item_iter)
Iterate through item_iterator and create the initial runs based on memory budget.
Definition: ExternalSort.cpp:21
std::unique_ptr< ItemIterator > Sort(ItemIterator *input_iter)
Given an input_iter, it iterates over input_iter in one pass, and sorts all the returned items using ...
Definition: ExternalSort.cpp:37
PageNumber MergeInternalRuns(size_t low_run, size_t high_run)
Merge the runs low_run (inclusive) to high_run (inclusive) from last pass whose boundaries are stored...
Definition: ExternalSort.cpp:26
SortCompareFunction m_cmp
compare functions for sorting items.
Definition: ExternalSort.h:166
~ExternalSort()
Deconstructor of ExternalSort
Definition: ExternalSort.cpp:11
void GenerateNewPass(std::vector< PageNumber > &new_run_boundaries)
Generate a new sorted pass through a m_merge_ways merge from m_file[1 - m_current_pass].
Definition: ExternalSort.cpp:32
std::unique_ptr< File > m_file[2]
tmp files used in external sorting
Definition: ExternalSort.h:159
uint8_t m_current_pass
0 or 1, indicates which file current pass is using.
Definition: ExternalSort.h:157
std::vector< PageNumber > m_run_boundaries
Saves the page boundaries of last pass sorted runs.
Definition: ExternalSort.h:168
static std::unique_ptr< ExternalSort > Create(const SortCompareFunction &comp, size_t merge_ways)
Create an ExternalSort instance where comp provides the method of comparision function of two items.
Definition: ExternalSort.cpp:16
Represents an open virtual file managed by the FileManager.
Definition: FileManager.h:322
A pure abstract iterator over items (i.e., plain byte arrays).
Definition: ItemIterator.h:18
int16_t FieldOffset
Definition: tdb_base.h:218
uint32_t PageNumber
Definition: tdb_base.h:220
std::function< int(const char *item1, const char *item2)> SortCompareFunction
SortCompareFunction compares item1 and item2 and returns a negative integer if item1 < item2,...
Definition: ExternalSort.h:25