5#include <portals/detail/find_model_source.hpp>
6#include <portals/search.hpp>
7#include <portals/worker_storage.hpp>
9#include <memory_resource>
12namespace portals::detail {
14struct SearchBudgetExceeded {};
17class SearchMemory final :
public ProjectionMemory {
19 explicit SearchMemory(std::size_t cap) : cap_(cap) {
22 std::size_t used() const noexcept {
26 std::size_t peak() const noexcept {
30 void chargeExternal(std::size_t bytes)
override;
31 void releaseExternal(std::size_t bytes)
noexcept override;
34 void *do_allocate(std::size_t bytes, std::size_t alignment)
override;
35 void do_deallocate(
void *data, std::size_t bytes, std::size_t alignment)
override;
37 bool do_is_equal(
const std::pmr::memory_resource &other)
const noexcept override {
38 return this == &other;
41 std::size_t cap_{}, used_{}, peak_{};
45 std::uint32_t byteFirst{}, byteCount{};
46 std::uint32_t originalFirst{}, originalLast{};
51 std::uint32_t first{}, count{}, row{};
55struct SearchIndexRow {
57 std::uint32_t textFirst{}, textCount{};
61 std::uint32_t term{}, depth{}, terminalFirst{}, terminalCount{}, childrenFirst{}, childrenCount{};
62 std::uint32_t minLength{}, minOrdinal{};
66class SearchIndex final :
public WorkerStorageValue {
68 SearchIndex(SearchSourceIdentity identity, SearchOptions options);
69 std::size_t bytes() const noexcept;
70 SearchSourceIdentity identity;
71 SearchOptions options;
73 std::pmr::
string original;
74 std::pmr::
string normalized;
75 std::pmr::vector<SearchUnit> units;
76 std::pmr::vector<SearchTerm> terms;
77 std::pmr::vector<SearchIndexRow> rows;
78 std::pmr::vector<SearchNode> nodes;
79 std::pmr::vector<std::uint32_t> children;
82bool validSearchOptions(const SearchOptions &) noexcept;
83std::expected<std::unique_ptr<SearchIndex>, SearchError>
84buildSearchIndex(const FindWorkerSource &, SearchSourceIdentity, SearchOptions, std::stop_token);
85std::expected<std::shared_ptr<const SearchResult>, SearchError>
86querySearchIndex(const SearchIndex &, std::string_view, std::uint64_t generation, std::stop_token);
consteval auto id(StyleState state=StyleState::ANY, bool readOnly=false)
Definition style_static.hpp:865
consteval auto token()
Definition style_static.hpp:814