Skip to content

Commit

Permalink
store sorting strategy as a member in the sort manager, so we don't h…
Browse files Browse the repository at this point in the history
…ave to pass it in to each ReadEntry() call
  • Loading branch information
arvidn authored and hoffmang9 committed Nov 3, 2020
1 parent c894e83 commit 7342c76
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/phase3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ Phase3Results RunPhase3(
tmp_dirname,
filename + ".p3.t" + std::to_string(table_index + 1),
0,
0);
0,
strategy_t::quicksort_last);

bool should_read_entry = true;
std::vector<uint64_t> left_new_pos(kCachedPositionsSize);
Expand Down Expand Up @@ -408,7 +409,8 @@ Phase3Results RunPhase3(
tmp_dirname,
filename + ".p3s.t" + std::to_string(table_index + 1),
0,
0);
0,
strategy_t::quicksort);

std::vector<uint8_t> park_deltas;
std::vector<uint64_t> park_stubs;
Expand Down
24 changes: 23 additions & 1 deletion src/sort_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ namespace fs = ghc::filesystem;
#include "./uniformsort.hpp"
#include "exceptions.hpp"

enum class strategy_t : uint8_t
{
uniform,
quicksort,
quicksort_last,
};

class SortManager {
public:
SortManager(
Expand All @@ -47,7 +54,8 @@ class SortManager {
const std::string &tmp_dirname,
const std::string &filename,
uint32_t begin_bits,
uint64_t const stripe_size)
uint64_t const stripe_size,
strategy_t const sort_strategy = strategy_t::uniform)
: memory_start(memory)
, memory_size(memory_size)
, entry_size(entry_size)
Expand All @@ -59,6 +67,7 @@ class SortManager {
, prev_bucket_buf_(new uint8_t[prev_bucket_buf_size]())
// 7 bytes head-room for SliceInt64FromBytes()
, entry_buf_(new uint8_t[entry_size + 7])
, strategy_(sort_strategy)
{
// Cross platform way to concatenate paths, gulrak library.
std::vector<fs::path> bucket_filenames = std::vector<fs::path>();
Expand Down Expand Up @@ -105,6 +114,10 @@ class SortManager {

uint8_t *ReadEntry(uint64_t position, int quicksort = 0)
{
assert((quicksort == 0) == (strategy_ == strategy_t::uniform));
assert((quicksort == 1) == (strategy_ == strategy_t::quicksort));
assert((quicksort == 2) == (strategy_ == strategy_t::quicksort_last));

if (position < this->final_position_start) {
if (!(position >= this->prev_bucket_position_start)) {
throw InvalidStateException("Invalid prev bucket start");
Expand Down Expand Up @@ -136,6 +149,10 @@ class SortManager {

void TriggerNewBucket(uint64_t position, bool quicksort)
{
assert((quicksort == false) == (strategy_ == strategy_t::uniform));
assert((quicksort == true) == (strategy_ == strategy_t::quicksort
|| strategy_ == strategy_t::quicksort_last));

if (!(position <= this->final_position_end)) {
throw InvalidValueException("Triggering bucket too late");
}
Expand Down Expand Up @@ -226,6 +243,7 @@ class SortManager {
uint64_t final_position_end = 0;
uint64_t next_bucket_to_sort = 0;
std::unique_ptr<uint8_t[]> entry_buf_;
strategy_t strategy_;

void FlushTable(uint16_t bucket_i)
{
Expand All @@ -245,6 +263,10 @@ class SortManager {

void SortBucket(int quicksort)
{
assert((quicksort == 0) == (strategy_ == strategy_t::uniform));
assert((quicksort == 1) == (strategy_ == strategy_t::quicksort));
assert((quicksort == 2) == (strategy_ == strategy_t::quicksort_last));

this->done = true;
if (next_bucket_to_sort >= buckets_.size()) {
throw InvalidValueException("Trying to sort bucket which does not exist.");
Expand Down

0 comments on commit 7342c76

Please sign in to comment.