diff --git a/core/analysis/minhash_token_stream.cpp b/core/analysis/minhash_token_stream.cpp index d5e89a67a..0dc26ef86 100644 --- a/core/analysis/minhash_token_stream.cpp +++ b/core/analysis/minhash_token_stream.cpp @@ -40,9 +40,9 @@ namespace { // That is important because produced tokens are stored in the index as terms. // Some primes between 2^63 and 2^64 for various uses. -static const uint64_t k0 = 0xc3a5c85c97cb3127ULL; -static const uint64_t k1 = 0xb492b66fbe98f273ULL; -static const uint64_t k2 = 0x9ae16a3b2f90404fULL; +static constexpr uint64_t k0 = 0xc3a5c85c97cb3127ULL; +static constexpr uint64_t k1 = 0xb492b66fbe98f273ULL; +static constexpr uint64_t k2 = 0x9ae16a3b2f90404fULL; #ifdef ABSL_IS_BIG_ENDIAN #define uint32_in_expected_order(x) (absl::gbswap_32(x)) @@ -467,17 +467,11 @@ bool MinHashTokenStream::next() { return false; } - const size_t value = [value = *begin_]() noexcept -> size_t { - if constexpr (is_big_endian()) { - return absl::gbswap_64(value); - } else { - return value; - } - }(); + const auto value = absl::little_endian::FromHost(*begin_); [[maybe_unused]] const size_t length = absl::strings_internal::Base64EscapeInternal( - reinterpret_cast(&value), sizeof value, buf_.data(), + reinterpret_cast(&value), sizeof value, buf_.data(), buf_.size(), absl::strings_internal::kBase64Chars, false); IRS_ASSERT(length == buf_.size()); @@ -510,7 +504,7 @@ void MinHashTokenStream::ComputeSignature() { do { const std::string_view value = ViewCast(term_->value); - const size_t hash_value = ::CityHash64(value.data(), value.size()); + const auto hash_value = ::CityHash64(value.data(), value.size()); minhash_.Insert(hash_value); end = offs->end; diff --git a/core/analysis/minhash_token_stream.hpp b/core/analysis/minhash_token_stream.hpp index 72e80d62d..131e4f21b 100644 --- a/core/analysis/minhash_token_stream.hpp +++ b/core/analysis/minhash_token_stream.hpp @@ -67,7 +67,7 @@ class MinHashTokenStream final : public TypedAnalyzer, private: using attributes = std::tuple; - using iterator = std::vector::const_iterator; + using iterator = std::vector::const_iterator; void ComputeSignature(); diff --git a/core/error/error.hpp b/core/error/error.hpp index 8bb8d9da8..745a7d544 100644 --- a/core/error/error.hpp +++ b/core/error/error.hpp @@ -46,8 +46,8 @@ enum class ErrorCode : uint32_t { undefined_error }; -#define DECLARE_ERROR_CODE(class_name) \ - static const ErrorCode CODE = ErrorCode::class_name; \ +#define DECLARE_ERROR_CODE(class_name) \ + static constexpr ErrorCode CODE = ErrorCode::class_name; \ ::irs::ErrorCode code() const noexcept final { return CODE; } ////////////////////////////////////////////////////////////////////////////// diff --git a/core/formats/columnstore.cpp b/core/formats/columnstore.cpp index 0a7e91611..f522683ed 100644 --- a/core/formats/columnstore.cpp +++ b/core/formats/columnstore.cpp @@ -460,7 +460,7 @@ namespace columnstore { template class index_block { public: - static const size_t SIZE = Size; + static constexpr size_t SIZE = Size; void push_back(doc_id_t key, uint64_t offset) noexcept { IRS_ASSERT(key_ >= keys_); diff --git a/core/formats/columnstore2.cpp b/core/formats/columnstore2.cpp index 00bf5a116..d9c200315 100644 --- a/core/formats/columnstore2.cpp +++ b/core/formats/columnstore2.cpp @@ -1705,7 +1705,7 @@ const column_header* reader::header(field_id field) const { : columns_[field]; if (column) { - return &down_cast(*column).header(); + return &DownCast(*column).header(); } return nullptr; diff --git a/core/formats/formats.hpp b/core/formats/formats.hpp index f7a3f7304..8c100179f 100644 --- a/core/formats/formats.hpp +++ b/core/formats/formats.hpp @@ -144,8 +144,8 @@ struct field_writer { }; struct WandInfo { - byte_type mapped_index{WandContext::kDisable}; - byte_type count{0}; + uint8_t mapped_index{WandContext::kDisable}; + uint8_t count{0}; }; struct postings_reader { @@ -171,7 +171,7 @@ struct postings_reader { virtual doc_iterator::ptr iterator(IndexFeatures field_features, IndexFeatures required_features, const term_meta& meta, - byte_type wand_count) = 0; + uint8_t wand_count) = 0; virtual doc_iterator::ptr wanderator(IndexFeatures field_features, IndexFeatures required_features, @@ -187,7 +187,7 @@ struct postings_reader { // This API is experimental. virtual size_t bit_union(IndexFeatures field_features, const term_provider_f& provider, size_t* set, - byte_type wand_count) = 0; + uint8_t wand_count) = 0; }; // Expected usage pattern of seek_term_iterator @@ -252,7 +252,7 @@ struct term_reader : public attribute_provider { virtual bytes_view(max)() const = 0; // Returns true if scorer denoted by the is supported by the field. - virtual bool has_scorer(byte_type index) const = 0; + virtual bool has_scorer(uint8_t index) const = 0; }; struct field_reader { diff --git a/core/formats/formats_10.cpp b/core/formats/formats_10.cpp index b70eb4cf5..76e37bb20 100644 --- a/core/formats/formats_10.cpp +++ b/core/formats/formats_10.cpp @@ -675,7 +675,7 @@ void postings_writer_base::EndTerm(version10::term_meta& meta) { const bool has_skip_list = skip_.Skip0() < meta.docs_count; auto write_max_score = [&](size_t level) { ApplyWriters([&](auto& writer) { - const byte_type size = writer.SizeRoot(level); + const uint8_t size = writer.SizeRoot(level); doc_out_->write_byte(size); }); ApplyWriters([&](auto& writer) { writer.WriteRoot(level, *doc_out_); }); @@ -1000,7 +1000,7 @@ void postings_writer::write(irs::doc_iterator& docs, // FIXME(gnusi): optimize for 1 writer case? compile? maybe just 1 // composite wand writer? ApplyWriters([&](auto& writer) { - const byte_type size = writer.Size(level); + const uint8_t size = writer.Size(level); IRS_ASSERT(size <= irs::WandWriter::kMaxSize); out.write_byte(size); }); @@ -1928,24 +1928,24 @@ void single_doc_iterator::prepare( static_assert(kMaxScorers < WandContext::kDisable); -template +template struct Extent { - static constexpr byte_type GetExtent() noexcept { return Value; } + static constexpr uint8_t GetExtent() noexcept { return Value; } }; template<> struct Extent { - Extent(byte_type value) noexcept : value{value} {} + Extent(uint8_t value) noexcept : value{value} {} - constexpr byte_type GetExtent() const noexcept { return value; } + constexpr uint8_t GetExtent() const noexcept { return value; } - byte_type value; + uint8_t value; }; using DynamicExtent = Extent; -template -auto ResolveExtent(byte_type extent, Func&& func) { +template +auto ResolveExtent(uint8_t extent, Func&& func) { if constexpr (PossibleMin == WandContext::kDisable) { return std::forward(func)(Extent<0>{}); } else { @@ -1985,7 +1985,7 @@ void CommonSkipWandData(WandExtent extent, index_input& in) { } template -void CommonReadWandData(WandExtent wextent, byte_type index, +void CommonReadWandData(WandExtent wextent, uint8_t index, const ScoreFunction& func, WandSource& ctx, index_input& in, score_t& score) { const auto extent = wextent.GetExtent(); @@ -1998,7 +1998,7 @@ void CommonReadWandData(WandExtent wextent, byte_type index, return; } - byte_type i = 0; + uint8_t i = 0; uint64_t scorer_offset = 0; for (; i < index; ++i) { scorer_offset += in.read_byte(); @@ -2043,7 +2043,7 @@ class doc_iterator : public doc_iterator_base { void WandPrepare(const term_meta& meta, const index_input* doc_in, const index_input* pos_in, const index_input* pay_in, const ScoreFunctionFactory& factory, const Scorer& scorer, - byte_type wand_index) { + uint8_t wand_index) { prepare(meta, doc_in, pos_in, pay_in, wand_index); if (meta.docs_count > FieldTraits::block_size()) { return; @@ -2073,7 +2073,7 @@ class doc_iterator : public doc_iterator_base { void prepare(const term_meta& meta, const index_input* doc_in, [[maybe_unused]] const index_input* pos_in, [[maybe_unused]] const index_input* pay_in, - byte_type wand_index = WandContext::kDisable); + uint8_t wand_index = WandContext::kDisable); private: attribute* get_mutable(irs::type_info::type_id type) noexcept final { @@ -2138,8 +2138,8 @@ class doc_iterator : public doc_iterator_base { Disable(); // Prevent using skip-list by default } - void ReadMaxScore(byte_type index, const ScoreFunction& func, - WandSource& ctx, index_input& in, score_t& score) { + void ReadMaxScore(uint8_t index, const ScoreFunction& func, WandSource& ctx, + index_input& in, score_t& score) { CommonReadWandData(static_cast(*this), index, func, ctx, in, score); } @@ -2246,7 +2246,7 @@ template void doc_iterator::prepare( const term_meta& meta, const index_input* doc_in, [[maybe_unused]] const index_input* pos_in, - [[maybe_unused]] const index_input* pay_in, byte_type wand_index) { + [[maybe_unused]] const index_input* pay_in, uint8_t wand_index) { // Don't use doc_iterator for singleton docs, must be ensured by the caller IRS_ASSERT(meta.docs_count > 1); IRS_ASSERT(this->begin_ == std::end(this->buf_.docs)); @@ -2452,7 +2452,7 @@ class wanderator : public doc_iterator_base, using ptr = memory::managed_ptr; wanderator(const ScoreFunctionFactory& factory, const Scorer& scorer, - WandExtent extent, byte_type index, bool strict) + WandExtent extent, uint8_t index, bool strict) : skip_{IteratorTraits::block_size(), postings_writer_base::kSkipN, ReadSkip{factory, scorer, index, extent}}, scorer_{factory(*this)} { @@ -2503,7 +2503,7 @@ class wanderator : public doc_iterator_base, class ReadSkip { public: ReadSkip(const ScoreFunctionFactory& factory, const Scorer& scorer, - byte_type index, WandExtent extent) + uint8_t index, WandExtent extent) : ctx_{scorer.prepare_wand_source()}, func_{factory(*ctx_)}, index_{index}, @@ -2551,7 +2551,7 @@ class wanderator : public doc_iterator_base, std::vector skip_scores_; SkipState prev_skip_; // skip context used by skip reader score_t threshold_{}; - byte_type index_; + uint8_t index_; IRS_NO_UNIQUE_ADDRESS WandExtent extent_; }; @@ -2903,7 +2903,7 @@ bool IndexMetaWriter::prepare(directory& dir, IndexMeta& meta, if (version_ > kFormatMin) { const auto payload = GetPayload(meta); - const byte_type flags = IsNull(payload) ? 0 : kHasPayload; + const uint8_t flags = IsNull(payload) ? 0 : kHasPayload; out->write_byte(flags); if (flags == kHasPayload) { @@ -3121,7 +3121,7 @@ void SegmentMetaWriter::write(directory& dir, std::string& meta_file, throw io_error{absl::StrCat("failed to create file, path: ", meta_file)}; } - byte_type flags = meta.column_store ? HAS_COLUMN_STORE : 0; + uint8_t flags = meta.column_store ? HAS_COLUMN_STORE : 0; format_utils::write_header(*out, FORMAT_NAME, version_); write_string(*out, meta.name); @@ -3498,7 +3498,7 @@ class postings_reader final : public postings_reader_base { irs::doc_iterator::ptr iterator(IndexFeatures field_features, IndexFeatures required_features, const term_meta& meta, - byte_type wand_count) final { + uint8_t wand_count) final { if (meta.docs_count == 0) { IRS_ASSERT(false); return irs::doc_iterator::empty(); @@ -3540,7 +3540,7 @@ class postings_reader final : public postings_reader_base { } size_t bit_union(IndexFeatures field, const term_provider_f& provider, - size_t* set, byte_type wand_count) final; + size_t* set, uint8_t wand_count) final; private: irs::doc_iterator::ptr MakeWanderator(IndexFeatures field_features, @@ -3760,7 +3760,7 @@ void bit_union(index_input& doc_in, doc_id_t docs_count, uint32_t (&docs)[N], template size_t postings_reader::bit_union( const IndexFeatures field_features, const term_provider_f& provider, - size_t* set, byte_type wand_count) { + size_t* set, uint8_t wand_count) { constexpr auto BITS{bits_required>()}; uint32_t enc_buf[FormatTraits::block_size()]; uint32_t docs[FormatTraits::block_size()]; diff --git a/core/formats/formats_burst_trie.cpp b/core/formats/formats_burst_trie.cpp index 21444877c..644537ac3 100644 --- a/core/formats/formats_burst_trie.cpp +++ b/core/formats/formats_burst_trie.cpp @@ -253,7 +253,7 @@ struct block_t : private util::noncopyable { using block_index_t = IntrusiveList; - block_t(block_index_t&& other, uint64_t block_start, byte_type meta, + block_t(block_index_t&& other, uint64_t block_start, uint8_t meta, uint16_t label) noexcept : index{std::move(other)}, start{block_start}, label{label}, meta{meta} {} @@ -282,7 +282,7 @@ struct block_t : private util::noncopyable { block_index_t index; // fst index data uint64_t start; // file pointer uint16_t label; // block lead label - byte_type meta; // block metadata + uint8_t meta; // block metadata }; template @@ -386,7 +386,7 @@ class MonotonicBuffer { using OutputBuffer = MonotonicBuffer; -enum EntryType : byte_type { ET_TERM = 0, ET_BLOCK, ET_INVALID }; +enum EntryType : uint8_t { ET_TERM = 0, ET_BLOCK, ET_INVALID }; // Block or term class entry : private util::noncopyable { @@ -394,8 +394,7 @@ class entry : private util::noncopyable { entry(irs::bytes_view term, version10::term_meta&& attrs, bool volatile_term); entry(irs::bytes_view prefix, block_t::block_index_t&& index, - uint64_t block_start, byte_type meta, uint16_t label, - bool volatile_term); + uint64_t block_start, uint8_t meta, uint16_t label, bool volatile_term); entry(entry&& rhs) noexcept; entry& operator=(entry&& rhs) noexcept; ~entry() noexcept; @@ -434,7 +433,7 @@ entry::entry(irs::bytes_view term, version10::term_meta&& attrs, } entry::entry(irs::bytes_view prefix, block_t::block_index_t&& index, - uint64_t block_start, byte_type meta, uint16_t label, + uint64_t block_start, uint8_t meta, uint16_t label, bool volatile_term) : type_(ET_BLOCK) { if (block_t::INVALID_LABEL != label) { @@ -500,29 +499,27 @@ struct block_meta { // 2 - is floor block // block has terms - static bool terms(byte_type mask) noexcept { - return check_bit(mask); - } + static bool terms(uint8_t mask) noexcept { return check_bit(mask); } // block has sub-blocks - static bool blocks(byte_type mask) noexcept { + static bool blocks(uint8_t mask) noexcept { return check_bit(mask); } - static void type(byte_type& mask, EntryType type) noexcept { + static void type(uint8_t& mask, EntryType type) noexcept { set_bit(mask, type); } // block is floor block - static bool floor(byte_type mask) noexcept { + static bool floor(uint8_t mask) noexcept { return check_bit(mask); } - static void floor(byte_type& mask, bool b) noexcept { + static void floor(uint8_t& mask, bool b) noexcept { set_bit(b, mask); } // resets block meta - static void reset(byte_type mask) noexcept { + static void reset(uint8_t mask) noexcept { unset_bit(mask); unset_bit(mask); } @@ -829,7 +826,7 @@ struct cookie final : seek_cookie { bool IsEqual(const irs::seek_cookie& rhs) const noexcept final { // We intentionally don't check `rhs` cookie type. - const auto& rhs_meta = down_cast(rhs).meta; + const auto& rhs_meta = DownCast(rhs).meta; return meta.doc_start == rhs_meta.doc_start && meta.pos_start == rhs_meta.pos_start; } @@ -1007,7 +1004,7 @@ class field_writer final : public irs::field_writer { // end - index of the last entry in the block // meta - block metadata // label - block lead label (if present) - void WriteBlock(size_t prefix, size_t begin, size_t end, byte_type meta, + void WriteBlock(size_t prefix, size_t begin, size_t end, uint8_t meta, uint16_t label); // prefix - prefix length ( in last_term @@ -1038,7 +1035,7 @@ class field_writer final : public irs::field_writer { }; void field_writer::WriteBlock(size_t prefix, size_t begin, size_t end, - irs::byte_type meta, uint16_t label) { + uint8_t meta, uint16_t label) { IRS_ASSERT(end > begin); // begin of the block @@ -1089,7 +1086,7 @@ void field_writer::WriteBlock(size_t prefix, size_t begin, size_t end, terms_out_->write_vlong( shift_pack_64(static_cast(block_size), leaf)); - auto copy = [this](const irs::byte_type* b, size_t len) { + auto copy = [this](const byte_type* b, size_t len) { terms_out_->write_bytes(b, len); return true; }; @@ -1097,7 +1094,7 @@ void field_writer::WriteBlock(size_t prefix, size_t begin, size_t end, if (terms_out_cipher_) { auto offset = block_start; - auto encrypt_and_copy = [this, &offset](irs::byte_type* b, size_t len) { + auto encrypt_and_copy = [this, &offset](byte_type* b, size_t len) { IRS_ASSERT(terms_out_cipher_); if (!terms_out_cipher_->encrypt(offset, b, len)) { @@ -1134,7 +1131,7 @@ void field_writer::WriteBlocks(size_t prefix, size_t count) { IRS_ASSERT(blocks_.empty()); // block metadata - irs::byte_type meta{}; + uint8_t meta{}; const size_t end = stack_.size(); const size_t begin = end - count; @@ -1377,7 +1374,7 @@ void field_writer::EndField(std::string_view name, IndexFeatures index_features, const auto [wand_mask, doc_count] = pw_->end_field(); // cause creation of all final blocks - Push(kEmptyStringView); + Push(kEmptyStringView); // write root block with empty prefix WriteBlocks(0, stack_.size()); @@ -1483,15 +1480,15 @@ class term_reader_base : public irs::term_reader, private util::noncopyable { bytes_view min() const noexcept final { return min_term_; } bytes_view max() const noexcept final { return max_term_; } attribute* get_mutable(irs::type_info::type_id type) noexcept final; - bool has_scorer(byte_type index) const noexcept final; + bool has_scorer(uint8_t index) const noexcept final; virtual void prepare(burst_trie::Version version, index_input& in, const feature_map_t& features); - byte_type WandCount() const noexcept { return wand_count_; } + uint8_t WandCount() const noexcept { return wand_count_; } protected: - byte_type WandIndex(byte_type i) const noexcept; + uint8_t WandIndex(uint8_t i) const noexcept; private: field_meta field_; @@ -1505,7 +1502,7 @@ class term_reader_base : public irs::term_reader, private util::noncopyable { frequency freq_; // total term freq }; -byte_type term_reader_base::WandIndex(byte_type i) const noexcept { +uint8_t term_reader_base::WandIndex(uint8_t i) const noexcept { if (i >= kMaxScorers) { return WandContext::kDisable; } @@ -1516,10 +1513,10 @@ byte_type term_reader_base::WandIndex(byte_type i) const noexcept { return WandContext::kDisable; } - return static_cast(std::popcount(wand_mask_ & (mask - 1))); + return static_cast(std::popcount(wand_mask_ & (mask - 1))); } -bool term_reader_base::has_scorer(byte_type index) const noexcept { +bool term_reader_base::has_scorer(uint8_t index) const noexcept { return WandIndex(index) != WandContext::kDisable; } @@ -1546,7 +1543,7 @@ void term_reader_base::prepare(burst_trie::Version version, index_input& in, if (IRS_LIKELY(version >= burst_trie::Version::WAND)) { wand_mask_ = in.read_long(); - wand_count_ = static_cast(std::popcount(wand_mask_)); + wand_count_ = static_cast(std::popcount(wand_mask_)); } } @@ -1620,7 +1617,7 @@ class block_iterator : util::noncopyable { const version10::term_meta& state() const noexcept { return state_; } bool dirty() const noexcept { return dirty_; } - byte_type meta() const noexcept { return cur_meta_; } + uint8_t meta() const noexcept { return cur_meta_; } size_t prefix() const noexcept { return prefix_; } EntryType type() const noexcept { return cur_type_; } uint64_t block_start() const noexcept { return cur_block_start_; } @@ -3055,7 +3052,7 @@ bool automaton_term_iterator::next() { const auto* arc = arcs.value(); if (next_label < arc->min) { - IRS_ASSERT(arc->min <= std::numeric_limits::max()); + IRS_ASSERT(arc->min <= std::numeric_limits::max()); cur_block_->scan_to_sub_block(byte_type(arc->min)); IRS_ASSERT(cur_block_->next_label() == block_t::INVALID_LABEL || arc->min < uint32_t(cur_block_->next_label())); @@ -3076,7 +3073,7 @@ bool automaton_term_iterator::next() { if (!arc) { IRS_ASSERT(arcs.value()->min <= - std::numeric_limits::max()); + std::numeric_limits::max()); cur_block_->scan_to_sub_block(byte_type(arcs.value()->min)); IRS_ASSERT(cur_block_->next_label() == block_t::INVALID_LABEL || arcs.value()->min < uint32_t(cur_block_->next_label())); @@ -3254,7 +3251,7 @@ class field_reader final : public irs::field_reader { size_t bit_union(const cookie_provider& provider, size_t* set) const final { auto term_provider = [&provider]() mutable -> const term_meta* { if (auto* cookie = provider()) { - return &down_cast<::cookie>(*cookie).meta; + return &DownCast<::cookie>(*cookie).meta; } return nullptr; @@ -3302,7 +3299,7 @@ class field_reader final : public irs::field_reader { doc_iterator::ptr postings(const seek_cookie& cookie, IndexFeatures features) const final { return owner_->pr_->iterator(meta().index_features, features, - down_cast<::cookie>(cookie).meta, + DownCast<::cookie>(cookie).meta, WandCount()); } @@ -3311,7 +3308,7 @@ class field_reader final : public irs::field_reader { const WanderatorOptions& options, WandContext ctx) const final { return owner_->pr_->wanderator( - meta().index_features, features, down_cast<::cookie>(cookie).meta, + meta().index_features, features, DownCast<::cookie>(cookie).meta, options, ctx, {.mapped_index = WandIndex(ctx.index), .count = WandCount()}); } diff --git a/core/formats/wand_writer.hpp b/core/formats/wand_writer.hpp index 9c722a896..5cebed531 100644 --- a/core/formats/wand_writer.hpp +++ b/core/formats/wand_writer.hpp @@ -73,13 +73,13 @@ class WandWriterImpl final : public WandWriter { Producer::Write(entry, out); } - byte_type Size(size_t level) const noexcept final { + uint8_t Size(size_t level) const noexcept final { IRS_ASSERT(level + 1 < levels_.size()); const auto& entry = levels_[level]; return Producer::Size(entry); } - byte_type SizeRoot(size_t level) noexcept final { + uint8_t SizeRoot(size_t level) noexcept final { IRS_ASSERT(level < levels_.size()); auto it = levels_.begin(); for (auto end = it + level; it != end;) { @@ -208,7 +208,7 @@ class FreqNormProducer { } } - static size_t Size(Entry entry) noexcept { + static uint8_t Size(Entry entry) noexcept { IRS_ASSERT(entry.freq >= 1); size_t size = bytes_io::vsize(entry.freq); if constexpr (kNorm) { diff --git a/core/index/field_data.cpp b/core/index/field_data.cpp index d45eecd00..06906f7d9 100644 --- a/core/index/field_data.cpp +++ b/core/index/field_data.cpp @@ -98,7 +98,7 @@ IRS_FORCE_INLINE void write_cookie(Inserter& out, uint64_t cookie) { } IRS_FORCE_INLINE uint64_t cookie(size_t slice_offset, size_t offset) noexcept { - IRS_ASSERT(offset <= std::numeric_limits::max()); + IRS_ASSERT(offset <= std::numeric_limits::max()); return static_cast(slice_offset) << 8 | static_cast(offset); } diff --git a/core/index/index_features.hpp b/core/index/index_features.hpp index 4af59810d..7b5692fbf 100644 --- a/core/index/index_features.hpp +++ b/core/index/index_features.hpp @@ -37,7 +37,7 @@ struct field_stats; struct column_output; // Represents a set of features that can be stored in the index -enum class IndexFeatures : byte_type { +enum class IndexFeatures : uint8_t { // Documents NONE = 0, diff --git a/core/index/index_reader_options.hpp b/core/index/index_reader_options.hpp index 2c48abc65..13b5dcad2 100644 --- a/core/index/index_reader_options.hpp +++ b/core/index/index_reader_options.hpp @@ -46,13 +46,13 @@ using ScorersView = std::span; inline constexpr size_t kMaxScorers = bits_required(); struct WandContext { - static constexpr auto kDisable = std::numeric_limits::max(); + static constexpr auto kDisable = std::numeric_limits::max(); bool Enabled() const noexcept { return index != kDisable; } // Index of the wand data in the IndexWriter to use for optimization. // Optimization is turned off by default. - byte_type index{kDisable}; + uint8_t index{kDisable}; bool strict{false}; mutable bool root{true}; }; diff --git a/core/index/merge_writer.cpp b/core/index/merge_writer.cpp index 7d4e2a322..b17e1a0c7 100644 --- a/core/index/merge_writer.cpp +++ b/core/index/merge_writer.cpp @@ -1355,7 +1355,7 @@ bool WriteFields(Columnstore& cs, Iterator& feature_itr, // Ensured by the caller IRS_ASSERT(flush_state.columns); auto& buffered_columns = const_cast( - down_cast(*flush_state.columns)); + DownCast(*flush_state.columns)); while (field_itr.next()) { buffered_columns.Clear(); diff --git a/core/index/norm.cpp b/core/index/norm.cpp index a6617aa2e..629ce28f1 100644 --- a/core/index/norm.cpp +++ b/core/index/norm.cpp @@ -161,8 +161,8 @@ FeatureWriter::ptr Norm2::MakeWriter(std::span headers) { } switch (max_bytes) { - case sizeof(byte_type): - return memory::make_managed>(); + case sizeof(uint8_t): + return memory::make_managed>(); case sizeof(uint16_t): return memory::make_managed>(); default: diff --git a/core/index/norm.hpp b/core/index/norm.hpp index 78a1fa1ed..76ddb3ff2 100644 --- a/core/index/norm.hpp +++ b/core/index/norm.hpp @@ -72,10 +72,10 @@ class Norm : public attribute { static_assert(std::is_nothrow_move_constructible_v); static_assert(std::is_nothrow_move_assignable_v); -enum class Norm2Version : byte_type { kMin = 0 }; +enum class Norm2Version : uint8_t { kMin = 0 }; -enum class Norm2Encoding : byte_type { - Byte = sizeof(byte_type), +enum class Norm2Encoding : uint8_t { + Byte = sizeof(uint8_t), Short = sizeof(uint16_t), Int = sizeof(uint32_t) }; @@ -88,7 +88,7 @@ class Norm2Header final { } constexpr static bool CheckNumBytes(size_t num_bytes) noexcept { - return num_bytes == sizeof(byte_type) || num_bytes == sizeof(uint16_t) || + return num_bytes == sizeof(uint8_t) || num_bytes == sizeof(uint16_t) || num_bytes == sizeof(uint32_t); } @@ -104,8 +104,8 @@ class Norm2Header final { void Reset(const Norm2Header& hdr) noexcept; size_t MaxNumBytes() const noexcept { - if (max_ <= std::numeric_limits::max()) { - return sizeof(byte_type); + if (max_ <= std::numeric_limits::max()) { + return sizeof(uint8_t); } else if (max_ <= std::numeric_limits::max()) { return sizeof(uint16_t); } else { @@ -127,7 +127,7 @@ class Norm2Header final { template class Norm2Writer : public FeatureWriter { public: - static_assert(std::is_same_v || std::is_same_v || + static_assert(std::is_same_v || std::is_same_v || std::is_same_v); explicit Norm2Writer() noexcept : hdr_{Norm2Encoding{sizeof(T)}} {} @@ -145,7 +145,7 @@ class Norm2Writer : public FeatureWriter { uint32_t value; switch (payload.size()) { - case sizeof(irs::byte_type): { + case sizeof(uint8_t): { value = payload.front(); } break; case sizeof(uint16_t): { @@ -168,8 +168,8 @@ class Norm2Writer : public FeatureWriter { private: static void WriteValue(data_output& out, uint32_t value) { - if constexpr (sizeof(T) == sizeof(byte_type)) { - out.write_byte(static_cast(value & 0xFF)); + if constexpr (sizeof(T) == sizeof(uint8_t)) { + out.write_byte(static_cast(value & 0xFF)); } if constexpr (sizeof(T) == sizeof(uint16_t)) { @@ -209,7 +209,7 @@ class Norm2 : public attribute { template static auto MakeReader(Context&& ctx) { - static_assert(std::is_same_v || std::is_same_v || + static_assert(std::is_same_v || std::is_same_v || std::is_same_v); IRS_ASSERT(ctx.num_bytes == sizeof(T)); IRS_ASSERT(ctx.it); @@ -222,11 +222,11 @@ class Norm2 : public attribute { IRS_ASSERT(sizeof(T) == ctx.payload->value.size()); const auto* value = ctx.payload->value.data(); - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v) { return *value; + } else { + return irs::read(value); } - - return irs::read(value); } // we should investigate why we failed to find a norm2 value for doc diff --git a/core/search/bm25.cpp b/core/search/bm25.cpp index 4e0bc7f12..ef33ef108 100644 --- a/core/search/bm25.cpp +++ b/core/search/bm25.cpp @@ -366,8 +366,8 @@ void BM25::collect(byte_type* stats_buf, const irs::FieldCollector* field, const irs::TermCollector* term) const { auto* stats = stats_cast(stats_buf); - const auto* field_ptr = down_cast(field); - const auto* term_ptr = down_cast(term); + const auto* field_ptr = DownCast(field); + const auto* term_ptr = DownCast(term); // nullptr possible if e.g. 'all' filter const auto docs_with_field = field_ptr ? field_ptr->docs_with_field : 0; @@ -546,7 +546,7 @@ bool BM25::equals(const Scorer& other) const noexcept { if (!Scorer::equals(other)) { return false; } - const auto& p = down_cast(other); + const auto& p = DownCast(other); return p.k_ == k_ && p.b_ == b_; } diff --git a/core/search/boolean_filter.cpp b/core/search/boolean_filter.cpp index 18956a2d2..22a55565c 100644 --- a/core/search/boolean_filter.cpp +++ b/core/search/boolean_filter.cpp @@ -327,7 +327,7 @@ bool boolean_filter::equals(const filter& rhs) const noexcept { if (!filter::equals(rhs)) { return false; } - const auto& typed_rhs = down_cast(rhs); + const auto& typed_rhs = DownCast(rhs); return filters_.size() == typed_rhs.size() && std::equal(begin(), end(), typed_rhs.begin(), [](const filter::ptr& lhs, const filter::ptr& rhs) { @@ -384,7 +384,7 @@ void boolean_filter::group_filters(filter::ptr& all_docs_zero_boost, continue; } if (irs::type::id() == (*begin)->type()) { - const auto res = optimize_not(down_cast(**begin)); + const auto res = optimize_not(DownCast(**begin)); if (!res.first) { continue; @@ -628,7 +628,7 @@ bool Not::equals(const irs::filter& rhs) const noexcept { if (!filter::equals(rhs)) { return false; } - const auto& typed_rhs = down_cast(rhs); + const auto& typed_rhs = DownCast(rhs); return (!empty() && !typed_rhs.empty() && *filter_ == *typed_rhs.filter_) || (empty() && typed_rhs.empty()); } diff --git a/core/search/filter.hpp b/core/search/filter.hpp index 38b439902..64e8c75b9 100644 --- a/core/search/filter.hpp +++ b/core/search/filter.hpp @@ -138,7 +138,7 @@ class filter_with_options : public filter { protected: bool equals(const filter& rhs) const noexcept override { return filter::equals(rhs) && - options_ == down_cast(rhs).options_; + options_ == DownCast(rhs).options_; } private: @@ -163,7 +163,7 @@ class filter_base : public filter_with_options { protected: bool equals(const filter& rhs) const noexcept final { return filter_with_options::equals(rhs) && - field_ == down_cast(rhs).field_; + field_ == DownCast(rhs).field_; } private: diff --git a/core/search/levenshtein_filter.cpp b/core/search/levenshtein_filter.cpp index 24e2198d8..d0032d7b8 100644 --- a/core/search/levenshtein_filter.cpp +++ b/core/search/levenshtein_filter.cpp @@ -53,7 +53,7 @@ IRS_FORCE_INLINE score_t similarity(uint32_t distance, uint32_t size) noexcept { } template -inline auto executeLevenshtein(byte_type max_distance, +inline auto executeLevenshtein(uint8_t max_distance, by_edit_distance_options::pdp_f provider, bool with_transpositions, const bytes_view prefix, const bytes_view target, @@ -176,10 +176,10 @@ bool collect_terms(const IndexReader& index, std::string_view field, } auto matcher = make_automaton_matcher(acceptor); - const uint32_t utf8_term_size = - std::max(1U, uint32_t(utf8_utils::utf8_length(prefix)) + - uint32_t(utf8_utils::utf8_length(term))); - const byte_type max_distance = d.max_distance() + 1; + const auto utf8_term_size = + std::max(1U, static_cast(utf8_utils::utf8_length(prefix) + + utf8_utils::utf8_length(term))); + const uint8_t max_distance = d.max_distance() + 1; for (auto& segment : index) { if (auto* reader = segment.field(field); reader) { @@ -266,10 +266,10 @@ field_visitor by_edit_distance::visitor( return [](const SubReader&, const term_reader&, filter_visitor&) {}; } - const uint32_t utf8_term_size = - std::max(1U, uint32_t(utf8_utils::utf8_length(prefix) + - utf8_utils::utf8_length(term))); - const byte_type max_distance = d.max_distance() + 1; + const auto utf8_term_size = + std::max(1U, static_cast(utf8_utils::utf8_length(prefix) + + utf8_utils::utf8_length(term))); + const uint8_t max_distance = d.max_distance() + 1; return [ctx = std::move(ctx), utf8_term_size, max_distance]( const SubReader& segment, const term_reader& field, @@ -282,8 +282,8 @@ field_visitor by_edit_distance::visitor( filter::prepared::ptr by_edit_distance::prepare( const PrepareContext& ctx, std::string_view field, bytes_view term, - size_t scored_terms_limit, byte_type max_distance, - options_type::pdp_f provider, bool with_transpositions, bytes_view prefix) { + size_t scored_terms_limit, uint8_t max_distance, options_type::pdp_f provider, + bool with_transpositions, bytes_view prefix) { return executeLevenshtein( max_distance, provider, with_transpositions, prefix, term, []() -> filter::prepared::ptr { return prepared::empty(); }, diff --git a/core/search/levenshtein_filter.hpp b/core/search/levenshtein_filter.hpp index 85758ec35..bac64ffe3 100644 --- a/core/search/levenshtein_filter.hpp +++ b/core/search/levenshtein_filter.hpp @@ -35,7 +35,7 @@ struct by_edit_distance_filter_options { ////////////////////////////////////////////////////////////////////////////// /// @brief parametric description provider ////////////////////////////////////////////////////////////////////////////// - using pdp_f = const parametric_description& (*)(byte_type, bool); + using pdp_f = const parametric_description& (*)(uint8_t, bool); ////////////////////////////////////////////////////////////////////////////// /// @brief target value @@ -59,7 +59,7 @@ struct by_edit_distance_filter_options { ////////////////////////////////////////////////////////////////////////////// /// @returns maximum allowed edit distance ////////////////////////////////////////////////////////////////////////////// - byte_type max_distance{0}; + uint8_t max_distance{0}; ////////////////////////////////////////////////////////////////////////////// /// @brief consider transpositions as an atomic change @@ -74,7 +74,7 @@ struct by_edit_distance_filter_options { size_t hash() const noexcept { const auto hash0 = hash_combine(std::hash()(with_transpositions), std::hash()(term)); - const auto hash1 = hash_combine(std::hash()(max_distance), + const auto hash1 = hash_combine(std::hash()(max_distance), std::hash()(prefix)); return hash_combine(hash0, hash1); } @@ -112,7 +112,7 @@ class by_edit_distance final : public filter_base { static prepared::ptr prepare(const PrepareContext& ctx, std::string_view field, bytes_view term, - size_t terms_limit, byte_type max_distance, + size_t terms_limit, uint8_t max_distance, options_type::pdp_f provider, bool with_transpositions, bytes_view prefix); diff --git a/core/search/phrase_query.cpp b/core/search/phrase_query.cpp index a157d033e..c44ae8ebb 100644 --- a/core/search/phrase_query.cpp +++ b/core/search/phrase_query.cpp @@ -268,7 +268,7 @@ doc_iterator::ptr VariadicPhraseQuery::execute( // TODO(MBkkt) VariadicPhrase wand support auto disj = MakeDisjunction({}, std::move(disj_itrs), NoopAggregator{}); - pos.first = down_cast(disj.get()); + pos.first = DownCast(disj.get()); conj_itrs.emplace_back(std::move(disj)); ++position; } @@ -371,7 +371,7 @@ doc_iterator::ptr VariadicPhraseQuery::ExecuteWithOffsets( // TODO(MBkkt) VariadicPhrase wand support auto disj = MakeDisjunction({}, std::move(disj_itrs), NoopAggregator{}); - pos.first = down_cast(disj.get()); + pos.first = DownCast(disj.get()); conj_itrs.emplace_back(std::move(disj)); ++position; ++i; diff --git a/core/search/phrase_query.hpp b/core/search/phrase_query.hpp index c438f4227..4d79c67b4 100644 --- a/core/search/phrase_query.hpp +++ b/core/search/phrase_query.hpp @@ -59,9 +59,9 @@ class PhraseQuery : public filter::prepared { if (auto state = states_.find(segment); state) { boost *= this->boost(); if constexpr (std::is_same_v) { - visitor.Visit(down_cast(*this), *state, boost); + visitor.Visit(DownCast(*this), *state, boost); } else if constexpr (std::is_same_v) { - visitor.Visit(down_cast(*this), *state, boost); + visitor.Visit(DownCast(*this), *state, boost); } } } diff --git a/core/search/tfidf.cpp b/core/search/tfidf.cpp index 285a1df8f..91c79dd33 100644 --- a/core/search/tfidf.cpp +++ b/core/search/tfidf.cpp @@ -262,8 +262,8 @@ struct MakeScoreFunctionImpl> { void TFIDF::collect(byte_type* stats_buf, const FieldCollector* field, const TermCollector* term) const { - const auto* field_ptr = down_cast(field); - const auto* term_ptr = down_cast(term); + const auto* field_ptr = DownCast(field); + const auto* term_ptr = DownCast(term); // nullptr possible if e.g. 'all' filter const auto docs_with_field = field_ptr ? field_ptr->docs_with_field : 0; @@ -389,7 +389,7 @@ bool TFIDF::equals(const Scorer& other) const noexcept { if (!Scorer::equals(other)) { return false; } - const auto& p = down_cast(other); + const auto& p = DownCast(other); return p.normalize_ == normalize_; } diff --git a/core/utils/automaton_utils.cpp b/core/utils/automaton_utils.cpp index 6fc981578..d30634b7c 100644 --- a/core/utils/automaton_utils.cpp +++ b/core/utils/automaton_utils.cpp @@ -172,16 +172,13 @@ automaton::StateId utf8_expand_labels(automaton& a) { class utf8_char { public: explicit utf8_char(uint32_t utf32value) noexcept - : size_(utf8_utils::utf32_to_utf8(utf32value, data())) { - } + : size_(utf8_utils::utf32_to_utf8(utf32value, data())) {} uint32_t size() const noexcept { return size_; } const byte_type* c_str() const noexcept { return const_cast(this)->data(); } - operator bytes_view() const noexcept { - return { c_str(), size() }; - } + operator bytes_view() const noexcept { return {c_str(), size()}; } private: byte_type* data() noexcept { return reinterpret_cast(&data_); } @@ -194,7 +191,7 @@ automaton::StateId utf8_expand_labels(automaton& a) { utf8_transitions_builder builder; fst::ArcIteratorData arcs; - for (auto s = 0, nstates = a.NumStates(); s < nstates ; ++s) { + for (auto s = 0, nstates = a.NumStates(); s < nstates; ++s) { a.InitArcIterator(s, &arcs); if (arcs.narcs) { @@ -214,7 +211,7 @@ automaton::StateId utf8_expand_labels(automaton& a) { auto begin = arcs.arcs; for (; begin != arc; ++begin) { if (IRS_UNLIKELY(begin->ilabel > -static_cast