Skip to content

Commit

Permalink
refactor(compressed-graph): cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
dsalwasser committed Jul 16, 2024
1 parent 1ab95b0 commit 8f1de40
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 88 deletions.
6 changes: 3 additions & 3 deletions apps/benchmarks/shm_variable_length_codec_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
#include "kaminpar-cli/CLI11.h"

#include "kaminpar-common/console_io.h"
#include "kaminpar-common/graph-compression/varint_codec.h"
#include "kaminpar-common/graph-compression/varint_run_length_codec.h"
#include "kaminpar-common/graph-compression/varint_stream_codec.h"
#include "kaminpar-common/logger.h"
#include "kaminpar-common/timer.h"
#include "kaminpar-common/varint_codec.h"
#include "kaminpar-common/varint_run_length_codec.h"
#include "kaminpar-common/varint_stream_codec.h"

using namespace kaminpar;

Expand Down
18 changes: 9 additions & 9 deletions kaminpar-common/graph-compression/compressed_neighborhoods.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#include "kaminpar-common/constexpr_utils.h"
#include "kaminpar-common/datastructures/compact_static_array.h"
#include "kaminpar-common/datastructures/static_array.h"
#include "kaminpar-common/graph-compression/varint_codec.h"
#include "kaminpar-common/graph-compression/varint_run_length_codec.h"
#include "kaminpar-common/graph-compression/varint_stream_codec.h"
#include "kaminpar-common/math.h"
#include "kaminpar-common/ranges.h"
#include "kaminpar-common/varint_codec.h"
#include "kaminpar-common/varint_run_length_codec.h"
#include "kaminpar-common/varint_stream_codec.h"

