Add "clear" fn to Book & BookSide

Prelude to python market data bindings
This commit is contained in:
John Colvin committed 2025-06-04 04:37:02 +00:00
1 parent 1849d875b1
commit 82b8224416
2 files changed
+24

No files matched your search

+18
View File
@@ -19,6 +19,13 @@ class BookT {
[[nodiscard]] static constexpr size_t max_depth();
[[nodiscard]] constexpr std::size_t size() const noexcept;
/**
* @brief Gets the number of price levels with non-zero quantities (the sum of such levels on
* both sides of the market, bids and asks).
*
* @return constexpr std::size_t The number of price levels with non-zero quantities
*/
[[nodiscard]] std::size_t count_populated() const noexcept;
[[nodiscard]] constexpr BS &bids() noexcept;
[[nodiscard]] constexpr const BS &bids() const noexcept;
@@ -34,6 +41,7 @@ class BookT {
template <class OtherBook>
void merge_with(OtherBook const &b);
void clear();
void clear_to_end(std::size_t level = 0);
void clear_after_empty();
[[nodiscard]] bool is_sorted() const;
@@ -98,6 +106,11 @@ constexpr std::size_t BookT<BS>::size() const noexcept {
return _books.size();
}
template <class BS>
std::size_t BookT<BS>::count_populated() const noexcept {
return _books[0].count_populated() + _books[1].count_populated();
}
template <class BS>
constexpr BS &BookT<BS>::bids() noexcept {
return _books[Side::Buy];
@@ -184,6 +197,11 @@ void BookT<BS>::remove_crosses(Side dominant_side) {
dominant_side.other(), (*this)[dominant_side][0].price);
}
template <class BS>
void BookT<BS>::clear() {
Side::foreach ([&](Side s) { operator[](s).clear(); });
}
template <class BS>
void BookT<BS>::clear_to_end(std::size_t level) {
Side::foreach ([&](Side s) {
+6
View File
@@ -120,6 +120,7 @@ class BookSideT {
[[nodiscard]] Quantity intersecting_front_quantity(
const OtherBookSide &other, std::size_t num_levels = max_depth()) const;
void clear();
void clear_to_end(std::uint8_t level = 0);
void clear_after_empty();
@@ -592,6 +593,11 @@ Quantity BookSideT<SZ>::intersecting_front_quantity(
return ifq;
}
template <std::size_t SZ>
void BookSideT<SZ>::clear() {
clear_to_end(0);
}
template <std::size_t SZ>
void BookSideT<SZ>::clear_to_end(std::uint8_t level) {
static_assert(SZ <= std::numeric_limits<std::uint8_t>::max());