Slick OrderBook 1.1.0
High-Performance C++23 OrderBook Library
Loading...
Searching...
No Matches
slick::orderbook::detail::LevelContainer Class Reference

Container for storing sorted price levels Uses a sorted vector for cache-friendly storage (optimal for < 100 levels) More...

#include <level_container.hpp>

Collaboration diagram for slick::orderbook::detail::LevelContainer:

Public Types

using value_type = PriceLevelL2
 
using iterator = typename std::vector< PriceLevelL2 >::iterator
 
using const_iterator = typename std::vector< PriceLevelL2 >::const_iterator
 
using Comparator = std::function< bool(const PriceLevelL2 &, const PriceLevelL2 &)>
 

Public Member Functions

 LevelContainer ()
 Default constructor (for array initialization on MSVC)
 
 LevelContainer (Side side, std::size_t initial_capacity=32)
 Constructor with side and initial capacity.
 
Side side () const noexcept
 Get Side.
 
std::size_t size () const noexcept
 Get number of levels.
 
bool empty () const noexcept
 Check if empty.
 
const PriceLevelL2 & operator[] (std::size_t index) const noexcept
 Get level at index (no bounds checking)
 
const PriceLevelL2 & at (std::size_t index) const
 Get level at index with bounds checking.
 
const PriceLevelL2 * best () const noexcept
 Get best level (first element)
 
iterator find (Price price) noexcept
 Find level by price (binary search) Returns iterator to level with matching price, or end() if not found.
 
const_iterator find (Price price) const noexcept
 Find level by price (binary search, const version)
 
const PriceLevelL2 * getLevel (Price price) const noexcept
 Get level by price (returns pointer or nullptr)
 
std::pair< iterator, bool > insertOrUpdate (Price price, Quantity quantity, Timestamp timestamp)
 Insert or update a level If price exists, updates quantity; otherwise inserts new level Returns iterator to the level and whether insertion occurred.
 
bool erase (Price price) noexcept
 Remove level by price Returns true if level was found and removed.
 
iterator erase (iterator it) noexcept
 Remove level by iterator.
 
void clear () noexcept
 Clear all levels.
 
void reserve (std::size_t capacity)
 Reserve capacity.
 
std::size_t capacity () const noexcept
 Get capacity.
 
std::vector< PriceLevelL2 > getLevels (std::size_t depth=0) const
 Get all levels up to depth.
 
iterator begin () noexcept
 Iterators.
 
iterator end () noexcept
 
const_iterator begin () const noexcept
 
const_iterator end () const noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator cend () const noexcept
 

Detailed Description

Container for storing sorted price levels Uses a sorted vector for cache-friendly storage (optimal for < 100 levels)

The container is configured at construction time to sort either as bids (descending) or asks (ascending), allowing use in std::array for O(1) side indexing.

Definition at line 20 of file level_container.hpp.

Member Typedef Documentation

◆ Comparator

Definition at line 25 of file level_container.hpp.

◆ const_iterator

using slick::orderbook::detail::LevelContainer::const_iterator = typename std::vector<PriceLevelL2>::const_iterator

Definition at line 24 of file level_container.hpp.

◆ iterator

using slick::orderbook::detail::LevelContainer::iterator = typename std::vector<PriceLevelL2>::iterator

Definition at line 23 of file level_container.hpp.

◆ value_type

Constructor & Destructor Documentation

◆ LevelContainer() [1/2]

slick::orderbook::detail::LevelContainer::LevelContainer ( )
inline

Default constructor (for array initialization on MSVC)

Definition at line 28 of file level_container.hpp.

References slick::orderbook::Buy.

◆ LevelContainer() [2/2]

slick::orderbook::detail::LevelContainer::LevelContainer ( Side  side,
std::size_t  initial_capacity = 32 
)
inlineexplicit

Constructor with side and initial capacity.

Parameters
sideSide (Buy = bids/descending, Sell = asks/ascending)
initial_capacityInitial capacity for levels

Definition at line 33 of file level_container.hpp.

References slick::orderbook::Buy.

Member Function Documentation

◆ at()

const PriceLevelL2 & slick::orderbook::detail::LevelContainer::at ( std::size_t  index) const
inline

Get level at index with bounds checking.

Definition at line 63 of file level_container.hpp.

◆ begin() [1/2]

