Skip to content

Commit

Permalink
Update clang-format rules
Browse files Browse the repository at this point in the history
Updates the clang-format rules and reformats all source files. A current
version of clang-format is also used instead of 9.
  • Loading branch information
elshize committed Dec 20, 2023
1 parent 9ec5817 commit 9ec4844
Show file tree
Hide file tree
Showing 203 changed files with 2,464 additions and 3,226 deletions.
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
AccessModifierOffset: '-2'
AlignAfterOpenBracket: AlwaysBreak
AlignAfterOpenBracket: BlockIndent
AlignConsecutiveAssignments: 'false'
AlignConsecutiveDeclarations: 'false'
AlignEscapedNewlines: Left
Expand All @@ -26,7 +26,7 @@ BreakBeforeTernaryOperators: 'true'
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
BraceWrapping:
AfterFunction: true
AfterFunction: false
SplitEmptyFunction: false
ColumnLimit: '100'
CompactNamespaces: 'true'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
- name: Install clang-format
shell: bash
run: |
sudo apt-get install -y clang-format-9
sudo apt-get install -y clang-format
- name: Set up Python
uses: actions/setup-python@v1
Expand All @@ -112,7 +112,7 @@ jobs:
run: |
wget https://raw.githubusercontent.com/Sarcasm/run-clang-format/master/run-clang-format.py
python run-clang-format.py \
--clang-format-executable clang-format-9 \
--clang-format-executable clang-format \
-r src/**/*.cpp include/pisa/**/*.hpp tools/*.cpp tools/*.hpp test/*.cpp
headers:
Expand Down
21 changes: 8 additions & 13 deletions include/pisa/accumulator/lazy_accumulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class LazyAccumulator {
using reference = float&;

static_assert(
std::is_integral_v<Descriptor> && std::is_unsigned_v<Descriptor>, "must be unsigned number");
std::is_integral_v<Descriptor> && std::is_unsigned_v<Descriptor>, "must be unsigned number"
);
constexpr static auto descriptor_size_in_bits = sizeof(Descriptor) * 8;
constexpr static auto counters_in_descriptor = descriptor_size_in_bits / counter_bit_size;
constexpr static auto cycle = (1U << counter_bit_size);
Expand All @@ -34,17 +35,15 @@ class LazyAccumulator {
Descriptor descriptor{};
std::array<float, counters_in_descriptor> accumulators{};

[[nodiscard]] auto counter(int pos) const noexcept -> int
{
[[nodiscard]] auto counter(int pos) const noexcept -> int {
if constexpr (counter_bit_size == 8) { // NOLINT(readability-braces-around-statements)
return static_cast<int>(*(reinterpret_cast<uint8_t const*>(&descriptor) + pos));
} else {
return (descriptor >> (pos * counter_bit_size)) & mask;
}
}

void reset_counter(int pos, int counter)
{
void reset_counter(int pos, int counter) {
if constexpr (counter_bit_size == 8) { // NOLINT(readability-braces-around-statements)
*(reinterpret_cast<uint8_t*>(&descriptor) + pos) = static_cast<uint8_t>(counter);
} else {
Expand All @@ -58,13 +57,11 @@ class LazyAccumulator {

public:
explicit LazyAccumulator(std::size_t size)
: m_size(size), m_accumulators((size + counters_in_descriptor - 1) / counters_in_descriptor)
{
: m_size(size), m_accumulators((size + counters_in_descriptor - 1) / counters_in_descriptor) {
PISA_ASSERT_CONCEPT(PartialScoreAccumulator<decltype(*this)>);
}

void reset()
{
void reset() {
if (m_counter == 0) {
auto first = reinterpret_cast<std::byte*>(&m_accumulators.front());
auto last =
Expand All @@ -73,8 +70,7 @@ class LazyAccumulator {
}
}

void accumulate(std::size_t document, float score)
{
void accumulate(std::size_t document, float score) {
auto const block = document / counters_in_descriptor;
auto const pos_in_block = document % counters_in_descriptor;
if (m_accumulators[block].counter(pos_in_block) != m_counter) {
Expand All @@ -83,8 +79,7 @@ class LazyAccumulator {
m_accumulators[block].accumulators[pos_in_block] += score;
}

void collect(topk_queue& topk)
{
void collect(topk_queue& topk) {
uint64_t docid = 0U;
for (auto const& block: m_accumulators) {
int pos = 0;
Expand Down
6 changes: 2 additions & 4 deletions include/pisa/accumulator/simple_accumulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@ namespace pisa {
*/
class SimpleAccumulator: public std::vector<float> {
public:
explicit SimpleAccumulator(std::size_t size) : std::vector<float>(size)
{
explicit SimpleAccumulator(std::size_t size) : std::vector<float>(size) {
PISA_ASSERT_CONCEPT(PartialScoreAccumulator<decltype(*this)>);
}

void reset() { std::fill(begin(), end(), 0.0); }

void accumulate(std::uint32_t doc, float score) { operator[](doc) += score; }

void collect(topk_queue& topk)
{
void collect(topk_queue& topk) {
std::uint32_t docid = 0U;
std::for_each(begin(), end(), [&](auto score) {
if (topk.would_enter(score)) {
Expand Down
36 changes: 14 additions & 22 deletions include/pisa/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
namespace pisa {
namespace execution {

class sequenced_policy {
};
class parallel_policy {
};
class parallel_unsequenced_policy {
};
class sequenced_policy {};
class parallel_policy {};
class parallel_unsequenced_policy {};

inline constexpr sequenced_policy seq{};
inline constexpr parallel_policy par{};
Expand All @@ -23,20 +20,17 @@ namespace execution {
#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS)

[[nodiscard]] constexpr auto to_std(pisa::execution::sequenced_policy /* policy */)
-> std::execution::sequenced_policy
{
-> std::execution::sequenced_policy {
return std::execution::seq;
}

[[nodiscard]] constexpr auto to_std(pisa::execution::parallel_policy /* policy */)
-> std::execution::parallel_policy
{
-> std::execution::parallel_policy {
return std::execution::par;
}

[[nodiscard]] constexpr auto to_std(pisa::execution::parallel_unsequenced_policy /* policy */)
-> std::execution::parallel_unsequenced_policy
{
-> std::execution::parallel_unsequenced_policy {
return std::execution::par_unseq;
}

Expand All @@ -52,8 +46,8 @@ OutputIt transform(
ForwardIt1 first,
ForwardIt1 last,
OutputIt d_first,
UnaryOperation unary_op)
{
UnaryOperation unary_op
) {
#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS)
auto std_policy = pisa::execution::to_std(policy);
return std::transform(std_policy, first, last, d_first, unary_op);
Expand All @@ -71,8 +65,8 @@ OutputIt transform(
ForwardIt1 last1,
ForwardIt2 first2,
OutputIt d_first,
BinaryOperation binary_op)
{
BinaryOperation binary_op
) {
#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS)
auto std_policy = pisa::execution::to_std(policy);
return std::transform(std_policy, first1, last1, first2, d_first, binary_op);
Expand All @@ -82,8 +76,7 @@ OutputIt transform(
}

template <class ExecutionPolicy, class RandomIt>
void sort([[maybe_unused]] ExecutionPolicy&& policy, RandomIt first, RandomIt last)
{
void sort([[maybe_unused]] ExecutionPolicy&& policy, RandomIt first, RandomIt last) {
#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS)
auto std_policy = pisa::execution::to_std(policy);
return std::sort(std_policy, first, last);
Expand All @@ -93,8 +86,7 @@ void sort([[maybe_unused]] ExecutionPolicy&& policy, RandomIt first, RandomIt la
}

template <class ExecutionPolicy, class RandomIt, class Compare>
void sort([[maybe_unused]] ExecutionPolicy&& policy, RandomIt first, RandomIt last, Compare comp)
{
void sort([[maybe_unused]] ExecutionPolicy&& policy, RandomIt first, RandomIt last, Compare comp) {
#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS)
auto std_policy = pisa::execution::to_std(policy);
return std::sort(std_policy, first, last, comp);
Expand All @@ -105,8 +97,8 @@ void sort([[maybe_unused]] ExecutionPolicy&& policy, RandomIt first, RandomIt la

template <class ExecutionPolicy, class ForwardIt, class UnaryFunction2>
void for_each(
[[maybe_unused]] ExecutionPolicy&& policy, ForwardIt first, ForwardIt last, UnaryFunction2 f)
{
[[maybe_unused]] ExecutionPolicy&& policy, ForwardIt first, ForwardIt last, UnaryFunction2 f
) {
#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS)
auto std_policy = pisa::execution::to_std(policy);
std::for_each(std_policy, first, last, f);
Expand Down
18 changes: 6 additions & 12 deletions include/pisa/binary_collection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class base_binary_collection {
using pointer = typename std::
conditional<std::is_same<Source, mio::mmap_source>::value, posting_type const, posting_type>::type*;

explicit base_binary_collection(const char* filename)
{
explicit base_binary_collection(const char* filename) {
std::error_code error;
m_file.map(filename, error);
if (error) {
Expand Down Expand Up @@ -56,8 +55,7 @@ class base_binary_collection {
pointer end() const { return m_end; }
size_t size() const { return m_end - m_begin; }

posting_type back() const
{
posting_type back() const {
assert(size());
return *(m_end - 1);
}
Expand Down Expand Up @@ -100,15 +98,13 @@ class base_binary_collection {

auto const* operator->() const { return &m_cur_seq; }

base_iterator& operator++()
{
base_iterator& operator++() {
m_pos = m_next_pos;
read();
return *this;
}

bool operator==(base_iterator const& other) const
{
bool operator==(base_iterator const& other) const {
assert(m_data == other.m_data);
assert(m_data_size == other.m_data_size);
return m_pos == other.m_pos;
Expand All @@ -120,13 +116,11 @@ class base_binary_collection {
friend class base_binary_collection;

base_iterator(base_binary_collection const* coll, size_t pos)
: m_data(coll->m_data), m_data_size(coll->m_data_size), m_pos(pos)
{
: m_data(coll->m_data), m_data_size(coll->m_data_size), m_pos(pos) {
read();
}

void read()
{
void read() {
assert(m_pos <= m_data_size);
if (m_pos == m_data_size) {
return;
Expand Down
12 changes: 4 additions & 8 deletions include/pisa/binary_freq_collection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class binary_freq_collection {
public:
explicit binary_freq_collection(const char* basename)
: m_docs((std::string(basename) + ".docs").c_str()),
m_freqs((std::string(basename) + ".freqs").c_str())
{
m_freqs((std::string(basename) + ".freqs").c_str()) {
auto firstseq = *m_docs.begin();
if (firstseq.size() != 1) {
throw std::invalid_argument("First sequence should only contain number of documents");
Expand All @@ -23,8 +22,7 @@ class binary_freq_collection {

class iterator;

iterator begin() const
{
iterator begin() const {
auto docs_it = m_docs.begin();
return iterator(++docs_it, m_freqs.begin());
}
Expand Down Expand Up @@ -54,8 +52,7 @@ class binary_freq_collection {

sequence const* operator->() const { return &m_cur_seq; }

iterator& operator++()
{
iterator& operator++() {
m_cur_seq.docs = *++m_docs_it;
m_cur_seq.freqs = *++m_freqs_it;
return *this;
Expand All @@ -69,8 +66,7 @@ class binary_freq_collection {
friend class binary_freq_collection;

iterator(binary_collection::const_iterator docs_it, binary_collection::const_iterator freqs_it)
: m_docs_it(docs_it), m_freqs_it(freqs_it)
{
: m_docs_it(docs_it), m_freqs_it(freqs_it) {
m_cur_seq.docs = *m_docs_it;
m_cur_seq.freqs = *m_freqs_it;
}
Expand Down
Loading

0 comments on commit 9ec4844

Please sign in to comment.