Skip to content

Commit

Permalink
Cleanup some clang-tidy warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg7mdp committed Apr 24, 2023
1 parent 81df19c commit 3e43235
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 63 deletions.
20 changes: 8 additions & 12 deletions examples/hmap/matt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
class Timer
{
public:
Timer(std::string name)
Timer(const std::string& name)
: _name(name)
, _start(std::chrono::high_resolution_clock::now())
{
}

~Timer()
{
std::chrono::duration<float> elapsed_seconds =
std::chrono::high_resolution_clock::now() - _start;
std::chrono::duration<float> elapsed_seconds = std::chrono::high_resolution_clock::now() - _start;
printf("%s: %.3fs\n", _name.c_str(), elapsed_seconds.count());
}

Expand Down Expand Up @@ -57,18 +56,15 @@ class RSU
m_intermediateOffset = permuteQPR(permuteQPR(seedOffset) + 0x46790905);
}

uint32_t next()
{
return permuteQPR((permuteQPR(m_index++) + m_intermediateOffset) ^ 0x5bf03635);
}
uint32_t next() { return permuteQPR((permuteQPR(m_index++) + m_intermediateOffset) ^ 0x5bf03635); }
};

using Perturb = std::function<void(std::vector<uint64_t>&)>;

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
template<class Set, size_t N>
void test(const char* name, Perturb perturb1, Perturb /* perturb2 */)
void test(const char* name, const Perturb& perturb1, const Perturb& /* perturb2 */)
{
// gtl::btree_set<uint64_t> s;
Set s;
Expand All @@ -79,11 +75,11 @@ void test(const char* name, Perturb perturb1, Perturb /* perturb2 */)
for (uint32_t i = 0; i < N; ++i)
s.insert(rsu.next());

std::vector<uint64_t> order(
s.begin(), s.end()); // contains sorted, randomly generated keys (when using gtl::btree_set)
// or keys in the final order of a Set (when using Set).
std::vector<uint64_t> order(s.begin(),
s.end()); // contains sorted, randomly generated keys (when using gtl::btree_set)
// or keys in the final order of a Set (when using Set).

perturb1(order); // either keep them in same order, or shuffle them
perturb1(order); // either keep them in same order, or shuffle them

#if 0
order.resize(N/4);
Expand Down
7 changes: 2 additions & 5 deletions examples/hmap/serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,12 @@ class RSU
m_intermediateOffset = permuteQPR(permuteQPR(seedOffset) + 0x46790905);
}

unsigned int next()
{
return permuteQPR((permuteQPR(m_index++) + m_intermediateOffset) ^ 0x5bf03635);
}
unsigned int next() { return permuteQPR((permuteQPR(m_index++) + m_intermediateOffset) ^ 0x5bf03635); }
};

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
void showtime(const char* name, std::function<void()> doit)
void showtime(const char* name, const std::function<void()>& doit)
{
auto t1 = std::chrono::high_resolution_clock::now();
doit();
Expand Down
8 changes: 4 additions & 4 deletions examples/memoize/mt_memoize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ int main()
double sum = 0;
std::vector<std::future<double>> threads;
gtl::stopwatch<std::milli> sw;
constexpr size_t num_threads = 100;

for (int i = 0; i < 100; i++) {
threads.reserve(num_threads);
for (int i = 0; i < num_threads; i++) {
threads.emplace_back(std::async(simulate)); // new thread
}

for (auto& t : threads) {
sum += t.get(); // sum results from all threads
}

printf("Computed sum = %.3f (expected 24999981374.176) in %10.3f seconds\n",
sum,
sw.since_start() / 1000);
printf("Computed sum = %.3f (expected 24999981374.176) in %10.3f seconds\n", sum, sw.since_start() / 1000);

return 0;
}
8 changes: 4 additions & 4 deletions examples/memoize/mt_memoize_lru.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ int main()
double sum = 0;
std::vector<std::future<double>> threads;
gtl::stopwatch<std::milli> sw;
constexpr size_t num_threads = 100;

for (int i = 0; i < 100; i++) {
threads.reserve(num_threads);
for (int i = 0; i < num_threads; i++) {
threads.emplace_back(std::async(simulate)); // new thread
}

for (auto& t : threads) {
sum += t.get(); // sum results from all threads
}

printf("Computed sum = %.3f (expected 24999981374.176) in %10.3f seconds\n",
sum,
sw.since_start() / 1000);
printf("Computed sum = %.3f (expected 24999981374.176) in %10.3f seconds\n", sum, sw.since_start() / 1000);

return 0;
}
4 changes: 1 addition & 3 deletions examples/misc/intrusive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ int main()
{
{
gtl::intrusive_ptr<A> a = new A;
;

{
auto a2 = a;
gtl::intrusive_ptr<D> d = new D;
gtl::intrusive_ptr<D> d = new D;
{
gtl::intrusive_ptr<A> d2 = d;
}
Expand Down
1 change: 1 addition & 0 deletions examples/phmap/mt_word_counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ int main()

// run 4 threads, each thread processing lines from one of the vectors
// -------------------------------------------------------------------
threads.reserve(num_threads);
for (int i = 0; i < num_threads; ++i) {
threads.emplace_back(
[&word_counts](std::vector<std::string>&& lines) {
Expand Down
34 changes: 0 additions & 34 deletions examples/phmap/pmr.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion include/gtl/phmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ class raw_hash_set
// `that` must be left valid. If Hash is std::function<Key>, moving it
// would create a nullptr functor that cannot be called.
// -------------------------------------------------------------------
settings_(that.settings_)
settings_(std::move(that.settings_))
{
// growth_left was copied above, reset the one from `that`.
that.growth_left() = 0;
Expand Down

0 comments on commit 3e43235

Please sign in to comment.