Skip to content

Commit

Permalink
Clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
amallia committed Mar 6, 2020
1 parent f3afb5d commit f011585
Show file tree
Hide file tree
Showing 43 changed files with 733 additions and 668 deletions.
43 changes: 21 additions & 22 deletions benchmarks/index_perftest.cpp
@@ -1,16 +1,16 @@
#include "mappable/mapper.hpp"
#include "mio/mmap.hpp"
#include "spdlog/spdlog.h"
#include "mappable/mapper.hpp"

#include "index_types.hpp"
#include "util/util.hpp"
#include "util/do_not_optimize_away.hpp"
#include "util/util.hpp"

using pisa::get_time_usecs;
using pisa::do_not_optimize_away;
using pisa::get_time_usecs;

template <typename IndexType, bool with_freqs>
void perftest(IndexType const& index, std::string const& type)
void perftest(IndexType const &index, std::string const &type)
{
std::string freqs_log = with_freqs ? "+freq()" : "";
{
Expand All @@ -33,7 +33,7 @@ void perftest(IndexType const& index, std::string const& type)
auto tick = get_time_usecs();
uint64_t calls_per_list = 500000;
size_t postings = 0;
for (auto i: long_lists) {
for (auto i : long_lists) {
auto reader = index[i];
auto calls = std::min(calls_per_list, reader.size());
for (size_t i = 0; i < calls; ++i) {
Expand Down Expand Up @@ -63,21 +63,21 @@ void perftest(IndexType const& index, std::string const& type)
for (size_t i = 0; i < index.size(); ++i) {
auto reader = index[i];
uint64_t size = reader.size();
if (size < min_length) continue;
if (size < min_length)
continue;

skip_values.emplace_back(i, std::vector<uint64_t>());
for (size_t i = 0; i < std::min(pisa::ceil_div(size, skip),
max_calls_per_list); ++i) {
for (size_t i = 0; i < std::min(pisa::ceil_div(size, skip), max_calls_per_list); ++i) {
reader.move(i * skip);
skip_values.back().second.push_back(reader.docid());
}
}

auto tick = get_time_usecs();
size_t calls = 0;
for (auto const& p: skip_values) {
for (auto const &p : skip_values) {
auto reader = index[p.first];
for (auto const& val: p.second) {
for (auto const &val : p.second) {
reader.next_geq(val);
do_not_optimize_away(reader.docid());
if (with_freqs) {
Expand All @@ -100,7 +100,7 @@ void perftest(IndexType const& index, std::string const& type)
}

template <typename IndexType>
void perftest(const char* index_filename, std::string const& type)
void perftest(const char *index_filename, std::string const &type)
{
spdlog::info("Loading index from {}", index_filename);
IndexType index;
Expand All @@ -111,27 +111,26 @@ void perftest(const char* index_filename, std::string const& type)
perftest<IndexType, true>(index, type);
}


int main(int argc, const char** argv) {
int main(int argc, const char **argv)
{

using namespace pisa;

if (argc != 3) {
std::cerr << "Usage: " << argv[0]
<< " <index type> <index filename>"
<< std::endl;
std::cerr << "Usage: " << argv[0] << " <index type> <index filename>" << std::endl;
return 1;
}

std::string type = argv[1];
const char* index_filename = argv[2];
const char *index_filename = argv[2];

if (false) {
#define LOOP_BODY(R, DATA, T) \
} else if (type == BOOST_PP_STRINGIZE(T)) { \
perftest<BOOST_PP_CAT(T, _index)> \
(index_filename, type); \
/**/
#define LOOP_BODY(R, DATA, T) \
} \
else if (type == BOOST_PP_STRINGIZE(T)) \
{ \
perftest<BOOST_PP_CAT(T, _index)>(index_filename, type); \
/**/

BOOST_PP_SEQ_FOR_EACH(LOOP_BODY, _, PISA_INDEX_TYPES);
#undef LOOP_BODY
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/perftest_interpolative.cpp
@@ -1,12 +1,11 @@
#include <iostream>
#include <algorithm>
#include <iostream>

#include "spdlog/spdlog.h"

#include "util/util.hpp"
#include "codec/block_codecs.hpp"
#include "util/do_not_optimize_away.hpp"

#include "util/util.hpp"

int main()
{
Expand All @@ -24,7 +23,8 @@ int main()

double tick = get_time_usecs();
for (size_t run = 0; run < runs; ++run) {
interpolative_block::decode(encoded.data(), values.data(), sum_of_values, values.size());
interpolative_block::decode(
encoded.data(), values.data(), sum_of_values, values.size());
do_not_optimize_away(values[0]);
}

Expand Down
30 changes: 15 additions & 15 deletions benchmarks/scan_perftest.cpp
Expand Up @@ -2,17 +2,17 @@
#include "spdlog/spdlog.h"

#include "mappable/mapper.hpp"
#include "sequence_collection.hpp"
#include "sequence/partitioned_sequence.hpp"
#include "sequence/uniform_partitioned_sequence.hpp"
#include "util/util.hpp"
#include "sequence_collection.hpp"
#include "util/do_not_optimize_away.hpp"
#include "util/util.hpp"

using pisa::get_time_usecs;
using pisa::do_not_optimize_away;
using pisa::get_time_usecs;

template <typename BaseSequence>
void perftest(const char* index_filename)
void perftest(const char *index_filename)
{
typedef pisa::sequence_collection<BaseSequence> collection_type;
spdlog::info("Loading collection from {}", index_filename);
Expand Down Expand Up @@ -54,7 +54,7 @@ void perftest(const char* index_filename)
auto tick = get_time_usecs();
uint64_t calls_per_list = 500000;
size_t postings = 0;
for (auto i: long_lists) {
for (auto i : long_lists) {
auto reader = coll[i];
auto calls = std::min(calls_per_list, reader.size());
auto val = reader.move(0);
Expand All @@ -80,7 +80,8 @@ void perftest(const char* index_filename)
if (reader.size() >= min_length) {
uint64_t size = reader.size();
// make sure size is odd, so that it is coprime with skip
if (!(size & 1)) size -= 1;
if (!(size & 1))
size -= 1;

skip_values.emplace_back(i, std::vector<uint64_t>());
skip_positions.emplace_back(i, std::vector<uint64_t>());
Expand All @@ -94,9 +95,9 @@ void perftest(const char* index_filename)

auto tick = get_time_usecs();
size_t calls = 0;
for (auto const& p: skip_values) {
for (auto const &p : skip_values) {
auto reader = coll[p.first];
for (auto const& val: p.second) {
for (auto const &val : p.second) {
do_not_optimize_away(reader.next_geq(val).second);
}
calls += p.second.size();
Expand All @@ -110,9 +111,9 @@ void perftest(const char* index_filename)

tick = get_time_usecs();
calls = 0;
for (auto const& p: skip_positions) {
for (auto const &p : skip_positions) {
auto reader = coll[p.first];
for (auto const& pos: p.second) {
for (auto const &pos : p.second) {
do_not_optimize_away(reader.move(pos).second);
}
calls += p.second.size();
Expand All @@ -125,22 +126,21 @@ void perftest(const char* index_filename)
(elapsed / calls * 1000));
}
}
int main(int argc, const char** argv) {
int main(int argc, const char **argv)
{

using pisa::compact_elias_fano;
using pisa::indexed_sequence;
using pisa::partitioned_sequence;
using pisa::uniform_partitioned_sequence;

if (argc != 3) {
std::cerr << "Usage: " << argv[0]
<< " <collection type> <index filename>"
<< std::endl;
std::cerr << "Usage: " << argv[0] << " <collection type> <index filename>" << std::endl;
return 1;
}

std::string type = argv[1];
const char* index_filename = argv[2];
const char *index_filename = argv[2];

if (type == "ef") {
perftest<compact_elias_fano>(index_filename);
Expand Down
33 changes: 14 additions & 19 deletions benchmarks/selective_queries.cpp
Expand Up @@ -4,17 +4,15 @@
#include "mio/mmap.hpp"

#include "index_types.hpp"
#include "wand_data_compressed.hpp"
#include "query/queries.hpp"
#include "util/util.hpp"
#include "wand_data_compressed.hpp"

template <typename IndexType>
void selective_queries(const char* index_filename,
std::string const& type)
void selective_queries(const char *index_filename, std::string const &type)
{
using namespace pisa;


IndexType index;
spdlog::info("Loading index from {}", index_filename);
mio::mmap_source m(index_filename);
Expand All @@ -24,7 +22,6 @@ void selective_queries(const char* index_filename,

term_id_vec query;


uint64_t count_taken = 0;
uint64_t count = 0;
while (read_query(query)) {
Expand All @@ -43,38 +40,36 @@ void selective_queries(const char* index_filename,
}
}



if (insert) {
count_taken++;
std::cout << query[0];
for (size_t i = 1; i < query.size(); ++i) std::cout << " " << query[i];
for (size_t i = 1; i < query.size(); ++i)
std::cout << " " << query[i];
std::cout << std::endl;
}
}

std::cout << (float) count_taken / (float) count << std::endl;

std::cout << (float)count_taken / (float)count << std::endl;
}


int main(int, const char** argv) {
int main(int, const char **argv)
{
using namespace pisa;

std::string type = argv[1];
const char* index_filename = argv[2];
const char *index_filename = argv[2];

if (false) {
#define LOOP_BODY(R, DATA, T) \
} else if (type == BOOST_PP_STRINGIZE(T)) { \
selective_queries<BOOST_PP_CAT(T, _index)> \
(index_filename, type);
/**/
#define LOOP_BODY(R, DATA, T) \
} \
else if (type == BOOST_PP_STRINGIZE(T)) \
{ \
selective_queries<BOOST_PP_CAT(T, _index)>(index_filename, type);
/**/

BOOST_PP_SEQ_FOR_EACH(LOOP_BODY, _, PISA_INDEX_TYPES);
#undef LOOP_BODY
} else {
spdlog::error("Unknown type {}", type);
}

}
3 changes: 2 additions & 1 deletion test/temporary_directory.hpp
Expand Up @@ -14,7 +14,8 @@ struct Temporary_Directory {
boost::filesystem::create_directory(dir_);
std::cerr << "Created a tmp dir " << dir_.c_str() << '\n';
}
~Temporary_Directory() {
~Temporary_Directory()
{
if (boost::filesystem::exists(dir_)) {
boost::filesystem::remove_all(dir_);
}
Expand Down
14 changes: 7 additions & 7 deletions test/test_block_codecs.cpp
@@ -1,25 +1,25 @@
#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"

#include <vector>
#include <cstdlib>
#include <vector>

#include "codec/block_codecs.hpp"
#include "codec/maskedvbyte.hpp"
#include "codec/streamvbyte.hpp"
#include "codec/qmx.hpp"
#include "codec/varintgb.hpp"
#include "codec/simple8b.hpp"
#include "codec/simdbp.hpp"
#include "codec/simple16.hpp"
#include "codec/simple8b.hpp"
#include "codec/streamvbyte.hpp"
#include "codec/varintgb.hpp"

#include "test_common.hpp"

template <typename BlockCodec>
void test_block_codec()
{
std::vector<size_t> sizes = {1, 16, BlockCodec::block_size - 1, BlockCodec::block_size};
for (auto size: sizes) {
for (auto size : sizes) {
std::vector<uint32_t> values(size);
std::generate(values.begin(), values.end(), []() { return (uint32_t)rand() % (1 << 12); });

Expand All @@ -33,8 +33,8 @@ void test_block_codec()
BlockCodec::encode(values.data(), sum_of_values, values.size(), encoded);

std::vector<uint32_t> decoded(values.size());
uint8_t const* out = BlockCodec::decode(encoded.data(), decoded.data(),
sum_of_values, values.size());
uint8_t const *out =
BlockCodec::decode(encoded.data(), decoded.data(), sum_of_values, values.size());

REQUIRE(encoded.size() == out - encoded.data());
REQUIRE(std::equal(values.begin(), values.end(), decoded.begin()));
Expand Down

0 comments on commit f011585

Please sign in to comment.