19[[nodiscard]]
constexpr char ascii_upper(
char c)
noexcept {
20 return (c >=
'a' && c <=
'z') ?
static_cast<char>(c - 32) : c;
22[[nodiscard]]
constexpr char ascii_lower(
char c)
noexcept {
23 return (c >=
'A' && c <=
'Z') ?
static_cast<char>(c + 32) : c;
27[[nodiscard]]
constexpr std::uint64_t
symbol_hash(std::string_view s)
noexcept {
28 std::uint64_t h = 14695981039346656037ULL;
31 h *= 1099511628211ULL;
36[[nodiscard]]
constexpr bool iequals_symbol(std::string_view a, std::string_view b)
noexcept {
37 if (a.size() != b.size())
return false;
38 for (std::size_t i = 0; i < a.size(); ++i) {
46 static constexpr std::size_t
kSlots = 1024;
52 for (Slot& s : slots_) s = Slot{};
53 for (Entry& e : by_id_) e = Entry{};
62 if (!
add(inst.id, inst.venue, inst.symbol.view()))
return false;
68 if (symbol.empty() || symbol.size() > Symbol::kCapacity ||
id.value >=
kMaxInstruments)
70 if (
find(venue, symbol).valid())
return false;
73 std::size_t i =
static_cast<std::size_t
>(h) & (
kSlots - 1);
74 while (slots_[i].used) i = (i + 1) & (
kSlots - 1);
75 slots_[i] = Slot{h, id, venue,
true};
76 Entry& e = by_id_[
id.value];
78 for (std::size_t k = 0; k < symbol.size(); ++k) {
90 std::size_t i =
static_cast<std::size_t
>(h) & (
kSlots - 1);
91 for (std::size_t probes = 0; probes <
kSlots; ++probes) {
92 const Slot& s = slots_[i];
94 if (s.hash == h && s.venue == venue &&
97 i = (i + 1) & (
kSlots - 1);
104 return id.value <
kMaxInstruments && by_id_[
id.value].valid ? by_id_[
id.value].upper.view()
105 : std::string_view{};
109 return id.value <
kMaxInstruments && by_id_[
id.value].valid ? by_id_[
id.value].lower.view()
110 : std::string_view{};
119 [[nodiscard]] std::size_t
size() const noexcept {
return count_; }
123 std::uint64_t hash = 0;
134 std::array<Slot, kSlots> slots_;
135 std::array<Entry, kMaxInstruments> by_id_;
136 std::size_t count_ = 0;
Dense-by-id table built at startup; symbol lookup is a sorted FlatMap keyed by (venue,...
Definition instrument.hpp:141
bool contains(InstrumentId id) const noexcept
Definition symbology.hpp:118
std::string_view lower_symbol(InstrumentId id) const noexcept
Lowercase form used by Binance stream names ("btcusdt\@depth\@100ms").
Definition symbology.hpp:110
InstrumentId find(VenueId venue, std::string_view symbol) const noexcept
Case-insensitive lookup; invalid id when unknown. Hot path: no allocation.
Definition symbology.hpp:90
bool add(InstrumentId id, VenueId venue, std::string_view symbol) noexcept
Definition symbology.hpp:69
std::string_view venue_symbol(InstrumentId id) const noexcept
Canonical (uppercase) venue symbol, e.g. "BTCUSDT"; empty if unknown.
Definition symbology.hpp:105
VenueId venue_of(InstrumentId id) const noexcept
Definition symbology.hpp:114
std::size_t size() const noexcept
Definition symbology.hpp:121
bool build(const InstrumentTable &instruments) noexcept
Registers every instrument of the table.
Definition symbology.hpp:61
static constexpr std::size_t kSlots
>= 4 * kMaxInstruments: load factor <= 0.25
Definition symbology.hpp:48
SymbolTable() noexcept
Definition symbology.hpp:51
void clear() noexcept
Definition symbology.hpp:53
Instrument: the single definition of a tradable contract (5.3 / 5.15).
constexpr bool iequals_symbol(std::string_view a, std::string_view b) noexcept
Definition symbology.hpp:38
constexpr char ascii_upper(char c) noexcept
Definition symbology.hpp:21
constexpr std::uint64_t symbol_hash(std::string_view s) noexcept
FNV-1a over the upper-cased bytes.
Definition symbology.hpp:29
constexpr char ascii_lower(char c) noexcept
Definition symbology.hpp:24
StrongId< struct InstrumentTag, std::uint32_t > InstrumentId
Dense index into the engine's instrument table.
Definition strong_id.hpp:38
constexpr std::size_t kMaxInstruments
Definition instrument.hpp:26
FixedString< 20 > Symbol
Definition instrument.hpp:27
StrongId< struct VenueTag, std::uint8_t > VenueId
Definition strong_id.hpp:39
Strongly typed identifiers.
Definition instrument.hpp:29
static constexpr StrongId invalid() noexcept
Definition strong_id.hpp:30
Rep value
Definition strong_id.hpp:26