Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/source/pine_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30298,6 +30298,8 @@ std::array<std::uint64_t, 3> PineExecutionAdapter::retirement_validation_state()
#endif
} // namespace pineforge::source

#include "pine_adapter_probe.hpp"

namespace pineforge::source::detail {

CohortExposureFold fold_cohort_exposure(
Expand Down Expand Up @@ -30452,4 +30454,21 @@ void verify_cohort_exposure(
}
#endif

LookupIndexCounts probe_lookup_index(const NativeHostCache* cache) noexcept {
if (cache == nullptr || typeid(*cache) != typeid(AdapterLookupIndex)) return {};
const auto& index = static_cast<const AdapterLookupIndex&>(*cache);
LookupIndexCounts counts{true, index.cohort_sides.size(), index.unbound.size()};
std::size_t kind = 0;
for (const auto& by_origin : index.legs_by_origin) {
counts.legs_by_origin_keys[kind] = by_origin.size();
for (const auto& row : by_origin)
counts.legs_by_origin_ids[kind] += row.second.size();
++kind;
}
counts.immediate_closes_keys = index.immediate_closes_by_bar.size();
for (const auto& row : index.immediate_closes_by_bar)
counts.immediate_closes_ids += row.second.size();
return counts;
}

} // namespace pineforge::source::detail
25 changes: 25 additions & 0 deletions src/source/pine_adapter_probe.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include "pine_host_reads.hpp"

#include <array>
#include <cstddef>

namespace pineforge::source::detail {

// Pure reader: no unordered-map operator[], only size() and iteration over
// values into std::array counters. No allocation, no mutation, nothing hashed.
// The three slots are ExitLimit, ExitStop and ExitTrail, in that order.
struct LookupIndexCounts {
bool present = false;
std::size_t cohort_sides = 0;
std::size_t unbound = 0;
std::array<std::size_t, 3> legs_by_origin_keys{};
std::array<std::size_t, 3> legs_by_origin_ids{};
std::size_t immediate_closes_keys = 0;
std::size_t immediate_closes_ids = 0;
};

LookupIndexCounts probe_lookup_index(const NativeHostCache* cache) noexcept;

} // namespace pineforge::source::detail
4 changes: 4 additions & 0 deletions tests/cr150.d/adapter-lookup-index-counts.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if(PINEFORGE_BUILD_SOURCE_LAYER)
list(APPEND TEST_SOURCES test_adapter_lookup_index_counts)
pineforge_add_unit_test(test_adapter_lookup_index_counts)
endif()
Loading
Loading