const_iterator slick::orderbook::detail::LevelContainer::begin ( ) const
inlinenoexcept

Definition at line 163 of file level_container.hpp.

◆ begin() [2/2]

iterator slick::orderbook::detail::LevelContainer::begin ( )
inlinenoexcept

Iterators.

Definition at line 161 of file level_container.hpp.

◆ best()

const PriceLevelL2 * slick::orderbook::detail::LevelContainer::best ( ) const
inlinenoexcept

Get best level (first element)

Definition at line 68 of file level_container.hpp.

◆ capacity()

std::size_t slick::orderbook::detail::LevelContainer::capacity ( ) const
inlinenoexcept

Get capacity.

Definition at line 147 of file level_container.hpp.

◆ cbegin()

const_iterator slick::orderbook::detail::LevelContainer::cbegin ( ) const
inlinenoexcept

Definition at line 165 of file level_container.hpp.

◆ cend()

const_iterator slick::orderbook::detail::LevelContainer::cend ( ) const
inlinenoexcept

Definition at line 166 of file level_container.hpp.

◆ clear()

void slick::orderbook::detail::LevelContainer::clear ( )
inlinenoexcept

Clear all levels.

Definition at line 137 of file level_container.hpp.

◆ empty()

bool slick::orderbook::detail::LevelContainer::empty ( ) const
inlinenoexcept

Check if empty.

Definition at line 53 of file level_container.hpp.

◆ end() [1/2]

const_iterator slick::orderbook::detail::LevelContainer::end ( ) const
inlinenoexcept

Definition at line 164 of file level_container.hpp.

◆ end() [2/2]

iterator slick::orderbook::detail::LevelContainer::end ( )
inlinenoexcept

Definition at line 162 of file level_container.hpp.

◆ erase() [1/2]

iterator slick::orderbook::detail::LevelContainer::erase ( iterator  it)
inlinenoexcept

Remove level by iterator.

Definition at line 132 of file level_container.hpp.

◆ erase() [2/2]

bool slick::orderbook::detail::LevelContainer::erase ( Price  price)
inlinenoexcept

Remove level by price Returns true if level was found and removed.

Definition at line 122 of file level_container.hpp.

◆ find() [1/2]

const_iterator slick::orderbook::detail::LevelContainer::find ( Price  price) const
inlinenoexcept

Find level by price (binary search, const version)

Definition at line 84 of file level_container.hpp.

◆ find() [2/2]

iterator slick::orderbook::detail::LevelContainer::find ( Price  price)
inlinenoexcept

Find level by price (binary search) Returns iterator to level with matching price, or end() if not found.

Definition at line 74 of file level_container.hpp.

◆ getLevel()

const PriceLevelL2 * slick::orderbook::detail::LevelContainer::getLevel ( Price  price) const
inlinenoexcept

Get level by price (returns pointer or nullptr)

Definition at line 94 of file level_container.hpp.

◆ getLevels()

std::vector< PriceLevelL2 > slick::orderbook::detail::LevelContainer::getLevels ( std::size_t  depth = 0) const
inline

Get all levels up to depth.

Parameters
depthMaximum number of levels to return (0 = all)

Definition at line 153 of file level_container.hpp.

◆ insertOrUpdate()

std::pair< iterator, bool > slick::orderbook::detail::LevelContainer::insertOrUpdate ( Price  price,
Quantity  quantity,
Timestamp  timestamp 
)
inline

Insert or update a level If price exists, updates quantity; otherwise inserts new level Returns iterator to the level and whether insertion occurred.

Definition at line 102 of file level_container.hpp.

◆ operator[]()

const PriceLevelL2 & slick::orderbook::detail::LevelContainer::operator[] ( std::size_t  index) const
inlinenoexcept

Get level at index (no bounds checking)

Definition at line 58 of file level_container.hpp.

◆ reserve()

void slick::orderbook::detail::LevelContainer::reserve ( std::size_t  capacity)
inline

Reserve capacity.

Definition at line 142 of file level_container.hpp.

◆ side()

Side slick::orderbook::detail::LevelContainer::side ( ) const
inlinenoexcept

Get Side.

Definition at line 43 of file level_container.hpp.

◆ size()

std::size_t slick::orderbook::detail::LevelContainer::size ( ) const
inlinenoexcept

Get number of levels.

Definition at line 48 of file level_container.hpp.


The documentation for this class was generated from the following file: