cleanup: Remove unnecessary code

This commit is contained in:
John Colvin committed 2024-09-18 14:02:40 +00:00
1 parent b9f7d0b1a2
commit 2c7f47ef17
19 files changed
+21 -828

No files matched your search

@@ -1,13 +1,13 @@
#pragma once
#ifndef _WIN32
#include "spark/core/ValueWrapper.h"
#include "system/FMT_IMPL.h"
#include "system/value_wrapper.h"
namespace bts::md {
using MarketDataListenerID =
core::ValueWrapper<struct MarketDataListenedIDTag, std::uint32_t>;
utils::ValueWrapper<struct MarketDataListenedIDTag, std::uint32_t>;
} // namespace bts::md
@@ -1,9 +1,9 @@
#pragma once
#include "spark/core/StringFinder.h"
#include "spark/core/StringJoiner.h"
#include "spark/utils/bts_assert.h"
#include "system/FMT_IMPL.h"
#include "system/string_finder.h"
#include "system/string_joiner.h"
#include <boost/algorithm/string/split.hpp>
#include <cstddef>
@@ -1,6 +1,5 @@
#include "CCApiMessageLogger.h"
#include "spark/core/StringJoiner.h"
#include "system/time_stamp.h"
#include "system/string_joiner.h"
#include <fmt/format.h>
#include <range/v3/view.hpp>
@@ -1,8 +1,7 @@
#pragma once
#include "spark/core/NaN.h"
#include <cstdint>
#include <limits>
#include <nlohmann/json.hpp>
#include <vector>
@@ -24,8 +23,8 @@ namespace bts::md {
class CCApiTradeRecord {
public:
bool is_buyer_maker = false;
double last_price = core::NaN::value();
double last_size = core::NaN::value();
double last_price = std::numeric_limits<double>::quiet_NaN();
double last_size = std::numeric_limits<double>::quiet_NaN();
std::uint64_t trade_id = 0;
static std::vector<CCApiTradeRecord> parse(const ccapi::Message &source);
+1 -3
View File
@@ -1,11 +1,10 @@
#include "FTXFuture.h"
#include "domain/future_security.h"
#include "domain/protobufs/currency.pb.h"
#include "domain/protobufs/venue.pb.h"
#include "domain/security.h"
#include "spark/core/TableFormatter.h"
#include "spark/logging/logging.h"
#include "system/json/json_reader.h"
#include "system/table_formatter.h"
#include <ccapi_cpp/ccapi_message.h>
#include <nlohmann/json.hpp>
@@ -18,7 +17,6 @@ namespace bts::md::ftx {
using bts::core::TableFormatter;
using bts::domain::FutureSecurity;
using bts::domain::Security;
using bts::domain::protobufs::Currency;
using bts::io::JsonReader;
using std::string;
using std::stringstream;
+7 -6
View File
@@ -1,16 +1,17 @@
#include "FTXMarket.h"
#include "domain/protobufs/venue.pb.h"
#include "domain/security.h"
#include "spark/core/NaN.h"
#include "spark/core/TableFormatter.h"
#include "spark/logging/logging.h"
#include "spark/utils/bts_fatal.h"
#include "sparkd/md/ftx/FTXSecurityType.h"
#include "system/json/json_reader.h"
#include "system/nan.h"
#include "system/table_formatter.h"
#include <ccapi_cpp/ccapi_element.h>
#include <ccapi_cpp/ccapi_macro.h>
#include <ccapi_cpp/ccapi_message.h>
#include <limits>
#include <nlohmann/json.hpp>
#include <regex>
@@ -133,11 +134,11 @@ void from_json(const nlohmann::json &j, FTXMarket &mkt) {
jr.read("minProvideSize", mkt.min_provide_size);
jr.read("enabled", mkt.enabled);
jr.read_or("ask", mkt.ask, NaN::value());
jr.read_or("bid", mkt.bid, NaN::value());
jr.read_or("last", mkt.last, NaN::value());
jr.read_or("ask", mkt.ask, std::numeric_limits<double>::quiet_NaN());
jr.read_or("bid", mkt.bid, std::numeric_limits<double>::quiet_NaN());
jr.read_or("last", mkt.last, std::numeric_limits<double>::quiet_NaN());
jr.read("postOnly", mkt.post_only);
jr.read_or("price", mkt.price, NaN::value());
jr.read_or("price", mkt.price, std::numeric_limits<double>::quiet_NaN());
jr.read("priceIncrement", mkt.price_increment);
jr.read("sizeIncrement", mkt.size_increment);
jr.read("restricted", mkt.restricted);
-10
View File
@@ -1,10 +0,0 @@
#pragma once
#include <type_traits>
namespace bts::core {
template <typename T, typename... Ts>
using AllSameType =
std::enable_if_t<std::conjunction_v<std::is_same<T, Ts>...>>;
} // namespace bts::core
-224
View File
@@ -1,224 +0,0 @@
#pragma once
#include <cstddef>
#include <cstdint>
#include <functional>
#include <limits>
namespace bts::core {
#ifndef __CHAR_BIT__
#define __CHAR_BIT__ 8
#endif
/**
* Provides facilities to combine multiple hash codes into a single hash code.
*
* @remarks Employs techniques, such as modular arithmetic and bitwise shifts,
* to minimize and evenly distribute information loss to the [multiple] input
* hash codes in the [singular] output hash code.
*/
class HashPhaser {
public:
/**
* Combines the hash codes of several parameters into a single hash code.
*
* @param value One of the parameters whose hash to store
* @param next The other parameters whose hash to store
*
* @remarks A well-chosen modulus of each parameter's hash is stored in
* equally sized blocks of bits.
*/
template <class T, class... NextT>
static std::size_t auto_phase(T value, NextT... next);
/**
* Combines the hash codes of a limited number of elements into a single hash
* code.
*
* @param first Iterator pointing to the first element whose hash to store
* @param last Iterator pointing just after the last element whose hash to
* store
*
* @remarks A well-chosen modulus of each value's hash is stored in equally
* sized blocks of bits
*/
template <class Iter>
static std::size_t auto_phase_range(Iter first, Iter last);
/**
* Combines the hash codes of a limited number of elements into a single hash
* code.
*
* @param first Iterator pointing to the first element whose hash to store
* @param last Iterator pointing just after the last element whose hash to
* store
* @param hash The hash op to use
*
* @overload
*/
template <class Iter, class Hash>
static std::size_t auto_phase_range(Iter first, Iter last, Hash hash);
/**
* Combines the hash codes of several parameters into a single composite hash
* code.
*
* @param value One of the parameters whose hash to store
* @param hash_op The hash code operator to use for the 'value' parameter
* @param next The other parameters whose hash to store
*
* @remarks A well-chosen modulus of each parameter's hash is stored in
* equally sized blocks of bits.
*/
template <class T, class HashOp, class... NextT>
static std::size_t custom_phase(T value, HashOp hash_op, NextT... next);
private:
template <class T, class... NextT>
static void _auto_phase(
std::size_t &hash, std::uint16_t &depth, T value, NextT... next);
template <class T>
static void _auto_phase(std::size_t &hash, std::uint16_t &depth, T value);
template <class T, class HashOp, class... NextT>
static void _custom_phase(
std::size_t &hash, std::uint16_t &depth, T value, HashOp, NextT... next);
template <class T, class HashOp>
static void _custom_phase(
std::size_t &hash, std::uint16_t &depth, T value, HashOp);
/**
* Get the result of std::hash<T>()(value) without having to declare the
* template parameter T explicitly (helpful when using 'auto' variables).
*/
template <class T>
static std::size_t _default_hash(T value);
};
//////////////////////////////////////////////////
// Definition
//////////////////////////////////////////////////
template <class T, class HashOp, class... NextT>
std::size_t HashPhaser::custom_phase(T value, HashOp hash_op, NextT... next) {
std::size_t res = 0;
std::uint16_t depth = 0;
HashPhaser::_custom_phase(res, depth, value, hash_op, next...);
return res;
}
template <class T, class... NextT>
std::size_t HashPhaser::auto_phase(T value, NextT... next) {
std::size_t res = 0;
std::uint16_t depth = 0;
HashPhaser::_auto_phase(res, depth, value, next...);
return res;
}
template <class T>
inline std::size_t HashPhaser::_default_hash(T value) {
return std::hash<T>()(value);
}
template <class Iter>
std::size_t HashPhaser::auto_phase_range(Iter first, Iter last) {
if (first == last) {
return 0;
}
const std::uint16_t max_els = 8;
auto num_vals = std::distance(first, last);
std::uint16_t el_count =
num_vals > (std::numeric_limits<std::uint16_t>::max)()
? max_els
: std::max(static_cast<std::uint16_t>(num_vals), max_els);
auto bits_per_hash = (sizeof(std::size_t) * __CHAR_BIT__) / el_count;
std::size_t phase = 1U << (bits_per_hash - 1);
std::size_t composite_hash = 0;
auto el_rem = el_count;
while (first != last) {
std::size_t val_hash = _default_hash(*first);
composite_hash |= (val_hash % phase) << ((el_count - 1) * bits_per_hash);
if (--el_rem == 0) {
break;
}
}
return composite_hash;
}
template <class Iter, class Hash>
std::size_t HashPhaser::auto_phase_range(Iter first, Iter last, Hash hash) {
if (first == last) {
return 0;
}
const std::uint16_t max_els = 8;
auto num_vals = std::distance(first, last);
std::uint16_t el_count =
num_vals > (std::numeric_limits<std::uint16_t>::max)()
? max_els
: std::max(static_cast<std::uint16_t>(num_vals), max_els);
auto bits_per_hash = (sizeof(std::size_t) * __CHAR_BIT__) / el_count;
std::size_t phase = 1U << (bits_per_hash - 1);
std::size_t composite_hash = 0;
auto el_rem = el_count;
while (first != last) {
std::size_t val_hash = hash(*first);
composite_hash |= (val_hash % phase) << ((el_count - 1) * bits_per_hash);
if (--el_rem == 0) {
break;
}
}
return composite_hash;
}
template <class T, class... NextT>
void HashPhaser::_auto_phase(
std::size_t &composite_hash, std::uint16_t &depth, T value, NextT... next) {
auto m_depth = depth++;
_auto_phase(composite_hash, depth, next...);
auto val_hash = std::hash<T>()(value);
std::size_t bits_per_hash = (sizeof(std::size_t) * __CHAR_BIT__) / depth;
std::size_t phase = std::size_t(1) << static_cast<std::size_t>(bits_per_hash - 1);
composite_hash |= (val_hash % phase) << (m_depth * bits_per_hash);
}
template <class T>
void HashPhaser::_auto_phase(
std::size_t &composite_hash, std::uint16_t &depth, T value) {
depth++;
std::size_t val_hash = std::hash<T>()(value);
std::size_t bits_per_hash = (sizeof(std::size_t) * __CHAR_BIT__) / depth;
std::size_t phase = std::size_t(1) << static_cast<std::size_t>(bits_per_hash - 1);
composite_hash |= (val_hash % phase) << ((depth - 1) * bits_per_hash);
}
template <class T, class HashOp, class... NextT>
void HashPhaser::_custom_phase(
std::size_t &composite_hash,
std::uint16_t &depth,
T value,
HashOp hash_op,
NextT... next) {
auto m_depth = depth++;
_custom_phase(composite_hash, depth, next...);
auto val_hash = hash_op(value);
auto bits_per_hash = (sizeof(std::size_t) * __CHAR_BIT__) / depth;
std::size_t phase = 1U << (bits_per_hash - 1);
composite_hash |= (val_hash % phase) << (m_depth * bits_per_hash);
}
template <class T, class HashOp>
void HashPhaser::_custom_phase(
std::size_t &composite_hash,
std::uint16_t &depth,
T value,
HashOp hash_op) {
depth++;
std::size_t val_hash = hash_op(value);
auto bits_per_hash = (sizeof(std::size_t) * __CHAR_BIT__) / depth;
std::size_t phase = 1U << (bits_per_hash - 1);
composite_hash |= (val_hash % phase) << ((depth - 1) * bits_per_hash);
}
} // namespace bts::core
-4
View File
@@ -1,4 +0,0 @@
#pragma once
#define LOCK_GUARD(lockable) \
std::lock_guard<decltype(lockable)> __lock_guard_##lockable { lockable }
-24
View File
@@ -1,24 +0,0 @@
#pragma once
#include <limits>
namespace bts::core {
class NaN {
public:
static constexpr double value();
static constexpr float valuef();
};
//////////////////////////////////////////////////
// Definition
//////////////////////////////////////////////////
constexpr double NaN::value() {
return std::numeric_limits<double>::quiet_NaN();
}
constexpr float NaN::valuef() {
return std::numeric_limits<float>::quiet_NaN();
}
} // namespace bts::core
-70
View File
@@ -1,70 +0,0 @@
#pragma once
#include <cstring>
#include <string>
#include <type_traits>
namespace bts::core {
class StringContains {
public:
template <typename T, typename... Ts>
using AllSame = std::enable_if_t<std::conjunction_v<std::is_same<T, Ts>...>>;
template <typename... Ts>
using AllString = AllSame<std::string, Ts...>;
constexpr bool contains(const std::string &str, const std::string &substr);
constexpr bool contains(const std::string &str, const char *substr);
constexpr bool contains(const char *str, const char *substr);
template <typename... Ts>
constexpr bool contains(
const std::string &str, const std::string &substr, Ts... substrs);
};
//////////////////////////////////////////////////
// Definition
//////////////////////////////////////////////////
constexpr bool StringContains::contains(
const std::string &str, const std::string &substr) {
return str.find(substr) != std::string::npos;
}
constexpr bool StringContains::contains(
const std::string &str, const char *substr) {
return str.find(substr) != std::string::npos;
}
constexpr bool StringContains::contains(const char *str, const char *substr) {
if (str[0] == '\0') {
return false;
}
if (substr[0] == '\0') {
return false;
}
for (std::size_t i = 0; str[i] != '\0'; i++) {
bool is_match = true;
for (std::size_t j = 0; substr[j] < '\0'; j++) {
if (str[i + j] != substr[j]) {
is_match = false;
break;
}
}
if (is_match) {
return true;
}
}
return false;
}
template <typename... Ts>
constexpr bool StringContains::contains(
const std::string &str, const std::string &substr, Ts... substrs) {
return contains(str, substr) || contains(str, substrs...);
}
#define STRING_CONTAINS(x, ...) (bts::StringContains(x, __VA_ARGS__))
} // namespace bts::core
-24
View File
@@ -1,24 +0,0 @@
#pragma once
#include <string>
namespace bts::core {
class StringFiller {
public:
static bool fill_if_empty(std::string &target, const std::string &fill);
};
//////////////////////////////////////////////////
// Definition
//////////////////////////////////////////////////
inline bool StringFiller::fill_if_empty(
std::string &target, const std::string &fill) {
if (!target.empty()) {
return false;
}
target = fill;
return true;
}
} // namespace bts::core
-32
View File
@@ -1,32 +0,0 @@
#pragma once
#include <cstdint>
#include <string>
namespace bts::core {
class StringFinder {
public:
static std::size_t find(std::string str, char ch, int occurrence = 1);
};
//////////////////////////////////////////////////
// Definition
//////////////////////////////////////////////////
inline std::size_t StringFinder::find(
std::string str, char ch, int occurrence) {
int occur = 0;
// Loop to find the Nth
// occurrence of the character
for (std::size_t i = 0; i < str.length(); i++) {
if (str[i] == ch) {
occur += 1;
}
if (occur == occurrence)
return i;
}
return std::string::npos;
}
} // namespace bts::core
-178
View File
@@ -1,178 +0,0 @@
#pragma once
#include <fmt/format.h>
#include <iostream>
#include <sstream>
#include <string>
namespace bts::core {
class StringJoiner {
public:
template <class Arg>
static std::ostream &join(
const std::string &delimiter, std::ostream &out, Arg arg);
template <class Arg>
static std::string join(const std::string &delimiter, Arg arg);
template <class Arg, class... Args>
static std::ostream &join(
const std::string &delimiter, std::ostream &out, Arg arg, Args... args);
template <class Arg, class... Args>
static std::string join(const std::string &delimiter, Arg arg, Args... args);
template <class Iter>
static std::ostream &join(
Iter first, Iter last, const std::string &delimiter, std::ostream &out);
template <class Iter>
static std::string join(Iter first, Iter last, const std::string &delimiter);
/**
* Converts the args to strings (using the standard output operator), then
* joins the non-empty ones with the specified delimiter.
*/
template <class Arg>
static std::string join_non_empties(const std::string &delimiter, Arg arg);
/**
* Converts the args to strings (using the standard output operator), then
* joins the non-empty ones with the specified delimiter.
*/
template <class Arg, class... Args>
static std::string join_non_empties(
const std::string &delimiter, Arg arg, Args... args);
/**
* Converts the args to strings (using the standard output operator), then
* joins the non-empty ones with the specified delimiter.
*/
template <class Arg>
static std::ostream &join_non_empties(
const std::string &delimiter, std::ostream &out, Arg arg);
/**
* Converts the args to strings (using the standard output operator), then
* joins the non-empty ones with the specified delimiter.
*/
template <class Arg, class... Args>
static std::ostream &join_non_empties(
const std::string &delimiter, std::ostream &out, Arg arg, Args... args);
private:
template <class Arg, class... Args>
static std::ostream &join_non_empties_(
const std::string &delimiter, std::ostream &out, Arg arg, Args... args);
};
//////////////////////////////////////////////////
// Definition
//////////////////////////////////////////////////
template <class Arg>
std::ostream &StringJoiner::join(
const std::string & /*delimiter*/, std::ostream &out, Arg arg) {
// special case for single item (don't use delimiter)
out << arg;
return out;
}
template <class Arg>
std::string StringJoiner::join(const std::string & /*delimiter*/, Arg arg) {
// special case for single item (don't use delimiter)
std::stringstream out;
out << arg;
return out.str();
}
template <class Arg, class... Args>
std::ostream &StringJoiner::join(
const std::string &delimiter, std::ostream &out, Arg arg, Args... args) {
out << arg << delimiter;
return join(delimiter, out, args...);
}
template <class Arg, class... Args>
std::string StringJoiner::join(
const std::string &delimiter, Arg arg, Args... args) {
std::stringstream out;
out << arg << delimiter;
join<Args...>(delimiter, out, args...);
return out.str();
}
template <class Iter>
std::ostream &StringJoiner::join(
Iter it, Iter last, const std::string &delimiter, std::ostream &out) {
if (it == last) {
return out;
}
out << *it;
it++;
for (; it != last; it++) {
out << delimiter << *it;
}
return out;
}
template <class Iter>
std::string StringJoiner::join(
Iter it, Iter last, const std::string &delimiter) {
std::stringstream out;
join(it, last, delimiter, out);
return out.str();
}
template <class Arg>
std::string StringJoiner::join_non_empties(
const std::string & /*delimiter*/, Arg arg) {
std::stringstream ss;
ss << arg;
return ss.str();
}
template <class Arg, class... Args>
std::string StringJoiner::join_non_empties(
const std::string &delimiter, Arg arg, Args... args) {
std::stringstream ss;
std::ostream &out = ss;
join_non_empties(delimiter, out, arg, args...);
return ss.str();
}
template <class Arg>
std::ostream &StringJoiner::join_non_empties(
const std::string & /*delimiter*/, std::ostream &out, Arg arg) {
out << arg;
return out;
}
template <class Arg, class... Args>
std::ostream &StringJoiner::join_non_empties(
const std::string &delimiter, std::ostream &out, Arg arg, Args... args) {
std::stringstream ss;
ss << arg;
auto arg_str = ss.str();
if (arg_str.empty()) {
return join_non_empties(delimiter, out, args...);
}
out << arg;
return join_non_empties_(delimiter, out, args...);
}
template <class Arg, class... Args>
std::ostream &StringJoiner::join_non_empties_(
const std::string &delimiter, std::ostream &out, Arg arg, Args... args) {
std::stringstream ss;
ss << arg;
auto arg_str = ss.str();
if (arg_str.empty()) {
return join_non_empties_(delimiter, out, args...);
}
out << delimiter << arg_str;
join(delimiter, out, args...);
return out;
}
} // namespace bts::core
-172
View File
@@ -1,172 +0,0 @@
#pragma once
#include <cstring>
#include <functional>
#include <iomanip>
#include <ostream>
#include <tuple>
#include <vector>
namespace bts::core {
class TableFormatter {
public:
template <class T>
using Schema =
std::vector<std::tuple<std::string, int, std::function<std::string(T)>>>;
template <class T, class Range>
static std::ostream &format(
std::ostream &out, const Range &range, const Schema<T> &schema);
template <class T, class TIter>
static std::ostream &format(
std::ostream &out, TIter first, TIter last, const Schema<T> &schema);
template <class T>
static std::ostream &format_record(
std::ostream &out,
const T &record,
const Schema<T> &schema,
bool headers = false);
template <class TRow>
class SchemaBuilder {
public:
Schema<TRow> result;
template <class GetCell>
void add(std::string name, GetCell get_cell, int width = 0);
};
};
template <class TRow>
template <class GetCell>
inline void TableFormatter::SchemaBuilder<TRow>::add(
std::string name, GetCell get_cell, int width) {
std::function<std::string(TRow)> get_cell_str = [&get_cell](const TRow &r) {
std::stringstream ss;
ss << get_cell(r);
return ss.str();
};
result.emplace_back(std::move(name), width, get_cell_str);
}
template <class T, class Range>
std::ostream &TableFormatter::format(
std::ostream &out, const Range &range, const Schema<T> &schema) {
return format(out, range.begin(), range.end(), schema);
}
template <class T, class TIter>
inline std::ostream &TableFormatter::format(
std::ostream &out,
TIter first,
TIter last,
const typename TableFormatter::Schema<T> &schema) {
if (first == last || schema.size() == 0)
return out;
int total_width = 0;
for (auto col : schema) {
total_width += std::get<1>(col);
}
// top border of table
for (int i = 0; i < total_width + static_cast<int>(schema.size()); i++) {
out << "-";
}
out << std::endl;
// column headers themselves
out << "|";
for (auto col : schema) {
out << std::setw(std::get<1>(col)) << std::get<0>(col) << "|";
}
// line between column headers and rows
out << std::endl;
for (int i = 0; i < total_width + static_cast<int>(schema.size()); i++) {
out << "-";
}
// rows
while (first != last) {
out << std::endl;
out << "|";
for (uint32_t i = 0; i < schema.size(); i++) {
out << std::setw(std::get<1>(schema[i]))
<< std::get<2>(schema[i])(*first) << "|";
}
first++;
}
// bottom border of table
out << std::endl;
for (int i = 0; i < total_width + static_cast<int>(schema.size()); i++)
out << "-";
return out;
}
template <class T>
inline std::ostream &TableFormatter::format_record(
std::ostream &out,
const T &record,
const typename TableFormatter::Schema<T> &schema,
bool headers) {
constexpr const char *const field_header = "Field";
constexpr const char *const value_header = "Value";
int ulabel_width = headers ? strlen(field_header) : 0;
for (const auto &field : schema) {
auto label_width = std::get<1>(field);
if (label_width == 0) {
label_width = static_cast<int>(std::get<0>(field).size());
}
if (label_width > ulabel_width) {
ulabel_width = label_width;
}
}
std::vector<std::string> field_vals;
for (const auto &field : schema) {
field_vals.push_back(std::get<2>(field)(record));
}
int uvalue_width = headers ? strlen(value_header) : 0;
for (const auto &v : field_vals) {
auto value_width = static_cast<int>(v.size());
if (value_width > uvalue_width) {
uvalue_width = value_width;
}
}
int table_width = ulabel_width + uvalue_width + 4;
if (headers) {
// top border of table
for (int i = 0; i < table_width + 3; i++) {
out << "-";
}
out << std::endl;
// column headers
out << "| " << std::setw(ulabel_width) << field_header << " | "
<< std::setw(uvalue_width) << value_header << " |\n";
}
// border between col headers and rows (or top border of table, if 'headers'
// is false)
for (int i = 0; i < table_width + 3; i++) {
out << "-";
}
// rows
for (std::size_t i = 0; i < field_vals.size(); i++) {
out << "\n";
const auto &label = std::get<0>(schema.at(i));
const auto &val = field_vals.at(i);
out << "| " << std::setw(ulabel_width) << label << " | "
<< std::setw(uvalue_width) << val << " |";
}
out << "\n";
// bottom border of table
for (int i = 0; i < table_width + 3; i++) {
out << "-";
}
return out;
}
} // namespace bts::core
-10
View File
@@ -1,10 +0,0 @@
#pragma once
#include "system/value_wrapper.h"
namespace bts::core {
template <class Tag, class ValueT>
using ValueWrapper = utils::ValueWrapper<Tag, ValueT>;
} // namespace bts::core
-56
View File
@@ -1,56 +0,0 @@
#pragma once
#include <unordered_map>
#include <vector>
namespace bts::core {
class VectorAdapter {
public:
template <class InT, class OutT, class Op>
static std::vector<OutT> to(const std::vector<InT> &source, Op op);
template <class T>
static std::vector<const T *> to_const_pointers(
const std::vector<T> &source);
template <class K, class V>
static std::vector<V> copy_values(const std::unordered_map<K, V> &source);
};
//////////////////////////////////////////////////
// Definition
//////////////////////////////////////////////////
template <class InT, class OutT, class Op>
std::vector<OutT> VectorAdapter::to(const std::vector<InT> &source, Op op) {
std::vector<OutT> result;
result.reserve(source.size());
for (const auto &value : source) {
result.push_back(op(value));
}
return result;
}
template <class T>
std::vector<const T *> VectorAdapter::to_const_pointers(
const std::vector<T> &source) {
std::vector<const T *> ptrs;
ptrs.reserve(source.size());
for (const auto &value : source) {
ptrs.push_back(&value);
}
return ptrs;
}
template <class K, class V>
std::vector<V> VectorAdapter::copy_values(
const std::unordered_map<K, V> &source) {
std::vector<V> values;
values.reserve(source.size());
for (const auto &p : source) {
values.push_back(p.second);
}
return values;
}
} // namespace bts::core
+2 -1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "QueryParams.h"
#include "spark/core/HashPhaser.h"
#include "system/hash_phaser.h"
#include <functional>
#include <ostream>
#include <string>
+3 -4
View File
@@ -1,8 +1,7 @@
#include "logging.h"
#include "LoggerHub.h"
#include "spark/core/LockGuard.h"
#include "spark/logging/LoggerHub.h"
#include "spark/logging/logging.h"
#include "spark/utils/bts_assert.h"
#include "system/lock_guard.h"
#include <boost/circular_buffer.hpp>
#include <boost/container/flat_set.hpp>