From e1d66e9a0ecbd6929de2d175656a4cc5058c8ee8 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 15 Jun 2022 13:23:08 -0400 Subject: [PATCH] chore (linux build): Add benign changes to satisfy clang13 --- src/lib/api/public/ClientChannel.h | 3 ++- src/lib/logging/Common.h | 1 + src/lib/md/MBOProcessor.cpp | 3 --- src/lib/md/test/mbo_tests.cpp | 14 +++++++---- src/lib/md/test/md2_tests.cpp | 3 ++- .../algo/algo_orders/MomentumRecorder.cpp | 8 +++---- .../spreader_orders/tests/spreader_tests.cpp | 2 ++ src/lib/utils/Shuffle.h | 24 +++++++++++++++++++ 8 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 src/lib/utils/Shuffle.h diff --git a/src/lib/api/public/ClientChannel.h b/src/lib/api/public/ClientChannel.h index f00ec779c..bd0ac6144 100644 --- a/src/lib/api/public/ClientChannel.h +++ b/src/lib/api/public/ClientChannel.h @@ -99,7 +99,8 @@ public: std::vector added_keys, changed_keys, removed_keys; - for (size_t x = 0; x < change_count; ++x) { + for (std::size_t x = 0; + x < static_cast(change_count); ++x) { const StreamUpdate& change = changes[x]; switch(change.type) { case StreamUpdate::REMOVE: diff --git a/src/lib/logging/Common.h b/src/lib/logging/Common.h index 02650df87..eb2e36727 100644 --- a/src/lib/logging/Common.h +++ b/src/lib/logging/Common.h @@ -6,6 +6,7 @@ #include #include #include +#include namespace bts { namespace log { diff --git a/src/lib/md/MBOProcessor.cpp b/src/lib/md/MBOProcessor.cpp index 95aad0ff4..908edd8e3 100644 --- a/src/lib/md/MBOProcessor.cpp +++ b/src/lib/md/MBOProcessor.cpp @@ -45,9 +45,6 @@ void print_pool_stats(const utils::ConcurrentPool& pool) { std::sort(bid_sz.begin(), bid_sz.end()); std::sort(ask_sz.begin(), ask_sz.end()); - size_t bid_tot =0, ask_tot = 0; - for(size_t i : bid_sz) { bid_tot += i; } - for(size_t i : ask_sz) { ask_tot += i; } std::stringstream bid_percentiles, ask_percentiles; for (double x : { 0.5, 0.75, 0.9, 0.95, 0.99 }) { diff --git a/src/lib/md/test/mbo_tests.cpp b/src/lib/md/test/mbo_tests.cpp index 69abb194e..e8c2bca59 100644 --- a/src/lib/md/test/mbo_tests.cpp +++ b/src/lib/md/test/mbo_tests.cpp @@ -3,6 +3,7 @@ #include "../IntPrice.h" #include "../MBOProcessor.h" #include "Co2TestInstrument.h" +#include "lib/utils/Shuffle.h" #include #include @@ -54,7 +55,7 @@ std::vector gen_test_orders(uint64_t id=100, inc::UpdateType type=i // std::cout << std::endl << order_id.value() << ": " << price.price() << "-" << size; } } - std::random_shuffle(result.begin(), result.end()); + utils::Shuffle::shuffle(result.begin(), result.end()); return result; } @@ -105,7 +106,7 @@ TEST_CASE("MBO incremental", "[md][mbo]") { concat( gen_test_orders(128, inc::UpdateType::Bid), gen_test_orders(256, inc::UpdateType::Ask)); - std::random_shuffle(orders.begin(), orders.end()); + utils::Shuffle::shuffle(orders.begin(), orders.end()); apply_incremental(state, orders); REQUIRE(state.bid.size() + state.ask.size() == orders.size()); @@ -188,7 +189,8 @@ TEST_CASE("MBO sort order", "[md][mbo]") { }); } } - std::random_shuffle(updates.begin(), updates.end()); + std::random_device rd; + std::shuffle(updates.begin(), updates.end(), std::mt19937(rd())); apply_incremental(state, updates); @@ -316,5 +318,7 @@ TEST_CASE("MBO change price and size", "[md][mbo]") { REQUIRE(!not_ask); } -}}} -#endif \ No newline at end of file +} // namespace test +} // namespace md +} // namespace bts +#endif diff --git a/src/lib/md/test/md2_tests.cpp b/src/lib/md/test/md2_tests.cpp index 78dd6a63d..58c07f572 100644 --- a/src/lib/md/test/md2_tests.cpp +++ b/src/lib/md/test/md2_tests.cpp @@ -13,6 +13,7 @@ #include "lib/utils/bts_chrono.h" #include "lib/utils/defer.h" #include "lib/utils/warn_ctrl.h" +#include "lib/utils/Shuffle.h" #include "lib/config/protos/MarketData.pb.h" #include "lib/utils/Sqlite_utils.h" @@ -1217,7 +1218,7 @@ struct Co2IndexTests { template void test_random_search(Index &index) { vector temp(random_ids); - std::random_shuffle(temp.begin(), temp.end()); + utils::Shuffle::shuffle(temp.begin(), temp.end()); for (auto &id : temp) { if (used_ids.find(id) != used_ids.end()) { REQUIRE(index.has_security(id)); diff --git a/src/lib/orderman/orders/algo/algo_orders/MomentumRecorder.cpp b/src/lib/orderman/orders/algo/algo_orders/MomentumRecorder.cpp index b2e1151eb..060c1b061 100644 --- a/src/lib/orderman/orders/algo/algo_orders/MomentumRecorder.cpp +++ b/src/lib/orderman/orders/algo/algo_orders/MomentumRecorder.cpp @@ -67,10 +67,10 @@ struct MomentumRecorderParams { while (ss.good()) { string substr; getline(ss, substr, ','); - substr.erase( - substr.begin(), - std::find_if(substr.begin(), substr.end(), - std::bind1st(std::not_equal_to(), ' '))); + substr.erase(substr.begin(), + std::find_if(substr.begin(), substr.end(), + std::bind(std::not_equal_to(), ' ', + std::placeholders::_1))); security_name_strs.insert(prefix + substr); } } catch (...) { diff --git a/src/lib/orderman/orders/spreader_orders/tests/spreader_tests.cpp b/src/lib/orderman/orders/spreader_orders/tests/spreader_tests.cpp index a3e76866c..b08078932 100644 --- a/src/lib/orderman/orders/spreader_orders/tests/spreader_tests.cpp +++ b/src/lib/orderman/orders/spreader_orders/tests/spreader_tests.cpp @@ -1,4 +1,5 @@ #include "lib/orderman/orders/spreader_orders/tests/tests_common.h" +#include "lib/utils/helper_macros.h" #include #include @@ -150,6 +151,7 @@ TEST_CASE ("quoter price quantity state", "[spreader]") for(uint32_t i=0; i128) sum+=arr[i]; + UNUSED(sum); std::cout << "br pred (sorted) " << (utils::TimeStamp::now()-t0).nanoseconds() << " ns" << std::endl; // for(uint32_t i=0; i +#include + +namespace bts::utils { + +class Shuffle { + public: + template + static void shuffle(Iter first, Iter last); +}; + +////////////////////////////////////////////////// +// Definition +////////////////////////////////////////////////// + +template +void Shuffle::shuffle(Iter first, Iter last) { + std::random_device rd; + std::mt19937 g(rd()); + std::shuffle(first, last, g); +} + +} // namespace bts::utils