Skip to content
Merged
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
6 changes: 4 additions & 2 deletions keyvi/include/keyvi/compression/predictive_compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#include <inttypes.h>
#include <bitset>
#include <cstdint>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <sstream>
Expand Down Expand Up @@ -58,7 +60,7 @@ class PredictiveCompression final {
if (bigram[0] == 0 || bigram[1] == 0) {
return "";
} else {
return predictor_table_[(uint16_t(bigram[0]) << 8) + bigram[1]];
return predictor_table_[(static_cast<unsigned>(bigram[0]) << 8U) + bigram[1]];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]

      return predictor_table_[(static_cast<unsigned>(bigram[0]) << 8U) + bigram[1]];
             ^

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]

      return predictor_table_[(static_cast<unsigned>(bigram[0]) << 8U) + bigram[1]];
                                                                         ^

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]

      return predictor_table_[(static_cast<unsigned>(bigram[0]) << 8U) + bigram[1]];
                                                     ^

}
}

Expand Down Expand Up @@ -210,7 +212,7 @@ class PredictiveCompression final {
char c;
instream.get(c);
if (instream.eof()) break;
uint16_t index = (uint16_t(c) << 8) + (uint16_t)instream.get();
const uint16_t index = ((static_cast<unsigned>(c) & 0xFFU) << 8U) + instream.get();
uint8_t length = instream.get();
if (length > 8) {
char error[100];
Expand Down
6 changes: 3 additions & 3 deletions keyvi/include/keyvi/dictionary/fsa/internal/bit_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct BitVector final {
* Sets a bit in the bitvector.
* @param bit the bit to set.
*/
inline void Set(const size_t bit) { bits_[bit >> 5] |= (uint32_t)1 << (bit & 31); }
inline void Set(const size_t bit) { bits_[bit >> 5] |= static_cast<uint32_t>(1) << (bit & 31); }

/**
* Sets all bits of the given bitvector
Expand All @@ -86,7 +86,7 @@ struct BitVector final {
bits_[byte_position + i] |= other.bits_[i];
}
} else {
bits_[byte_position] |= ((uint32_t)other.bits_[0] << bit_position);
bits_[byte_position] |= (static_cast<uint32_t>(other.bits_[0]) << bit_position);
for (size_t i = 1; i < write_length; i++) {
bits_[byte_position + i] |= ((other.bits_[i] << bit_position) | (other.bits_[i - 1] >> (32 - bit_position)));
}
Expand Down Expand Up @@ -117,7 +117,7 @@ struct BitVector final {
* Erase a bit, set it to 0.
* @param bit the bit to erase.
*/
inline void Erase(const size_t bit) { bits_[bit >> 5] &= (uint32_t)(~(1 << (bit & 31))); }
inline void Erase(const size_t bit) { bits_[bit >> 5] &= static_cast<uint32_t>(~(1 << (bit & 31))); }

/** Gets the state of the given bit
*
Expand Down
13 changes: 9 additions & 4 deletions keyvi/include/keyvi/dictionary/fsa/internal/bit_vector_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@

#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <utility>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header utility is not used directly [misc-include-cleaner]

Suggested change

namespace keyvi {
namespace dictionary {
Expand Down Expand Up @@ -63,7 +66,7 @@ struct BitVector final {
* Sets a bit in the bitvector.
* @param bit the bit to set.
*/
inline void Set(const size_t bit) { bits_[bit >> 6] |= (uint64_t)1 << (bit & 63); }
void Set(const size_t bit) { bits_[bit >> 6U] |= static_cast<uint64_t>(1) << (bit & 63U); }

/**
* Sets all bits of the given bitvector
Expand All @@ -81,7 +84,7 @@ struct BitVector final {
bits_[byte_position + i] |= other.bits_[i];
}
} else {
bits_[byte_position] |= ((uint64_t)other.bits_[0] << bit_position);
bits_[byte_position] |= (static_cast<uint64_t>(other.bits_[0]) << bit_position);
for (size_t i = 1; i < write_length; ++i) {
bits_[byte_position + i] |= ((other.bits_[i] << bit_position) | (other.bits_[i - 1] >> (64 - bit_position)));
}
Expand Down Expand Up @@ -112,14 +115,16 @@ struct BitVector final {
* Erase a bit, set it to 0.
* @param bit the bit to erase.
*/
inline void Erase(const size_t bit) { bits_[bit >> 6] &= (uint64_t)(~(1 << (bit & 63))); }
void Erase(const size_t bit) { bits_[bit >> 6U] &= static_cast<uint64_t>(~(1ULL << (bit & 63U))); }

/** Gets the state of the given bit
*
* @param bit the bit
* @return True if set, false otherwise.
*/
inline bool Get(const size_t bit) const { return (bits_[bit >> 6] & ((uint64_t)1 << (bit & 63))) != 0; }
[[nodiscard]] bool Get(const size_t bit) const {
return (bits_[bit >> 6U] & (static_cast<uint64_t>(1) << (bit & 63U))) != 0;
}

/**
* Get the next non set bit in the bitvector starting from the given position.
Expand Down
11 changes: 7 additions & 4 deletions keyvi/include/keyvi/dictionary/fsa/internal/packed_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define KEYVI_DICTIONARY_FSA_INTERNAL_PACKED_STATE_H_

#include <algorithm>
#include <cstdint>
#include <string>

namespace keyvi {
Expand All @@ -51,16 +52,18 @@ struct PackedState final {
public:
PackedState() : PackedState(0, 0, 0) {}
PackedState(OffsetTypeT offset, HashCodeTypeT hashcode, int num_outgoing)
: offset_(offset), hashcode_(hashcode), num_outgoing_and_cookie_((uint32_t)(num_outgoing & 0x1FF)) {}
: offset_(offset), hashcode_(hashcode), num_outgoing_and_cookie_(static_cast<uint32_t>(num_outgoing) & 0x1FFU) {}

HashCodeTypeT GetHashcode() const { return hashcode_; }

int GetNumberOfOutgoingTransitions() const { return static_cast<int>(this->num_outgoing_and_cookie_ & 0x1FF); }
[[nodiscard]] int GetNumberOfOutgoingTransitions() const {
return static_cast<int>(this->num_outgoing_and_cookie_ & 0x1FFU);
}

int GetCookie() const { return static_cast<int>((this->num_outgoing_and_cookie_ & 0xFFFFFE00) >> 9); }
[[nodiscard]] int GetCookie() const { return static_cast<int>((this->num_outgoing_and_cookie_ & 0xFFFFFE00U) >> 9U); }

void SetCookie(int value) {
this->num_outgoing_and_cookie_ = (this->num_outgoing_and_cookie_ & 0x1FF) | (uint32_t)(value << 9);
this->num_outgoing_and_cookie_ = (this->num_outgoing_and_cookie_ & 0x1FFU) | (static_cast<uint32_t>(value) << 9U);
}

OffsetTypeT GetOffset() const { return offset_; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#ifndef KEYVI_DICTIONARY_FSA_INTERNAL_SPARSE_ARRAY_BUILDER_H_
#define KEYVI_DICTIONARY_FSA_INTERNAL_SPARSE_ARRAY_BUILDER_H_

#include <iostream> // NOLINT(misc-include-cleaner)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header iostream is not used directly [misc-include-cleaner]

Suggested change

#include "keyvi/dictionary/fsa/internal/constants.h"
#include "keyvi/dictionary/fsa/internal/lru_generation_cache.h"
#include "keyvi/dictionary/fsa/internal/minimization_hash.h"
Expand Down
3 changes: 3 additions & 0 deletions keyvi/tests/keyvi/dictionary/fsa/automata_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
* Author: hendrik
*/

#include <string>
#include <vector>

#include <boost/test/unit_test.hpp>

#include "keyvi/dictionary/fsa/automata.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
* Author: hendrik
*/

#include <string>
#include <vector>

#include <boost/test/unit_test.hpp>

#include "keyvi/dictionary/fsa/codepoint_state_traverser.h"
Expand Down
3 changes: 3 additions & 0 deletions keyvi/tests/keyvi/dictionary/fsa/entry_iterator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
* Author: hendrik
*/

#include <string>
#include <vector>

#include <boost/test/unit_test.hpp>

#include "keyvi/dictionary/fsa/entry_iterator.h"
Expand Down
2 changes: 2 additions & 0 deletions keyvi/tests/keyvi/dictionary/fsa/generator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* Author: hendrik
*/

#include <string>

#include <boost/filesystem.hpp>
#include <boost/test/unit_test.hpp>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include "keyvi/dictionary/fsa/internal/json_value_store.h"

#include <string>

#include <boost/filesystem.hpp>
#include <boost/interprocess/file_mapping.hpp>
#include <boost/test/unit_test.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* Author: hendrik
*/

#include <limits>

#include <boost/test/unit_test.hpp>

#include "keyvi/dictionary/fsa/internal/packed_state.h"
Expand Down Expand Up @@ -56,7 +58,7 @@ BOOST_AUTO_TEST_CASE(compare64) {
BOOST_CHECK(p.GetHashcode() == 42);

int64_t hashcode = std::numeric_limits<int64_t>::max();
int32_t hashcode_32 = (int32_t)hashcode;
const auto hashcode_32 = static_cast<int32_t>(hashcode);

PackedState<> p2(0, hashcode, 42);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ BOOST_AUTO_TEST_CASE(no_integer_overflow) {
positions.Set(10);

// trigger switch of the bit vectors
uint32_t t = uint32_t(INT_MAX) + 10;
const uint32_t t = static_cast<uint32_t>(INT_MAX) + 10;
positions.Set(t);

BOOST_CHECK(positions.IsSet(t));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
* Author: hendrik
*/

#include <string>
#include <vector>

#include <boost/test/unit_test.hpp>

#include "keyvi/dictionary/fsa/automata.h"
Expand Down
4 changes: 4 additions & 0 deletions keyvi/tests/keyvi/dictionary/matching/fuzzy_matching_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
*/

#include <algorithm>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include <boost/test/unit_test.hpp>

Expand Down
5 changes: 5 additions & 0 deletions keyvi/tests/keyvi/index/index_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@

#include <chrono> //NOLINT
#include <cstdlib>
#include <map>
#include <memory>
#include <string>
#include <thread> //NOLINT
#include <utility>
#include <vector>

#include <boost/filesystem.hpp>
#include <boost/test/unit_test.hpp>
Expand Down
2 changes: 2 additions & 0 deletions keyvi/tests/keyvi/index/internal/read_only_segment_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
//

#include <cstdio>
#include <string>
#include <vector>

#include <boost/test/unit_test.hpp>

Expand Down
2 changes: 2 additions & 0 deletions keyvi/tests/keyvi/index/internal/segment_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
//

#include <algorithm>
#include <string>
#include <vector>

#include <boost/filesystem.hpp>
#include <boost/test/unit_test.hpp>
Expand Down
3 changes: 3 additions & 0 deletions keyvi/tests/keyvi/index/internal/tiered_merge_policy_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
*/

#include <memory>
#include <string>
#include <unordered_set>
#include <vector>

#include <boost/test/unit_test.hpp>

Expand Down
2 changes: 2 additions & 0 deletions keyvi/tests/keyvi/stringdistance/levenshtein_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* Author: hendrik
*/
#include <cstdint>
#include <string>
#include <vector>

#include <boost/test/unit_test.hpp>

Expand Down
2 changes: 2 additions & 0 deletions keyvi/tests/keyvi/transform/fsa_transform_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/

#include <memory>
#include <string>
#include <vector>

#include <boost/test/unit_test.hpp>

Expand Down
Loading