Skip to content

Commit

Permalink
Update .clang-format and reformat.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg7mdp committed Oct 8, 2023
1 parent 0f422fd commit 0a0666f
Show file tree
Hide file tree
Showing 81 changed files with 2,597 additions and 5,191 deletions.
22 changes: 11 additions & 11 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: MultiLine
AfterEnum: true
AfterFunction: true
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
AfterStruct: false
AfterUnion: false
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: true
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Mozilla
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeComma
BreakBeforeTernaryOperators: true
Expand Down
6 changes: 2 additions & 4 deletions examples/btree/btree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#include <gtl/btree.hpp>
#include <iostream>

int main()
{
int main() {
// initialise map with some values using an initializer_list
gtl::btree_map<std::string, int> map = {
{"John", 35},
Expand All @@ -26,8 +25,7 @@ int main()

IntString map2; // IntString is declared in btree_fwd.hpp

map2.emplace(
std::piecewise_construct, std::forward_as_tuple(0), std::forward_as_tuple(10, 'c'));
map2.emplace(std::piecewise_construct, std::forward_as_tuple(0), std::forward_as_tuple(10, 'c'));
map2.try_emplace(1, 10, 'a'); // gtl::btree_map supports c++17 API

for (auto& p : map2)
Expand Down
6 changes: 2 additions & 4 deletions examples/hmap/allmaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#include <string>

template<class Set, class F>
void test_set(const F& f)
{
void test_set(const F& f) {
Set s;
typename Set::iterator it;
for (int i = 0; i < 100; ++i)
Expand All @@ -21,8 +20,7 @@ void test_set(const F& f)
it = s.begin();
}

int main(int, char**)
{
int main(int, char**) {
using namespace std;

auto make_int = [](int i) { return i; };
Expand Down
3 changes: 1 addition & 2 deletions examples/hmap/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

using gtl::flat_hash_map;

int main()
{
int main() {
// Create an unordered_map of three strings (that map to strings)
flat_hash_map<std::string, std::string> email = {
{"tom", "tom@gmail.com" },
Expand Down
72 changes: 26 additions & 46 deletions examples/hmap/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
#endif
#elif 1
#include <windows.h>
class srwlock
{
class srwlock {
SRWLOCK _lock;

public:
Expand All @@ -42,13 +41,11 @@ class srwlock
#else
// spinlocks - slow!
#include <atomic>
class spinlock
{
class spinlock {
std::atomic_flag flag = ATOMIC_FLAG_INIT;
public:
void lock()
{
void lock() {
while (flag.test_and_set(std::memory_order_acquire))
;
}
Expand Down Expand Up @@ -113,21 +110,18 @@ int64_t _abs(int64_t x) { return (x < 0) ? -x : x; }
#endif // _MSC_VER

// --------------------------------------------------------------------------
class Timer
{
class Timer {
typedef std::chrono::high_resolution_clock high_resolution_clock;
typedef std::chrono::milliseconds milliseconds;

public:
explicit Timer(bool run = false)
{
explicit Timer(bool run = false) {
if (run)
reset();
}
void reset() { _start = high_resolution_clock::now(); }

milliseconds elapsed() const
{
milliseconds elapsed() const {
return std::chrono::duration_cast<milliseconds>(high_resolution_clock::now() - _start);
}

Expand All @@ -138,14 +132,12 @@ class Timer
// --------------------------------------------------------------------------
// from: https://github.com/preshing/RandomSequence
// --------------------------------------------------------------------------
class RSU
{
class RSU {
private:
unsigned int m_index;
unsigned int m_intermediateOffset;

static unsigned int permuteQPR(unsigned int x)
{
static unsigned int permuteQPR(unsigned int x) {
static const unsigned int prime = 4294967291u;
if (x >= prime)
return x; // The 5 integers out of range are mapped to themselves.
Expand All @@ -154,8 +146,7 @@ class RSU
}

public:
RSU(unsigned int seedBase, unsigned int seedOffset)
{
RSU(unsigned int seedBase, unsigned int seedOffset) {
m_index = permuteQPR(permuteQPR(seedBase) + 0x682f0161);
m_intermediateOffset = permuteQPR(permuteQPR(seedOffset) + 0x46790905);
}
Expand All @@ -165,25 +156,22 @@ class RSU

// --------------------------------------------------------------------------
template<class T>
void _fill(vector<T>& v)
{
void _fill(vector<T>& v) {
srand(1); // for a fair/deterministic comparison
for (size_t i = 0, sz = v.size(); i < sz; ++i)
v[i] = (T)(i * 10 + rand() % 10);
}

// --------------------------------------------------------------------------
template<class T>
void _shuffle(vector<T>& v)
{
void _shuffle(vector<T>& v) {
for (size_t n = v.size(); n >= 2; --n)
std::swap(v[n - 1], v[static_cast<unsigned>(rand()) % n]);
}

// --------------------------------------------------------------------------
template<class T, class HT>
Timer _fill_random(vector<T>& v, HT& hash)
{
Timer _fill_random(vector<T>& v, HT& hash) {
_fill<T>(v);
_shuffle<T>(v);

Expand All @@ -195,14 +183,12 @@ Timer _fill_random(vector<T>& v, HT& hash)
}

// --------------------------------------------------------------------------
void out(const char* test, uint64_t cnt, const Timer& t, bool = false)
{
void out(const char* test, uint64_t cnt, const Timer& t, bool = false) {
printf("%s,time,%" PRIu64 ",%s,%f\n", test, cnt, program_slug, ((double)t.elapsed().count() / 1000));
}

// --------------------------------------------------------------------------
void outmem(const char*, uint64_t cnt, uint64_t mem, bool final = false)
{
void outmem(const char*, uint64_t cnt, uint64_t mem, bool final = false) {
static uint64_t max_mem = 0;
static uint64_t max_keys = 0;
if (final)
Expand All @@ -223,8 +209,7 @@ static const char* test = "random";

// --------------------------------------------------------------------------
template<class HT>
void _fill_random_inner(int64_t cnt, HT& hash, RSU& rsu)
{
void _fill_random_inner(int64_t cnt, HT& hash, RSU& rsu) {
for (int64_t i = 0; i < cnt; ++i) {
hash.insert(typename HT::value_type(rsu.next(), 0));
++s_num_keys[0];
Expand All @@ -233,8 +218,7 @@ void _fill_random_inner(int64_t cnt, HT& hash, RSU& rsu)

// --------------------------------------------------------------------------
template<class HT>
void _fill_random_inner_mt(int64_t cnt, HT& hash, RSU& rsu)
{
void _fill_random_inner_mt(int64_t cnt, HT& hash, RSU& rsu) {
constexpr int64_t num_threads = 8; // has to be a power of two
std::unique_ptr<std::thread> threads[num_threads];

Expand Down Expand Up @@ -278,8 +262,7 @@ void _fill_random_inner_mt(int64_t cnt, HT& hash, RSU& rsu)
}

// --------------------------------------------------------------------------
uint64_t total_num_keys()
{
uint64_t total_num_keys() {
uint64_t n = 0;
for (int i = 0; i < 16; ++i)
n += s_num_keys[i];
Expand All @@ -288,8 +271,7 @@ uint64_t total_num_keys()

// --------------------------------------------------------------------------
template<class HT>
Timer _fill_random2(int64_t cnt, HT& hash)
{
Timer _fill_random2(int64_t cnt, HT& hash) {
test = "random";
unsigned int seed = 76687;
RSU rsu(seed, seed + 1);
Expand Down Expand Up @@ -317,8 +299,7 @@ Timer _fill_random2(int64_t cnt, HT& hash)

// --------------------------------------------------------------------------
template<class T, class HT>
Timer _lookup(vector<T>& v, HT& hash, size_t& num_present)
{
Timer _lookup(vector<T>& v, HT& hash, size_t& num_present) {
_fill_random(v, hash);

num_present = 0;
Expand All @@ -334,8 +315,7 @@ Timer _lookup(vector<T>& v, HT& hash, size_t& num_present)

// --------------------------------------------------------------------------
template<class T, class HT>
Timer _delete(vector<T>& v, HT& hash)
{
Timer _delete(vector<T>& v, HT& hash) {
_fill_random(v, hash);
_shuffle(v); // don't delete in insertion order

Expand All @@ -347,8 +327,7 @@ Timer _delete(vector<T>& v, HT& hash)
}

// --------------------------------------------------------------------------
void memlog()
{
void memlog() {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
uint64_t nbytes_old_out = gtl::GetProcessMemoryUsed();
uint64_t nbytes_old = gtl::GetProcessMemoryUsed(); // last non outputted mem measurement
Expand All @@ -359,7 +338,8 @@ void memlog()
uint64_t nbytes = gtl::GetProcessMemoryUsed();

if ((double)_abs(nbytes - nbytes_old_out) / nbytes_old_out > 0.03 ||
(double)_abs(nbytes - nbytes_old) / nbytes_old > 0.01) {
(double)_abs(nbytes - nbytes_old) / nbytes_old > 0.01)
{
if ((double)(nbytes - nbytes_old) / nbytes_old > 0.03)
outmem(test, total_num_keys() - 1, nbytes_old);
outmem(test, total_num_keys(), nbytes);
Expand All @@ -377,8 +357,7 @@ void memlog()
}

// --------------------------------------------------------------------------
int main(int argc, char** argv)
{
int main(int argc, char** argv) {
int64_t num_keys = 100000000;
const char* bench_name = "random";
int64_t i, value = 0;
Expand Down Expand Up @@ -414,7 +393,8 @@ int main(int argc, char** argv)
out("random", num_keys, timer);
}
#endif
else if (!strcmp(bench_name, "random")) {
else if (!strcmp(bench_name, "random"))
{
fprintf(stderr, "size = %zu\n", sizeof(hash));
timer = _fill_random2(num_keys, hash);
} else if (!strcmp(bench_name, "lookup")) {
Expand Down
9 changes: 3 additions & 6 deletions examples/hmap/dump_load.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <gtl/phmap_dump.hpp>
#include <iostream>

void dump_load_uint64_uint32()
{
void dump_load_uint64_uint32() {
gtl::flat_hash_map<uint64_t, uint32_t> mp1 = {
{100, 99 },
{ 300, 299}
Expand All @@ -26,8 +25,7 @@ void dump_load_uint64_uint32()
std::cout << n.first << "'s value is: " << n.second << "\n";
}

void dump_load_parallel_flat_hash_map()
{
void dump_load_parallel_flat_hash_map() {
gtl::parallel_flat_hash_map<uint64_t, uint32_t> mp1 = {
{100, 99 },
{ 300, 299},
Expand All @@ -52,8 +50,7 @@ void dump_load_parallel_flat_hash_map()
std::cout << "key: " << n.first << ", value: " << n.second << "\n";
}

int main()
{
int main() {
dump_load_uint64_uint32();
dump_load_parallel_flat_hash_map();
return 0;
Expand Down
18 changes: 6 additions & 12 deletions examples/hmap/dump_nested.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
#include <iostream>

template<class K, class V>
class MyMap : public gtl::flat_hash_map<K, gtl::flat_hash_set<V>>
{
class MyMap : public gtl::flat_hash_map<K, gtl::flat_hash_set<V>> {
public:
using Set = gtl::flat_hash_set<V>;

void dump(const std::string& filename)
{
void dump(const std::string& filename) {
gtl::BinaryOutputArchive ar_out(filename.c_str());

ar_out.saveBinary(this->size());
Expand All @@ -25,8 +23,7 @@ class MyMap : public gtl::flat_hash_map<K, gtl::flat_hash_set<V>>
}
}

void load(const std::string& filename)
{
void load(const std::string& filename) {
gtl::BinaryInputArchive ar_in(filename.c_str());

size_t size;
Expand All @@ -44,14 +41,12 @@ class MyMap : public gtl::flat_hash_map<K, gtl::flat_hash_set<V>>
}
}

void insert(K k, V v)
{
void insert(K k, V v) {
Set& set = (*this)[k];
set.insert(v);
}

friend std::ostream& operator<<(std::ostream& os, const MyMap& map)
{
friend std::ostream& operator<<(std::ostream& os, const MyMap& map) {
for (const auto& [k, m] : map) {
os << k << ": [";
for (const auto& x : m)
Expand All @@ -62,8 +57,7 @@ class MyMap : public gtl::flat_hash_map<K, gtl::flat_hash_set<V>>
}
};

int main()
{
int main() {
MyMap<size_t, size_t> m;
m.insert(1, 5);
m.insert(1, 8);
Expand Down
Loading

0 comments on commit 0a0666f

Please sign in to comment.