namespace kaminpar {

Expand Down Expand Up @@ -562,7 +562,7 @@ template <typename NodeID, typename EdgeID, typename EdgeWeight> class Compresse
} else {
for (NodeID part = 0; part < part_count; ++part) {
const bool stop = iterate_part(part);
if (stop) {
if (stop) [[unlikely]] {
return;
}
}
Expand All @@ -586,11 +586,11 @@ template <typename NodeID, typename EdgeID, typename EdgeWeight> class Compresse
const bool stop = decode_intervals<kHasEdgeWeights>(
data, edge, prev_edge_weight, std::forward<Lambda>(l)
);
if (stop) {
if (stop) [[unlikely]] {
return true;
}

if (edge == max_edge) {
if (edge == max_edge) [[unlikely]] {
return false;
}
}
Expand Down Expand Up @@ -649,7 +649,7 @@ template <typename NodeID, typename EdgeID, typename EdgeWeight> class Compresse
invoke_caller(cur_left_extreme + j);
} else {
const bool stop = invoke_caller(cur_left_extreme + j);
if (stop) {
if (stop) [[unlikely]] {
return true;
}
}
Expand Down Expand Up @@ -703,7 +703,7 @@ template <typename NodeID, typename EdgeID, typename EdgeWeight> class Compresse
invoke_caller(first_adjacent_node);
} else {
const bool stop = invoke_caller(first_adjacent_node);
if (stop) {
if (stop) [[unlikely]] {
return true;
}
}
Expand Down Expand Up @@ -741,7 +741,7 @@ template <typename NodeID, typename EdgeID, typename EdgeWeight> class Compresse
invoke_caller(adjacent_node);
} else {
const bool stop = invoke_caller(adjacent_node);
if (stop) {
if (stop) [[unlikely]] {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @author: Daniel Salwasser
* @date: 26.12.2023
******************************************************************************/
#include "kaminpar-common/varint_codec.h"
#include "kaminpar-common/graph-compression/varint_codec.h"

namespace kaminpar {

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
******************************************************************************/
#pragma once

#include <cstddef>
#include <cstdint>
#include <stdexcept>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -143,7 +143,7 @@ template <typename Int> class VarIntRunLengthDecoder {
decode32(run_length, run_size, std::forward<Lambda>(l));
} else {
const bool stop = decode32(run_length, run_size, std::forward<Lambda>(l));
if (stop) {
if (stop) [[unlikely]] {
return;
}
}
Expand All @@ -157,7 +157,7 @@ template <typename Int> class VarIntRunLengthDecoder {
decode64(run_length, run_size, std::forward<Lambda>(l));
} else {
const bool stop = decode64(run_length, run_size, std::forward<Lambda>(l));
if (stop) {
if (stop) [[unlikely]] {
return;
}
}
Expand All @@ -171,203 +171,203 @@ template <typename Int> class VarIntRunLengthDecoder {

template <typename Lambda>
bool decode32(const std::uint8_t run_length, const std::uint8_t run_size, Lambda &&l) {
constexpr bool non_stoppable = std::is_void_v<std::invoke_result_t<Lambda, std::uint32_t>>;
constexpr bool kNonStoppable = std::is_void_v<std::invoke_result_t<Lambda, std::uint32_t>>;

switch (run_size) {
case 1:
for (std::uint8_t i = 0; i < run_length; ++i) {
std::uint32_t value = static_cast<std::uint32_t>(*_ptr);
const std::uint32_t value = static_cast<std::uint32_t>(*_ptr);
_ptr += 1;

if constexpr (non_stoppable) {
if constexpr (kNonStoppable) {
l(value);
} else {
const bool stop = l(value);
if (stop) {
if (stop) [[unlikely]] {
return true;
}
}
}
break;
case 2:
for (std::uint8_t i = 0; i < run_length; ++i) {
std::uint32_t value = *((std::uint16_t *)_ptr);
const std::uint32_t value = *((std::uint16_t *)_ptr);
_ptr += 2;

if constexpr (non_stoppable) {
if constexpr (kNonStoppable) {
l(value);
} else {
const bool stop = l(value);
if (stop) {
if (stop) [[unlikely]] {
return true;
}
}
}
break;
case 3:
for (std::uint8_t i = 0; i < run_length; ++i) {
std::uint32_t value = *((std::uint32_t *)_ptr) & 0xFFFFFF;
const std::uint32_t value = *((std::uint32_t *)_ptr) & 0xFFFFFF;
_ptr += 3;

if constexpr (non_stoppable) {
if constexpr (kNonStoppable) {
l(value);
} else {
const bool stop = l(value);
if (stop) {
if (stop) [[unlikely]] {
return true;
}
}
}
break;
case 4:
for (std::uint8_t i = 0; i < run_length; ++i) {
std::uint32_t value = *((std::uint32_t *)_ptr);
const std::uint32_t value = *((std::uint32_t *)_ptr);
_ptr += 4;

if constexpr (non_stoppable) {
if constexpr (kNonStoppable) {
l(value);
} else {
const bool stop = l(value);
if (stop) {
if (stop) [[unlikely]] {
return true;
}
}
}
break;
default:
throw std::runtime_error("unexpected run size");
__builtin_unreachable();
}

return false;
}

template <typename Lambda>
bool decode64(const std::uint8_t run_length, const std::uint8_t run_size, Lambda &&l) {
constexpr bool non_stoppable = std::is_void_v<std::invoke_result_t<Lambda, std::uint64_t>>;
constexpr bool kNonStoppable = std::is_void_v<std::invoke_result_t<Lambda, std::uint64_t>>;

switch (run_size) {
case 1:
for (std::uint8_t i = 0; i < run_length; ++i) {
std::uint64_t value = static_cast<std::uint64_t>(*_ptr);
const std::uint64_t value = static_cast<std::uint64_t>(*_ptr);
_ptr += 1;

if constexpr (non_stoppable) {
if constexpr (kNonStoppable) {
l(value);
} else {
const bool stop = l(value);
if (stop) {
if (stop) [[unlikely]] {
return true;
}
}
}
break;
case 2:
for (std::uint8_t i = 0; i < run_length; ++i) {
std::uint64_t value = *((std::uint16_t *)_ptr);
const std::uint64_t value = *((std::uint16_t *)_ptr);
_ptr += 2;

if constexpr (non_stoppable) {
if constexpr (kNonStoppable) {
l(value);
} else {
const bool stop = l(value);
if (stop) {
if (stop) [[unlikely]] {
return true;
}
}
}
break;
case 3:
for (std::uint8_t i = 0; i < run_length; ++i) {
std::uint64_t value = *((std::uint32_t *)_ptr) & 0xFFFFFF;
const std::uint64_t value = *((std::uint32_t *)_ptr) & 0xFFFFFF;
_ptr += 3;

if constexpr (non_stoppable) {
if constexpr (kNonStoppable) {
l(value);
} else {
const bool stop = l(value);
if (stop) {
if (stop) [[unlikely]] {
return true;
}
}
}
break;
case 4:
for (std::uint8_t i = 0; i < run_length; ++i) {
std::uint64_t value = *((std::uint32_t *)_ptr);
const std::uint64_t value = *((std::uint32_t *)_ptr);
_ptr += 4;

if constexpr (non_stoppable) {
if constexpr (kNonStoppable) {
l(value);
} else {
const bool stop = l(value);
if (stop) {
if (stop) [[unlikely]] {
return true;
}
}
}
break;
case 5:
for (std::uint8_t i = 0; i < run_length; ++i) {
std::uint64_t value = *((std::uint64_t *)_ptr) & 0xFFFFFFFFFF;
const std::uint64_t value = *((std::uint64_t *)_ptr) & 0xFFFFFFFFFF;
_ptr += 5;

if constexpr (non_stoppable) {
if constexpr (kNonStoppable) {
l(value);
} else {
const bool stop = l(value);
if (stop) {
if (stop) [[unlikely]] {
return true;
}
}
}
break;
case 6:
for (std::uint8_t i = 0; i < run_length; ++i) {
std::uint64_t value = *((std::uint64_t *)_ptr) & 0xFFFFFFFFFFFF;
const std::uint64_t value = *((std::uint64_t *)_ptr) & 0xFFFFFFFFFFFF;
_ptr += 6;

if constexpr (non_stoppable) {
if constexpr (kNonStoppable) {
l(value);
} else {
const bool stop = l(value);
if (stop) {
if (stop) [[unlikely]] {
return true;
}
}
}
break;
case 7:
for (std::uint8_t i = 0; i < run_length; ++i) {
std::uint64_t value = *((std::uint64_t *)_ptr) & 0xFFFFFFFFFFFFFF;
const std::uint64_t value = *((std::uint64_t *)_ptr) & 0xFFFFFFFFFFFFFF;
_ptr += 7;

if constexpr (non_stoppable) {
if constexpr (kNonStoppable) {
l(value);
} else {
const bool stop = l(value);
if (stop) {
if (stop) [[unlikely]] {
return true;
}
}
}
break;
case 8:
for (std::uint8_t i = 0; i < run_length; ++i) {
std::uint64_t value = *((std::uint64_t *)_ptr);
const std::uint64_t value = *((std::uint64_t *)_ptr);
_ptr += 8;

if constexpr (non_stoppable) {
if constexpr (kNonStoppable) {
l(value);
} else {
const bool stop = l(value);
if (stop) {
if (stop) [[unlikely]] {
return true;
}
}
}
break;
default:
throw std::runtime_error("unexpected run size");
__builtin_unreachable();
}

return false;
Expand Down
Loading

0 comments on commit 8f1de40

Please sign in to comment.