* Price levels are computed lazily * Once computed, a price level can be accessed in O(1) * Unit tests piggy back on rigorous existing unit tests in 'synthetic_book_computation' * Not integrated into the matcher, as that is non-trivial work, and the March 2021 roll is fast approaching
51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
#include "MapUtils.h"
|
|
|
|
namespace bts {
|
|
|
|
template <class K, class V>
|
|
inline const V *MapUtils::find_value(
|
|
const std::unordered_map<K, V> &umap, K key) {
|
|
auto it = umap.find(key);
|
|
if (it == umap.end())
|
|
return nullptr;
|
|
return &(it->second);
|
|
}
|
|
|
|
template <class K, class V>
|
|
inline V *MapUtils::find_value(std::unordered_map<K, V> &umap, K key) {
|
|
auto it = umap.find(key);
|
|
if (it == umap.end())
|
|
return nullptr;
|
|
return &(it->second);
|
|
}
|
|
|
|
template <class K, class V>
|
|
inline const V &MapUtils::assert_find_value(const std::unordered_map<K, V> &umap, K key) {
|
|
auto it = umap.find(key);
|
|
bts_assert(it != umap.end());
|
|
return it->second;
|
|
}
|
|
|
|
template <class K, class V>
|
|
inline V &MapUtils::assert_find_value(std::unordered_map<K, V> &umap, K key) {
|
|
auto it = umap.find(key);
|
|
bts_assert(it != umap.end());
|
|
return it->second;
|
|
}
|
|
|
|
template <class K, class V>
|
|
inline const V &MapUtils::assert_find_value(const boost::container::flat_map<K, V> &umap, K key) {
|
|
auto it = umap.find(key);
|
|
bts_assert(it != umap.end());
|
|
return it->second;
|
|
}
|
|
|
|
template <class K, class V>
|
|
inline V &MapUtils::assert_find_value(boost::container::flat_map<K, V> &umap, K key) {
|
|
auto it = umap.find(key);
|
|
bts_assert(it != umap.end());
|
|
return it->second;
|
|
}
|
|
|
|
} // namespace bts
|