Skip to content

Commit

Permalink
update CMakeLists.txt flags and update code to satisfy new constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
i80287 committed Oct 17, 2024
1 parent a6fd9b3 commit 0a4d97a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 13 deletions.
17 changes: 13 additions & 4 deletions graphs/HungarianAlgorithm/hungarian_algo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

namespace hungarian_algo {

namespace detail {

template <class TMatrixRow>
using MatrixRowValueType =
typename std::iterator_traits<typename std::ranges::iterator_t<TMatrixRow>>::value_type;
Expand Down Expand Up @@ -55,6 +57,10 @@ class MinAssignmentGraph final {
return g.accumulate_over(matrix_iter_begin);
}

MinAssignmentGraph(const MinAssignmentGraph&) = delete;
MinAssignmentGraph(MinAssignmentGraph&&) = delete;
MinAssignmentGraph& operator=(const MinAssignmentGraph&) = delete;
MinAssignmentGraph& operator=(MinAssignmentGraph&&) = delete;
~MinAssignmentGraph() {
operator delete(std::bit_cast<std::byte*>(matrix_));
}
Expand Down Expand Up @@ -405,15 +411,18 @@ class MinAssignmentGraph final {
const std::size_t size_;
};

template <MatrixIterator Iterator>
} // namespace detail

template <hungarian_algo::detail::MatrixIterator Iterator>
auto min_assignment(Iterator matrix_iter_begin, Iterator matrix_iter_end) {
using T = MatrixValueType<Iterator>;
return MinAssignmentGraph<T>::min_assignment(matrix_iter_begin, matrix_iter_end);
using T = typename hungarian_algo::detail::MatrixValueType<Iterator>;
return hungarian_algo::detail::MinAssignmentGraph<T>::min_assignment(matrix_iter_begin,
matrix_iter_end);
}

template <std::ranges::random_access_range TMatrix>
auto min_assignment(const TMatrix& matrix) {
return min_assignment(std::begin(matrix), std::end(matrix));
return hungarian_algo::min_assignment(std::begin(matrix), std::end(matrix));
}

} // namespace hungarian_algo
3 changes: 2 additions & 1 deletion number_theory/math_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,8 @@ class [[nodiscard]] Factorizer final {
public:
using PrimeFactors = std::vector<PrimeFactor<std::uint32_t>>;

CONSTEXPR_VECTOR Factorizer(std::uint32_t n) : least_prime_factor(std::size_t{n} + 1) {
CONSTEXPR_VECTOR Factorizer(std::uint32_t n)
: primes(), least_prime_factor(std::size_t{n} + 1) {
for (uint32_t i = 2; i <= std::size_t{n}; i++) {
if (least_prime_factor[i] == 0) {
least_prime_factor[i] = i;
Expand Down
9 changes: 7 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ function(configure_gcc_or_clang_gcc_options)
-Wshift-overflow=2
-Wlogical-op
-Wunsafe-loop-optimizations
-Wduplicated-cond)
-Wduplicated-cond
-Weffc++
-Wsign-promo
-fdiagnostics-color=always)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(LOCAL_FN_TEST_COMPILE_OPTIONS
Expand All @@ -124,7 +127,9 @@ function(configure_gcc_or_clang_gcc_options)
-Wshorten-64-to-32
-Wdeprecated-dynamic-exception-spec
-Wthread-safety
-Wzero-as-null-pointer-constant)
-fcolor-diagnostics
-fansi-escape-codes
-ftemplate-backtrace-limit=0)
set(LOCAL_FN_TEST_COMPILE_DEFINITIONS
${LOCAL_FN_TEST_COMPILE_DEFINITIONS}
_LIBCPP_ENABLE_ASSERTIONS)
Expand Down
29 changes: 24 additions & 5 deletions tf_idf_actrie/actrie.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ class [[nodiscard]] ReplacingACTrie final
size_type pattern_index{};
};

std::vector<ReplacementInfo> planned_replacements;
using ReplacementInfoVector = typename std::vector<ReplacementInfo>;
ReplacementInfoVector planned_replacements;
size_type new_length = text.size();
StoredNodeIndex current_node_index = Base::kRootNodeIndex;
for (auto iter = text.begin(), end = text.end(); iter != end; ++iter) {
Expand Down Expand Up @@ -436,7 +437,25 @@ class [[nodiscard]] ReplacingACTrie final
}

assert(replaced_occurances + planned_replacements.size() <= max_replacements);
for (const ReplacementInfo& info : std::ranges::views::reverse(planned_replacements)) {
auto reverse = [](const ReplacementInfoVector& vec) noexcept {
using Iterator = typename ReplacementInfoVector::const_reverse_iterator;
struct RevStruct {
Iterator begin_iter;
Iterator end_iter;
Iterator begin() const noexcept {
return begin_iter;
}
Iterator end() const noexcept {
return end_iter;
}
};
return RevStruct{
.begin_iter = vec.rbegin(),
.end_iter = vec.rend(),
};
};
// std::ranges::reverse fails to call begin on clang 14.0.0
for (const ReplacementInfo& info : reverse(planned_replacements)) {
const size_type pattern_index = info.pattern_index;
const StoredPatternSize pattern_size = Base::patterns_lengths_[pattern_index];
const size_type l_index_in_text = info.l_index_in_text;
Expand Down Expand Up @@ -553,7 +572,7 @@ class [[nodiscard]] ACTrieBuilder {
static constexpr auto kFakePrerootNodeIndex = ACTrieType::kFakePrerootNodeIndex;

public:
constexpr ACTrieBuilder() {
constexpr ACTrieBuilder() : nodes_(), patterns_lengths_() {
constexpr size_type kDefaultNodesSize =
std::max({kNullNodeIndex, kFakePrerootNodeIndex, kRootNodeIndex}) + 1;
constexpr size_type kDefaultNodesCapacity = std::max(kDefaultNodesSize, size_type(32));
Expand Down Expand Up @@ -690,7 +709,7 @@ class [[nodiscard]] ReplacingACTrieBuilder final

using Base::ContainsPattern;
using Base::PatternsSize;
constexpr bool AddPatternWithReplacement(std::string_view pattern, std::string replacement) {
bool AddPatternWithReplacement(std::string_view pattern, std::string replacement) {
bool added = Base::AddPattern(pattern);
if (added) {
words_replacements_.push_back(std::move(replacement));
Expand All @@ -704,7 +723,7 @@ class [[nodiscard]] ReplacingACTrieBuilder final
}

private:
std::vector<std::string> words_replacements_;
std::vector<std::string> words_replacements_{};
};

// cppcheck-suppress-end [duplInheritedMember]
Expand Down
2 changes: 1 addition & 1 deletion tf_idf_actrie/search_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ std::vector<string_view> Search(string_view text, string_view query, size_t max_
size_t WordsCount = 0;
size_t LineStartIndex = 0;
size_t LineEndIndex = 0;
std::unordered_map<size_t, uint32_t> QueryWordsIndexes;
std::unordered_map<size_t, uint32_t> QueryWordsIndexes{};
};

std::vector<LineInfo> query_words_on_lines;
Expand Down

0 comments on commit 0a4d97a

Please sign in to comment.