Skip to content

Commit

Permalink
Some clang-tidy update
Browse files Browse the repository at this point in the history
  • Loading branch information
wengxt committed Jun 15, 2024
1 parent 4b3e28c commit 1e5ae72
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/libime/core/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ namespace libime {
constexpr float DEFAULT_USER_LANGUAGE_MODEL_UNIGRAM_WEIGHT = 3;
constexpr float DEFAULT_USER_LANGUAGE_MODEL_BIGRAM_WEIGHT = 15;
constexpr float DEFAULT_LANGUAGE_MODEL_UNKNOWN_PROBABILITY_PENALTY =
1 / 60000000.0f;
1 / 60000000.0F;
// -38... is log10(2^-127)
constexpr float HISTORY_BIGRAM_ALPHA_VALUE = 1.0f;
constexpr float HISTORY_BIGRAM_ALPHA_VALUE = 1.0F;
constexpr float MIN_FLOAT_LOG10 = -38.23080944932561;
constexpr float DEFAULT_USER_LANGUAGE_MODEL_USER_WEIGHT = 0.2f;
constexpr float DEFAULT_USER_LANGUAGE_MODEL_USER_WEIGHT = 0.2F;
} // namespace libime

#endif // _FCITX_LIBIME_CORE_CONSTANTS_H_
7 changes: 7 additions & 0 deletions src/libime/core/datrie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@
#include <array>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <fstream>
#include <ios>
#include <istream>
#include <limits>
#include <ostream>
#include <stdexcept>
#include <string>
#include <string_view>
#include <tuple>
#include <vector>

namespace libime {
Expand Down
23 changes: 19 additions & 4 deletions src/libime/core/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,28 @@
#include "decoder.h"
#include "languagemodel.h"
#include "lattice_p.h"
#include "libime/core/lattice.h"
#include "libime/core/segmentgraph.h"
#include "utils.h"
#include <algorithm>
#include <boost/container_hash/hash.hpp>
#include <boost/functional/hash.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
#include <boost/range/adaptor/sliced.hpp>
#include <cassert>
#include <chrono>
#include <cstddef>
#include <fcitx-utils/macros.h>
#include <limits>
#include <memory>
#include <queue>
#include <string>
#include <string_view>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

namespace libime {

Expand All @@ -25,7 +39,7 @@ struct NBestNode {

const LatticeNode *node_;
// for nbest
float gn_ = 0.0f;
float gn_ = 0.0F;
float fn_ = -std::numeric_limits<float>::max();
std::shared_ptr<NBestNode> next_;
};
Expand Down Expand Up @@ -387,9 +401,10 @@ bool Decoder::decode(Lattice &l, const SegmentGraph &graph, size_t nbest,
}

LatticeNode *Decoder::createLatticeNodeImpl(
const SegmentGraphBase &, const LanguageModelBase *, std::string_view word,
WordIndex idx, SegmentGraphPath path, const State &state, float cost,
std::unique_ptr<LatticeNodeData>, bool) const {
const SegmentGraphBase & /*unused*/, const LanguageModelBase * /*unused*/,
std::string_view word, WordIndex idx, SegmentGraphPath path,
const State &state, float cost, std::unique_ptr<LatticeNodeData> /*unused*/,
bool /*unused*/) const {
return new LatticeNode(word, idx, std::move(path), state, cost);
}
} // namespace libime
37 changes: 24 additions & 13 deletions src/libime/core/zstdfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@
#ifndef LIBIME_ZSTDFILTER_H
#define LIBIME_ZSTDFILTER_H

#include <boost/iostreams/categories.hpp>
#include <boost/iostreams/constants.hpp>
#include <boost/iostreams/filter/symmetric.hpp>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/pipeline.hpp>
#include <boost/throw_exception.hpp>
#include <cstddef>
#include <cstring>
#include <fcitx-utils/log.h>
#include <fcitx-utils/misc.h>
#include <ios>
#include <istream>
#include <ostream>
#include <stdexcept>
#include <zstd.h>

namespace libime {
Expand Down Expand Up @@ -41,22 +50,23 @@ enum class ZSTDResult {

class ZSTDFilterBase {
public:
typedef char char_type;
using char_type = char;
ZSTDFilterBase(const ZSTDFilterBase &) = delete;

protected:
ZSTDFilterBase() = default;
ZSTDFilterBase(const ZSTDFilterBase &) = delete;
~ZSTDFilterBase() {}
void before(const char *&src_begin, const char *src_end, char *&dest_begin,
char *dest_end) {
const char *dest_end) {
in_.src = src_begin;
in_.size = static_cast<size_t>(src_end - src_begin);
in_.pos = 0;
out_.dst = dest_begin;
out_.size = static_cast<size_t>(dest_end - dest_begin);
out_.pos = 0;
}
void after(const char *&src_begin, char *&dest_begin, bool) {
void after(const char *&src_begin, char *&dest_begin,
bool /*unused*/) const {
src_begin = reinterpret_cast<const char *>(in_.src) + in_.pos;
dest_begin = reinterpret_cast<char *>(out_.dst) + out_.pos;
}
Expand Down Expand Up @@ -95,8 +105,9 @@ class ZSTDCompressorImpl : public ZSTDFilterBase {
ZSTDResult deflate(bool finish) {
// Ignore spurious extra calls.
// Note size > 0 will trigger an error in this case.
if (eof_ && in_.size == 0)
if (eof_ && in_.size == 0) {
return ZSTDResult::StreamEnd;
}
size_t result = ZSTD_compressStream(cstream_.get(), &out_, &in_);
ZSTDError::check(result);
if (finish) {
Expand Down Expand Up @@ -147,12 +158,12 @@ class ZSTDDecompressorImpl : public ZSTDFilterBase {
struct ZSTDCompressor
: boost::iostreams::symmetric_filter<details::ZSTDCompressorImpl> {
private:
typedef details::ZSTDCompressorImpl impl_type;
typedef symmetric_filter<impl_type> base_type;
using impl_type = details::ZSTDCompressorImpl;
using base_type = symmetric_filter<impl_type>;

public:
typedef typename base_type::char_type char_type;
typedef typename base_type::category category;
using char_type = typename base_type::char_type;
using category = typename base_type::category;
ZSTDCompressor(std::streamsize buffer_size =
boost::iostreams::default_device_buffer_size)
: base_type(buffer_size) {}
Expand All @@ -162,12 +173,12 @@ BOOST_IOSTREAMS_PIPABLE(ZSTDCompressor, 0)
struct ZSTDDecompressor
: boost::iostreams::symmetric_filter<details::ZSTDDecompressorImpl> {
private:
typedef details::ZSTDDecompressorImpl impl_type;
typedef symmetric_filter<impl_type> base_type;
using impl_type = details::ZSTDDecompressorImpl;
using base_type = symmetric_filter<impl_type>;

public:
typedef typename base_type::char_type char_type;
typedef typename base_type::category category;
using char_type = typename base_type::char_type;
using category = typename base_type::category;
ZSTDDecompressor(std::streamsize buffer_size =
boost::iostreams::default_device_buffer_size)
: base_type(buffer_size) {}
Expand Down

0 comments on commit 1e5ae72

Please sign in to comment.