diff --git a/.github/workflows/clang-tidy-post.yml b/.github/workflows/clang-tidy-post.yml index 1cbece053..cd827ac4b 100644 --- a/.github/workflows/clang-tidy-post.yml +++ b/.github/workflows/clang-tidy-post.yml @@ -19,3 +19,4 @@ jobs: lgtm_comment_body: '' annotations: false max_comments: 10 + num_comments_as_exitcode: false diff --git a/.github/workflows/clang-tidy-review.yml b/.github/workflows/clang-tidy-review.yml new file mode 100644 index 000000000..87734f1d0 --- /dev/null +++ b/.github/workflows/clang-tidy-review.yml @@ -0,0 +1,28 @@ +name: clang-tidy-review + +# You can be more specific, but it currently only works on pull requests +on: + pull_request: + paths: ['**.cpp', '**.h', '**.hpp', '**CMakeLists.txt', '**.cmake', '.github/workflows/clang*.yml'] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v5 + + - uses: ZedThree/clang-tidy-review@v0.21.0 + id: review + with: + split_workflow: true + build_dir: build + apt_packages: "libsnappy-dev, libzzip-dev, zlib1g-dev, libboost-all-dev, libzstd-dev" + clang_tidy_checks: '' + cmake_command: "cmake -Bbuild -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ." + + - uses: ZedThree/clang-tidy-review/upload@v0.21.0 + + # If there are any comments, fail the check + - if: steps.review.outputs.total_comments > 0 + run: exit 1 diff --git a/keyvi/include/keyvi/dictionary/fsa/automata.h b/keyvi/include/keyvi/dictionary/fsa/automata.h index 7a4a94b28..1fd2db980 100644 --- a/keyvi/include/keyvi/dictionary/fsa/automata.h +++ b/keyvi/include/keyvi/dictionary/fsa/automata.h @@ -406,17 +406,11 @@ class Automata final { return value_store_reader_->GetMsgPackedValueAsString(state_value, compression_algorithm); } - std::string GetStatistics() const { - return dictionary_properties_->GetStatistics(); - } + [[nodiscard]] std::string GetStatistics() const { return dictionary_properties_->GetStatistics(); } - const std::string& GetManifest() const { - return dictionary_properties_->GetManifest(); - } + [[nodiscard]] const std::string& GetManifest() const { return dictionary_properties_->GetManifest(); } - const uint64_t GetVersion() const { - return dictionary_properties_->GetVersion(); - } + [[nodiscard]] const uint64_t GetVersion() const { return dictionary_properties_->GetVersion(); } private: dictionary_properties_t dictionary_properties_; @@ -478,9 +472,7 @@ class Automata final { friend class keyvi::dictionary::SecondaryKeyDictionary; - const dictionary_properties_t& GetDictionaryProperties() const { - return dictionary_properties_; - } + [[nodiscard]] const dictionary_properties_t& GetDictionaryProperties() const { return dictionary_properties_; } }; // shared pointer diff --git a/keyvi/include/keyvi/dictionary/fsa/comparable_state_traverser.h b/keyvi/include/keyvi/dictionary/fsa/comparable_state_traverser.h index a9ac8b6fa..1873bf031 100644 --- a/keyvi/include/keyvi/dictionary/fsa/comparable_state_traverser.h +++ b/keyvi/include/keyvi/dictionary/fsa/comparable_state_traverser.h @@ -31,6 +31,7 @@ #include #include "keyvi/dictionary/fsa/automata.h" +#include "keyvi/dictionary/fsa/traversal/traversal_base.h" #include "keyvi/dictionary/fsa/traverser_types.h" // #define ENABLE_TRACING @@ -65,7 +66,7 @@ class ComparableStateTraverser final { using label_t = typename innerTraverserType::label_t; using transition_t = typename innerTraverserType::transition_t; - explicit ComparableStateTraverser(const innerTraverserType &&traverser, const bool advance = true, + explicit ComparableStateTraverser(const innerTraverserType&& traverser, const bool advance = true, const size_t order = 0) : state_traverser_(std::move(traverser)), order_(order) { if (advance) { @@ -85,7 +86,7 @@ class ComparableStateTraverser final { : ComparableStateTraverser(f, f->GetStartState(), advance, order) {} explicit ComparableStateTraverser(const automata_t f, const uint64_t start_state, - traversal::TraversalPayload &&payload, const bool advance = true, + traversal::TraversalPayload&& payload, const bool advance = true, const size_t order = 0) : state_traverser_(f, start_state, std::move(payload), false), order_(order) { if (advance) { @@ -94,13 +95,13 @@ class ComparableStateTraverser final { } ComparableStateTraverser() = delete; - ComparableStateTraverser &operator=(ComparableStateTraverser const &) = delete; - ComparableStateTraverser(const ComparableStateTraverser &that) = delete; + ComparableStateTraverser& operator=(ComparableStateTraverser const&) = delete; + ComparableStateTraverser(const ComparableStateTraverser& that) = delete; /** * Comparison of the state traverser for the purpose of ordering them */ - bool operator<(const ComparableStateTraverser &rhs) const { + bool operator<(const ComparableStateTraverser& rhs) const { int compare = std::memcmp(label_stack_.data(), rhs.label_stack_.data(), std::min(label_stack_.size(), rhs.label_stack_.size()) * sizeof(label_t)); if (compare != 0) { @@ -114,16 +115,16 @@ class ComparableStateTraverser final { return order_ > rhs.order_; } - bool operator>(const ComparableStateTraverser &rhs) const { return rhs.operator<(*this); } + bool operator>(const ComparableStateTraverser& rhs) const { return rhs.operator<(*this); } - bool operator<=(const ComparableStateTraverser &rhs) const { return !operator>(rhs); } + bool operator<=(const ComparableStateTraverser& rhs) const { return !operator>(rhs); } - bool operator>=(const ComparableStateTraverser &rhs) const { return !operator<(rhs); } + bool operator>=(const ComparableStateTraverser& rhs) const { return !operator<(rhs); } /** * Compare traverser with another one, _ignoring_ the order value */ - bool operator==(const ComparableStateTraverser &rhs) const { + bool operator==(const ComparableStateTraverser& rhs) const { if (label_stack_.size() != rhs.label_stack_.size()) { return false; } @@ -131,7 +132,7 @@ class ComparableStateTraverser final { return std::memcmp(label_stack_.data(), rhs.label_stack_.data(), label_stack_.size() * sizeof(label_t)) == 0; } - bool operator!=(const ComparableStateTraverser &rhs) const { return !operator==(rhs); } + bool operator!=(const ComparableStateTraverser& rhs) const { return !operator==(rhs); } operator bool() const { return state_traverser_; } @@ -162,7 +163,7 @@ class ComparableStateTraverser final { label_t GetStateLabel() const { return state_traverser_.GetStateLabel(); } - const std::vector &GetStateLabels() const { return label_stack_; } + [[nodiscard]] const std::vector& GetStateLabels() const { return label_stack_; } size_t GetOrder() const { return order_; } @@ -186,22 +187,22 @@ class ComparableStateTraverser final { template friend class matching::NearMatching; - traversal::TraversalState &GetStates() { return state_traverser_.GetStates(); } + traversal::TraversalState& GetStates() { return state_traverser_.GetStates(); } - traversal::TraversalPayload &GetTraversalPayload() { return state_traverser_.GetTraversalPayload(); } + traversal::TraversalPayload& GetTraversalPayload() { return state_traverser_.GetTraversalPayload(); } - const traversal::TraversalPayload &GetTraversalPayload() const { + [[nodiscard]] const traversal::TraversalPayload& GetTraversalPayload() const { return state_traverser_.GetTraversalPayload(); } }; -inline bool CompareWeights(const traversal::TraversalState &i, - const traversal::TraversalState &j) { +inline bool CompareWeights(const traversal::TraversalState& i, + const traversal::TraversalState& j) { return i.GetNextInnerWeight() == j.GetNextInnerWeight(); } template <> -inline bool ComparableStateTraverser::operator<(const ComparableStateTraverser &rhs) const { +inline bool ComparableStateTraverser::operator<(const ComparableStateTraverser& rhs) const { TRACE("operator< (weighted state specialization)"); TRACE("depth %ld %ld", state_traverser_.GetDepth(), rhs.state_traverser_.GetDepth()); @@ -231,7 +232,7 @@ inline bool ComparableStateTraverser::operator<(const Co } template <> -inline bool ComparableStateTraverser::operator==(const ComparableStateTraverser &rhs) const { +inline bool ComparableStateTraverser::operator==(const ComparableStateTraverser& rhs) const { if (label_stack_.size() != rhs.label_stack_.size()) { return false; } @@ -244,7 +245,7 @@ inline bool ComparableStateTraverser::operator==(const Compa } template <> -inline bool ComparableStateTraverser::operator<(const ComparableStateTraverser &rhs) const { +inline bool ComparableStateTraverser::operator<(const ComparableStateTraverser& rhs) const { TRACE("operator< (near state specialization)"); if (GetTraversalPayload().exact != rhs.GetTraversalPayload().exact) { diff --git a/keyvi/include/keyvi/dictionary/fsa/internal/lru_generation_cache.h b/keyvi/include/keyvi/dictionary/fsa/internal/lru_generation_cache.h index 613051f3f..e62d31912 100644 --- a/keyvi/include/keyvi/dictionary/fsa/internal/lru_generation_cache.h +++ b/keyvi/include/keyvi/dictionary/fsa/internal/lru_generation_cache.h @@ -66,21 +66,21 @@ class LeastRecentlyUsedGenerationsCache final { ~LeastRecentlyUsedGenerationsCache() { delete current_generation_; - for (MinimizationHash *generation : generations_) { + for (MinimizationHash* generation : generations_) { delete generation; } } LeastRecentlyUsedGenerationsCache() = delete; - LeastRecentlyUsedGenerationsCache &operator=(LeastRecentlyUsedGenerationsCache const &) = delete; - LeastRecentlyUsedGenerationsCache(const LeastRecentlyUsedGenerationsCache &that) = delete; + LeastRecentlyUsedGenerationsCache& operator=(LeastRecentlyUsedGenerationsCache const&) = delete; + LeastRecentlyUsedGenerationsCache(const LeastRecentlyUsedGenerationsCache& that) = delete; /** Add this object. * @param key The key to add */ void Add(EntryT key) { if (current_generation_->Size() >= size_per_generation_) { - MinimizationHash *newGeneration = nullptr; + MinimizationHash* newGeneration = nullptr; if (generations_.size() + 1 == max_number_of_generations_) { // remove(free) the first generation newGeneration = generations_[0]; @@ -101,7 +101,7 @@ class LeastRecentlyUsedGenerationsCache final { } template - const EntryT Get(EqualityType &key) { // NOLINT + const EntryT Get(EqualityType& key) { // NOLINT EntryT state = current_generation_->Get(key); if (!state.IsEmpty()) { @@ -126,7 +126,7 @@ class LeastRecentlyUsedGenerationsCache final { */ void Clear() { current_generation_->Clear(); - for (MinimizationHash *generation : generations_) { + for (MinimizationHash* generation : generations_) { delete generation; } generations_.clear(); @@ -148,8 +148,8 @@ class LeastRecentlyUsedGenerationsCache final { private: size_t size_per_generation_; size_t max_number_of_generations_; - MinimizationHash *current_generation_; - std::vector *> generations_; + MinimizationHash* current_generation_; + std::vector*> generations_; }; } /* namespace internal */ diff --git a/keyvi/include/keyvi/dictionary/fsa/internal/minimization_hash.h b/keyvi/include/keyvi/dictionary/fsa/internal/minimization_hash.h index 26253a490..18886aa2a 100644 --- a/keyvi/include/keyvi/dictionary/fsa/internal/minimization_hash.h +++ b/keyvi/include/keyvi/dictionary/fsa/internal/minimization_hash.h @@ -180,7 +180,7 @@ class MinimizationHash final { * @return the equal state or an empty value */ template - inline const T Get(EqualityType &key) const { // NOLINT + inline const T Get(EqualityType& key) const { // NOLINT size_t hash = key.GetHashcode() & 0x7fffffff; size_t bucket = hash % hash_size_; @@ -209,7 +209,7 @@ class MinimizationHash final { * @return the equal state or an empty value */ template - inline const T GetAndMove(EqualityType &key, MinimizationHash *other) { // NOLINT + inline const T GetAndMove(EqualityType& key, MinimizationHash* other) { // NOLINT size_t hash = key.GetHashcode() & 0x7fffffff; size_t bucket = hash % hash_size_; T entry = entries_[bucket]; @@ -325,10 +325,10 @@ class MinimizationHash final { size_t rehash_limit_ = 0; /// the actual data storage - T *entries_ = 0; + T* entries_ = 0; /// overflow data storage for colliding entries - T *overflow_entries_ = 0; + T* overflow_entries_ = 0; /// number of items in the data size_t count_ = 0; @@ -399,10 +399,10 @@ class MinimizationHash final { hash_size_ = hash_size_step_table_[hash_size_step_]; rehash_limit_ = static_cast(hash_size_ * load_factor_); - T *old_entries = entries_; + T* old_entries = entries_; entries_ = new T[hash_size_]; - T *old_overflow_entries = overflow_entries_; + T* old_overflow_entries = overflow_entries_; overflow_entries_size_ = std::min(hash_size_ >> 2, max_cookie_size_); overflow_entries_ = new T[overflow_entries_size_]; diff --git a/keyvi/include/keyvi/dictionary/fsa/internal/sparse_array_persistence.h b/keyvi/include/keyvi/dictionary/fsa/internal/sparse_array_persistence.h index 4a4a6b947..d930be301 100644 --- a/keyvi/include/keyvi/dictionary/fsa/internal/sparse_array_persistence.h +++ b/keyvi/include/keyvi/dictionary/fsa/internal/sparse_array_persistence.h @@ -200,9 +200,7 @@ class SparseArrayPersistence final { TRACE("Wrote Transitions, stream at %d", stream.tellp()); } - size_t GetChunkSizeExternalTransitions() const { - return transitions_extern_->GetChunkSize(); - } + size_t GetChunkSizeExternalTransitions() const { return transitions_extern_->GetChunkSize(); } uint32_t GetVersion() const; diff --git a/keyvi/include/keyvi/dictionary/fsa/state_traverser.h b/keyvi/include/keyvi/dictionary/fsa/state_traverser.h index 667f3ca82..04016c60a 100644 --- a/keyvi/include/keyvi/dictionary/fsa/state_traverser.h +++ b/keyvi/include/keyvi/dictionary/fsa/state_traverser.h @@ -55,7 +55,7 @@ class StateTraverser final { this->operator++(0); } - StateTraverser(automata_t f, const uint64_t start_state, traversal::TraversalPayload &&payload, + StateTraverser(automata_t f, const uint64_t start_state, traversal::TraversalPayload&& payload, const bool advance = true) : fsa_(f), current_weight_(0), current_label_(0), stack_(std::move(payload)) { current_state_ = start_state; @@ -81,10 +81,10 @@ class StateTraverser final { } StateTraverser() = delete; - StateTraverser &operator=(StateTraverser const &) = delete; - StateTraverser(const StateTraverser &that) = delete; + StateTraverser& operator=(StateTraverser const&) = delete; + StateTraverser(const StateTraverser& that) = delete; - StateTraverser(StateTraverser &&other) + StateTraverser(StateTraverser&& other) : fsa_(other.fsa_), current_state_(other.current_state_), current_weight_(other.current_weight_), @@ -182,13 +182,13 @@ class StateTraverser final { template friend class ComparableStateTraverser; - const traversal::TraversalStack &GetStack() const { return stack_; } + const traversal::TraversalStack& GetStack() const { return stack_; } - traversal::TraversalState &GetStates() { return stack_.GetStates(); } + traversal::TraversalState& GetStates() { return stack_.GetStates(); } - traversal::TraversalPayload &GetTraversalPayload() { return stack_.traversal_stack_payload; } + traversal::TraversalPayload& GetTraversalPayload() { return stack_.traversal_stack_payload; } - const traversal::TraversalPayload &GetTraversalPayload() const { return stack_.traversal_stack_payload; } + const traversal::TraversalPayload& GetTraversalPayload() const { return stack_.traversal_stack_payload; } }; /** diff --git a/keyvi/include/keyvi/dictionary/fsa/zip_state_traverser.h b/keyvi/include/keyvi/dictionary/fsa/zip_state_traverser.h index f787e4023..406a2db4a 100644 --- a/keyvi/include/keyvi/dictionary/fsa/zip_state_traverser.h +++ b/keyvi/include/keyvi/dictionary/fsa/zip_state_traverser.h @@ -66,7 +66,7 @@ class ZipStateTraverser final { using traverser_t = std::shared_ptr>; struct TraverserCompare { - bool operator()(const traverser_t &t1, const traverser_t &t2) const { return *t1 > *t2; } + bool operator()(const traverser_t& t1, const traverser_t& t2) const { return *t1 > *t2; } }; public: @@ -74,9 +74,9 @@ class ZipStateTraverser final { using transition_t = typename innerTraverserType::transition_t; using heap_t = boost::heap::skew_heap, boost::heap::mutable_>; - explicit ZipStateTraverser(const std::vector &fsas, const bool advance = true) { + explicit ZipStateTraverser(const std::vector& fsas, const bool advance = true) { size_t order = 0; - for (const automata_t &f : fsas) { + for (const automata_t& f : fsas) { traverser_t traverser = std::make_shared>(f, advance, order++); // the traverser could be exhausted after it has been advanced if (*traverser) { @@ -98,7 +98,7 @@ class ZipStateTraverser final { FillInValues(); } - explicit ZipStateTraverser(const std::vector> &fsa_start_state_pairs, + explicit ZipStateTraverser(const std::vector>& fsa_start_state_pairs, const bool advance = true) { size_t order = 0; for (auto f : fsa_start_state_pairs) { @@ -114,12 +114,12 @@ class ZipStateTraverser final { FillInValues(); } - explicit ZipStateTraverser(std::vector>> - &&fsa_start_state_payloads, + explicit ZipStateTraverser(std::vector>>&& + fsa_start_state_payloads, const bool advance = true) { size_t order = 0; - for (auto &f : fsa_start_state_payloads) { + for (auto& f : fsa_start_state_payloads) { if (std::get<1>(f) > 0) { traverser_t traverser = std::make_shared>( std::get<0>(f), std::get<1>(f), std::move(std::get<2>(f)), advance, order++); @@ -134,10 +134,10 @@ class ZipStateTraverser final { } ZipStateTraverser() = delete; - ZipStateTraverser &operator=(ZipStateTraverser const &) = delete; - ZipStateTraverser(const ZipStateTraverser &that) = delete; + ZipStateTraverser& operator=(ZipStateTraverser const&) = delete; + ZipStateTraverser(const ZipStateTraverser& that) = delete; - ZipStateTraverser(ZipStateTraverser &&other) + ZipStateTraverser(ZipStateTraverser&& other) : traverser_queue_(std::move(other.traverser_queue_)), final_(other.final_), depth_(other.depth_), @@ -212,7 +212,7 @@ class ZipStateTraverser final { label_t GetStateLabel() const { return state_label_; } - const std::vector &GetStateLabels() const { return traverser_queue_.top()->GetStateLabels(); } + const std::vector& GetStateLabels() const { return traverser_queue_.top()->GetStateLabels(); } /** * Set the minimum weight states must be greater or equal to. @@ -245,7 +245,7 @@ class ZipStateTraverser final { pruned = false; if (!traverser_queue_.empty()) { - const traverser_t &t = traverser_queue_.top(); + const traverser_t& t = traverser_queue_.top(); TRACE("take values from traverser %lu", t->GetOrder()); final_ = t->IsFinalState(); @@ -295,7 +295,7 @@ class ZipStateTraverser final { template friend class matching::NearMatching; - const traversal::TraversalPayload &GetTraversalPayload() const { + const traversal::TraversalPayload& GetTraversalPayload() const { return traverser_queue_.top()->GetTraversalPayload(); } }; @@ -322,7 +322,7 @@ inline void ZipStateTraverser::PreIncrement() { size_t steps = equal_states_; while (steps > 0) { - for (const transition_t &transition : (*it)->GetStates().traversal_state_payload.transitions) { + for (const transition_t& transition : (*it)->GetStates().traversal_state_payload.transitions) { if (global_weights.count(transition.label) == 0 || global_weights.at(transition.label) < transition.weight) { global_weights[transition.label] = transition.weight; } @@ -335,7 +335,7 @@ inline void ZipStateTraverser::PreIncrement() { it = traverser_queue_.ordered_begin(); steps = equal_states_; while (steps > 0) { - for (transition_t &transition : (*it)->GetStates().traversal_state_payload.transitions) { + for (transition_t& transition : (*it)->GetStates().traversal_state_payload.transitions) { transition.weight = global_weights.at(transition.label); } // re-sort transitions @@ -370,16 +370,16 @@ inline ZipStateTraverser::ZipStateTraverser(const std::i } // 1st pass collect all weights per label - for (const auto &t : traversers) { - for (const transition_t &transition : t->GetStates().traversal_state_payload.transitions) { + for (const auto& t : traversers) { + for (const transition_t& transition : t->GetStates().traversal_state_payload.transitions) { if (global_weights.count(transition.label) == 0 || global_weights.at(transition.label) < transition.weight) { global_weights[transition.label] = transition.weight; } } } // 2nd pass apply global weights - for (const auto &t : traversers) { - for (transition_t &transition : t->GetStates().traversal_state_payload.transitions) { + for (const auto& t : traversers) { + for (transition_t& transition : t->GetStates().traversal_state_payload.transitions) { transition.weight = global_weights.at(transition.label); } // re-sort transitions @@ -400,7 +400,7 @@ inline ZipStateTraverser::ZipStateTraverser(const std::i } template <> -inline ZipStateTraverser::ZipStateTraverser(const std::vector &fsas, +inline ZipStateTraverser::ZipStateTraverser(const std::vector& fsas, const bool advance) { TRACE("construct (weighted state specialization)"); size_t order = 0; @@ -423,16 +423,16 @@ inline ZipStateTraverser::ZipStateTraverser(const std::v } // 1st pass collect all weights per label - for (const auto &t : traversers) { - for (const transition_t &transition : t->GetStates().traversal_state_payload.transitions) { + for (const auto& t : traversers) { + for (const transition_t& transition : t->GetStates().traversal_state_payload.transitions) { if (global_weights.count(transition.label) == 0 || global_weights.at(transition.label) < transition.weight) { global_weights[transition.label] = transition.weight; } } } // 2nd pass apply global weights - for (const auto &t : traversers) { - for (transition_t &transition : t->GetStates().traversal_state_payload.transitions) { + for (const auto& t : traversers) { + for (transition_t& transition : t->GetStates().traversal_state_payload.transitions) { transition.weight = global_weights.at(transition.label); } // re-sort transitions @@ -454,7 +454,7 @@ inline ZipStateTraverser::ZipStateTraverser(const std::v template <> inline ZipStateTraverser::ZipStateTraverser( - const std::vector> &fsa_start_state_pairs, const bool advance) { + const std::vector>& fsa_start_state_pairs, const bool advance) { size_t order = 0; if (fsa_start_state_pairs.size() < 2) { @@ -480,16 +480,16 @@ inline ZipStateTraverser::ZipStateTraverser( } } // 1st pass collect all weights per label - for (const auto &t : traversers) { - for (const transition_t &transition : t->GetStates().traversal_state_payload.transitions) { + for (const auto& t : traversers) { + for (const transition_t& transition : t->GetStates().traversal_state_payload.transitions) { if (global_weights.count(transition.label) == 0 || global_weights.at(transition.label) < transition.weight) { global_weights[transition.label] = transition.weight; } } } // 2nd pass apply global weights - for (const auto &t : traversers) { - for (transition_t &transition : t->GetStates().traversal_state_payload.transitions) { + for (const auto& t : traversers) { + for (transition_t& transition : t->GetStates().traversal_state_payload.transitions) { transition.weight = global_weights.at(transition.label); } TRACE("resort %ld", t->GetOrder()); diff --git a/keyvi/include/keyvi/dictionary/util/trace.h b/keyvi/include/keyvi/dictionary/util/trace.h index 008b56432..665702784 100644 --- a/keyvi/include/keyvi/dictionary/util/trace.h +++ b/keyvi/include/keyvi/dictionary/util/trace.h @@ -22,15 +22,15 @@ * Author: hendrik */ -//The following is left intentionally without include guard -//so that tracing can be switched on and off on a per file basis. +// The following is left intentionally without include guard +// so that tracing can be switched on and off on a per file basis. #ifdef ENABLE_TRACING -# undef TRACE -# define TRACE ::keyvi::dictionary::util::trace::trace_it -# undef ENABLE_TRACING +#undef TRACE +#define TRACE ::keyvi::dictionary::util::trace::trace_it +#undef ENABLE_TRACING #else -# undef TRACE -# define TRACE(x,...) +#undef TRACE +#define TRACE(x, ...) #endif #ifndef TRACE_H_ @@ -45,17 +45,17 @@ namespace util { class trace final { public: - static void trace_it(const char* message, ...) { - va_list arguments; - va_start(arguments, message); - - fprintf(stderr, "* "); - vfprintf(stderr, message, arguments); - fprintf(stderr, "\n"); - } - }; - - } /* namespace util */ - } /* namespace dictionary */ - } /* namespace keyvi */ + static void trace_it(const char* message, ...) { + va_list arguments; + va_start(arguments, message); + + fprintf(stderr, "* "); + vfprintf(stderr, message, arguments); + fprintf(stderr, "\n"); + } +}; + +} /* namespace util */ +} /* namespace dictionary */ +} /* namespace keyvi */ #endif /* TRACE_H_ */ diff --git a/keyvi/include/keyvi/dictionary/util/transform.h b/keyvi/include/keyvi/dictionary/util/transform.h index 09cf95e1f..19cd5e76e 100644 --- a/keyvi/include/keyvi/dictionary/util/transform.h +++ b/keyvi/include/keyvi/dictionary/util/transform.h @@ -31,15 +31,14 @@ namespace keyvi { namespace dictionary { namespace util { -class Transform final{ +class Transform final { public: /** * Apply Bag of Words reordering for all but the last token * @param input * @return token with bow applied */ - static std::string BagOfWordsPartial(const std::string& input, size_t& number_of_tokens) - { + static std::string BagOfWordsPartial(const std::string& input, size_t& number_of_tokens) { std::vector strs; boost::split(strs, input, boost::is_any_of("\t ")); number_of_tokens = strs.size(); diff --git a/keyvi/include/keyvi/dictionary/util/utf8_utils.h b/keyvi/include/keyvi/dictionary/util/utf8_utils.h index 3925837a1..6662e0cc5 100644 --- a/keyvi/include/keyvi/dictionary/util/utf8_utils.h +++ b/keyvi/include/keyvi/dictionary/util/utf8_utils.h @@ -25,12 +25,11 @@ #ifndef UTF8_UTILS_H_ #define UTF8_UTILS_H_ - namespace keyvi { namespace dictionary { namespace util { -class Utf8Utils final{ +class Utf8Utils final { public: static bool IsLeadByte(char utf8_byte) { int intValue = utf8_byte & 0xFF; @@ -42,32 +41,22 @@ class Utf8Utils final{ return (intValue < 0x80) || (intValue >= 0xC0); } - static size_t GetCharLength(char utf8_lead_byte) - { - int intValue = utf8_lead_byte & 0xff; + static size_t GetCharLength(char utf8_lead_byte) { + int intValue = utf8_lead_byte & 0xff; - if (intValue < 0x80) - { - return 1; - } - else if (intValue < 0xc0) - { - std::invalid_argument("Illegal UTF-8 lead byte: " + std::to_string(intValue)); - } - else if (intValue < 0xe0) - { - return 2; - } - else if (intValue < 0xf0) - { - return 3; - } - else if (intValue < 0xf8) - { - return 4; - } + if (intValue < 0x80) { + return 1; + } else if (intValue < 0xc0) { + std::invalid_argument("Illegal UTF-8 lead byte: " + std::to_string(intValue)); + } else if (intValue < 0xe0) { + return 2; + } else if (intValue < 0xf0) { + return 3; + } else if (intValue < 0xf8) { + return 4; + } - throw std::invalid_argument("Illegal UTF-8 lead byte: " + std::to_string(intValue)); + throw std::invalid_argument("Illegal UTF-8 lead byte: " + std::to_string(intValue)); } }; diff --git a/keyvi/tests/keyvi/dictionary/fsa/internal/minimization_hash_test.cpp b/keyvi/tests/keyvi/dictionary/fsa/internal/minimization_hash_test.cpp index 24024de9c..006510ef1 100644 --- a/keyvi/tests/keyvi/dictionary/fsa/internal/minimization_hash_test.cpp +++ b/keyvi/tests/keyvi/dictionary/fsa/internal/minimization_hash_test.cpp @@ -35,7 +35,7 @@ namespace internal { BOOST_AUTO_TEST_SUITE(MinimizationHashTests) BOOST_AUTO_TEST_CASE(insert) { - MinimizationHash> *hash = new MinimizationHash>(); + MinimizationHash>* hash = new MinimizationHash>(); PackedState<> p1 = {10, 25, 2}; hash->Add(p1); PackedState<> p2 = {12, 25, 3}; @@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(insert) { } BOOST_AUTO_TEST_CASE(reset) { - MinimizationHash> *hash = new MinimizationHash>(); + MinimizationHash>* hash = new MinimizationHash>(); PackedState<> p1 = {10, 25, 2}; hash->Add(p1); PackedState<> p2 = {12, 25, 3}; diff --git a/keyvi/tests/keyvi/dictionary/fsa/zip_state_traverser_test.cpp b/keyvi/tests/keyvi/dictionary/fsa/zip_state_traverser_test.cpp index 3602adca0..0577ab0b4 100644 --- a/keyvi/tests/keyvi/dictionary/fsa/zip_state_traverser_test.cpp +++ b/keyvi/tests/keyvi/dictionary/fsa/zip_state_traverser_test.cpp @@ -510,7 +510,7 @@ BOOST_AUTO_TEST_CASE(basic) { BOOST_CHECK(!t); } -std::vector GetAllKeys(ZipStateTraverser> *zip_traverser) { +std::vector GetAllKeys(ZipStateTraverser>* zip_traverser) { std::vector label_stack; std::vector keys; diff --git a/keyvi/tests/keyvi/index/index_limits_test.cpp b/keyvi/tests/keyvi/index/index_limits_test.cpp index 141e82cb9..34e6acc15 100644 --- a/keyvi/tests/keyvi/index/index_limits_test.cpp +++ b/keyvi/tests/keyvi/index/index_limits_test.cpp @@ -46,9 +46,7 @@ inline std::string get_keyvimerger_bin() { } inline size_t limit_filedescriptors(size_t file_descriptor_limit) { - struct rlimit limit { - 0 - }; + struct rlimit limit{0}; getrlimit(RLIMIT_NOFILE, &limit); const size_t old_limit = limit.rlim_cur;