From 5cd2f0dc7d0659acf3a95939df7b52d19af274cd Mon Sep 17 00:00:00 2001 From: Rostislav Date: Wed, 31 Mar 2021 19:42:44 +0300 Subject: [PATCH] Reduce entry sizes in non-bitfield phases 2 and 3 --- src/b17phase2.hpp | 6 +++--- src/b17phase3.hpp | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/b17phase2.hpp b/src/b17phase2.hpp index 9e63702a3..e4dac6cc5 100644 --- a/src/b17phase2.hpp +++ b/src/b17phase2.hpp @@ -210,7 +210,7 @@ std::vector b17RunPhase2( entry_offset = Util::SliceInt64FromBytes(right_entry_buf, pos_size, kOffsetSize); entry_sort_key = Util::SliceInt64FromBytes( - right_entry_buf, pos_size + kOffsetSize, k + 1); + right_entry_buf, pos_size + kOffsetSize, k); } } else if (cached_entry_pos == current_pos) { // We have a cached entry at this position @@ -295,7 +295,7 @@ std::vector b17RunPhase2( // use this instead of (y + pos + offset) since its smaller. new_left_entry += Bits(entry_pos, pos_size); new_left_entry += Bits(entry_offset, kOffsetSize); - new_left_entry += Bits(left_entry_counter, k + 1); + new_left_entry += Bits(left_entry_counter, k); // If we are not taking up all the bits, make sure they are zeroed if (Util::ByteAlign(new_left_entry.GetSize()) < left_entry_size_bytes * 8) { @@ -348,7 +348,7 @@ std::vector b17RunPhase2( ? Bits(old_sort_keys[write_pointer_pos % kReadMinusWrite][counter], k) : Bits( old_sort_keys[write_pointer_pos % kReadMinusWrite][counter], - k + 1); + k); new_right_entry += new_pos_bin; // match_positions.push_back(std::make_pair(new_pos, new_offset_pos)); new_right_entry.AppendValue(new_offset_pos - new_pos, kOffsetSize); diff --git a/src/b17phase3.hpp b/src/b17phase3.hpp index 8c83e08e6..1e5c23694 100644 --- a/src/b17phase3.hpp +++ b/src/b17phase3.hpp @@ -62,6 +62,7 @@ b17Phase3Results b17RunPhase3( const bool show_progress) { uint8_t pos_size = k; + uint8_t line_point_size = 2 * k - 1; std::vector final_table_begin_pointers(12, 0); final_table_begin_pointers[1] = header_size; @@ -103,7 +104,7 @@ b17Phase3Results b17RunPhase3( // Sort key for table 7 is just y, which is k bits. For all other tables it can // be higher than 2^k and therefore k+1 bits are used. - uint32_t right_sort_key_size = table_index == 6 ? k : k + 1; + uint32_t right_sort_key_size = k; uint32_t left_entry_size_bytes = EntrySizes::GetMaxEntrySize(k, table_index, false); right_entry_size_bytes = EntrySizes::GetMaxEntrySize(k, table_index + 1, false); @@ -258,7 +259,7 @@ b17Phase3Results b17RunPhase3( } else { // k+1 bits in case it overflows left_new_pos[current_pos % kCachedPositionsSize] = - Util::SliceInt64FromBytes(left_entry_disk_buf, k + 1, k + 1); + Util::SliceInt64FromBytes(left_entry_disk_buf, right_sort_key_size, k); } } @@ -289,7 +290,7 @@ b17Phase3Results b17RunPhase3( abort(); } } - Bits to_write = Bits(line_point, 2 * k); + Bits to_write = Bits(line_point, line_point_size); to_write += Bits( old_sort_keys[write_pointer_pos % kReadMinusWrite][counter], right_sort_key_size); @@ -357,19 +358,20 @@ b17Phase3Results b17RunPhase3( // groups(parks), with a checkpoint in each group. Bits right_entry_bits; int added_to_cache = 0; + uint8_t index_size = table_index == 6 ? k + 1 : k; for (uint64_t index = 0; index < total_r_entries; index++) { right_reader_entry_buf = R_sort_manager->ReadEntry(right_reader, 2); right_reader += right_entry_size_bytes; right_reader_count++; // Right entry is read as (line_point, sort_key) - uint128_t line_point = Util::SliceInt128FromBytes(right_reader_entry_buf, 0, 2 * k); + uint128_t line_point = Util::SliceInt128FromBytes(right_reader_entry_buf, 0, line_point_size); uint64_t sort_key = - Util::SliceInt64FromBytes(right_reader_entry_buf, 2 * k, right_sort_key_size); + Util::SliceInt64FromBytes(right_reader_entry_buf, line_point_size, right_sort_key_size); // Write the new position (index) and the sort key Bits to_write = Bits(sort_key, right_sort_key_size); - to_write += Bits(index, k + 1); + to_write += Bits(index, index_size); L_sort_manager->AddToCache(to_write); added_to_cache++;