tomoto 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/ext/tomoto/extconf.rb +4 -2
- data/lib/tomoto/version.rb +1 -1
- data/vendor/tomotopy/README.kr.rst +10 -1
- data/vendor/tomotopy/README.rst +10 -1
- data/vendor/tomotopy/src/TopicModel/CT.h +2 -2
- data/vendor/tomotopy/src/TopicModel/CTModel.cpp +5 -0
- data/vendor/tomotopy/src/TopicModel/CTModel.hpp +1 -0
- data/vendor/tomotopy/src/TopicModel/DMR.h +2 -2
- data/vendor/tomotopy/src/TopicModel/DMRModel.cpp +5 -0
- data/vendor/tomotopy/src/TopicModel/DMRModel.hpp +1 -0
- data/vendor/tomotopy/src/TopicModel/DT.h +2 -2
- data/vendor/tomotopy/src/TopicModel/DTModel.cpp +5 -0
- data/vendor/tomotopy/src/TopicModel/DTModel.hpp +3 -0
- data/vendor/tomotopy/src/TopicModel/GDMR.h +2 -2
- data/vendor/tomotopy/src/TopicModel/GDMRModel.cpp +5 -0
- data/vendor/tomotopy/src/TopicModel/GDMRModel.hpp +1 -0
- data/vendor/tomotopy/src/TopicModel/HDP.h +2 -2
- data/vendor/tomotopy/src/TopicModel/HDPModel.cpp +5 -0
- data/vendor/tomotopy/src/TopicModel/HDPModel.hpp +2 -0
- data/vendor/tomotopy/src/TopicModel/HLDA.h +2 -2
- data/vendor/tomotopy/src/TopicModel/HLDAModel.cpp +5 -0
- data/vendor/tomotopy/src/TopicModel/HLDAModel.hpp +9 -0
- data/vendor/tomotopy/src/TopicModel/HPA.h +2 -2
- data/vendor/tomotopy/src/TopicModel/HPAModel.cpp +5 -0
- data/vendor/tomotopy/src/TopicModel/HPAModel.hpp +2 -0
- data/vendor/tomotopy/src/TopicModel/LDA.h +8 -2
- data/vendor/tomotopy/src/TopicModel/LDAModel.cpp +5 -0
- data/vendor/tomotopy/src/TopicModel/LDAModel.hpp +8 -0
- data/vendor/tomotopy/src/TopicModel/LLDA.h +2 -2
- data/vendor/tomotopy/src/TopicModel/LLDAModel.cpp +5 -0
- data/vendor/tomotopy/src/TopicModel/LLDAModel.hpp +1 -0
- data/vendor/tomotopy/src/TopicModel/MGLDA.h +2 -2
- data/vendor/tomotopy/src/TopicModel/MGLDAModel.cpp +5 -0
- data/vendor/tomotopy/src/TopicModel/MGLDAModel.hpp +1 -0
- data/vendor/tomotopy/src/TopicModel/PA.h +2 -2
- data/vendor/tomotopy/src/TopicModel/PAModel.cpp +5 -0
- data/vendor/tomotopy/src/TopicModel/PAModel.hpp +2 -0
- data/vendor/tomotopy/src/TopicModel/PLDAModel.hpp +1 -0
- data/vendor/tomotopy/src/TopicModel/PT.h +3 -3
- data/vendor/tomotopy/src/TopicModel/PTModel.cpp +5 -0
- data/vendor/tomotopy/src/TopicModel/PTModel.hpp +1 -0
- data/vendor/tomotopy/src/TopicModel/SLDA.h +3 -2
- data/vendor/tomotopy/src/TopicModel/SLDAModel.cpp +5 -0
- data/vendor/tomotopy/src/TopicModel/SLDAModel.hpp +1 -0
- data/vendor/tomotopy/src/TopicModel/TopicModel.hpp +77 -3
- data/vendor/tomotopy/src/Utils/Dictionary.cpp +102 -0
- data/vendor/tomotopy/src/Utils/Dictionary.h +26 -75
- data/vendor/tomotopy/src/Utils/Mmap.cpp +146 -0
- data/vendor/tomotopy/src/Utils/Mmap.h +139 -0
- data/vendor/tomotopy/src/Utils/MultiNormalDistribution.hpp +1 -0
- data/vendor/tomotopy/src/Utils/SharedString.cpp +134 -0
- data/vendor/tomotopy/src/Utils/SharedString.h +104 -0
- data/vendor/tomotopy/src/Utils/serializer.cpp +166 -0
- data/vendor/tomotopy/src/Utils/serializer.hpp +261 -85
- metadata +9 -4
- data/vendor/tomotopy/src/Utils/SharedString.hpp +0 -206
@@ -1,206 +0,0 @@
|
|
1
|
-
#pragma once
|
2
|
-
|
3
|
-
#include <string>
|
4
|
-
#include "serializer.hpp"
|
5
|
-
|
6
|
-
namespace tomoto
|
7
|
-
{
|
8
|
-
class SharedString
|
9
|
-
{
|
10
|
-
const char* ptr = nullptr;
|
11
|
-
size_t len = 0;
|
12
|
-
|
13
|
-
void incref()
|
14
|
-
{
|
15
|
-
if (ptr)
|
16
|
-
{
|
17
|
-
++*(size_t*)ptr;
|
18
|
-
}
|
19
|
-
}
|
20
|
-
|
21
|
-
void decref()
|
22
|
-
{
|
23
|
-
if (ptr)
|
24
|
-
{
|
25
|
-
if (--*(size_t*)ptr == 0)
|
26
|
-
{
|
27
|
-
delete[] ptr;
|
28
|
-
ptr = nullptr;
|
29
|
-
}
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
|
-
void init(const char* _begin, const char* _end)
|
34
|
-
{
|
35
|
-
ptr = new char[_end - _begin + 9];
|
36
|
-
*(size_t*)ptr = 1;
|
37
|
-
len = _end - _begin;
|
38
|
-
std::memcpy((void*)(ptr + 8), _begin, _end - _begin);
|
39
|
-
((char*)ptr)[_end - _begin + 8] = 0;
|
40
|
-
}
|
41
|
-
|
42
|
-
public:
|
43
|
-
|
44
|
-
SharedString()
|
45
|
-
{
|
46
|
-
}
|
47
|
-
|
48
|
-
explicit SharedString(const char* _begin, const char* _end)
|
49
|
-
{
|
50
|
-
init(_begin, _end);
|
51
|
-
}
|
52
|
-
|
53
|
-
explicit SharedString(const char* _ptr)
|
54
|
-
{
|
55
|
-
if (_ptr)
|
56
|
-
{
|
57
|
-
init(_ptr, _ptr + std::strlen(_ptr));
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
|
-
explicit SharedString(const std::string& str)
|
62
|
-
{
|
63
|
-
if (!str.empty())
|
64
|
-
{
|
65
|
-
init(str.data(), str.data() + str.size());
|
66
|
-
}
|
67
|
-
}
|
68
|
-
|
69
|
-
SharedString(const SharedString& o) noexcept
|
70
|
-
: ptr{ o.ptr }, len{ o.len }
|
71
|
-
{
|
72
|
-
incref();
|
73
|
-
}
|
74
|
-
|
75
|
-
SharedString(SharedString&& o) noexcept
|
76
|
-
{
|
77
|
-
std::swap(ptr, o.ptr);
|
78
|
-
std::swap(len, o.len);
|
79
|
-
}
|
80
|
-
|
81
|
-
~SharedString()
|
82
|
-
{
|
83
|
-
decref();
|
84
|
-
}
|
85
|
-
|
86
|
-
SharedString& operator=(const SharedString& o)
|
87
|
-
{
|
88
|
-
if (this != &o)
|
89
|
-
{
|
90
|
-
decref();
|
91
|
-
ptr = o.ptr;
|
92
|
-
len = o.len;
|
93
|
-
incref();
|
94
|
-
}
|
95
|
-
return *this;
|
96
|
-
}
|
97
|
-
|
98
|
-
SharedString& operator=(SharedString&& o) noexcept
|
99
|
-
{
|
100
|
-
std::swap(ptr, o.ptr);
|
101
|
-
std::swap(len, o.len);
|
102
|
-
return *this;
|
103
|
-
}
|
104
|
-
|
105
|
-
size_t size() const
|
106
|
-
{
|
107
|
-
if (ptr) return len;
|
108
|
-
return 0;
|
109
|
-
}
|
110
|
-
|
111
|
-
bool empty() const
|
112
|
-
{
|
113
|
-
return ptr == nullptr || size() == 0;
|
114
|
-
}
|
115
|
-
|
116
|
-
operator std::string() const
|
117
|
-
{
|
118
|
-
if (!ptr) return {};
|
119
|
-
return { ptr + 8, ptr + 8 + len };
|
120
|
-
}
|
121
|
-
|
122
|
-
const char* c_str() const
|
123
|
-
{
|
124
|
-
if (!ptr) return "";
|
125
|
-
return ptr + 8;
|
126
|
-
}
|
127
|
-
|
128
|
-
const char* data() const
|
129
|
-
{
|
130
|
-
return c_str();
|
131
|
-
}
|
132
|
-
|
133
|
-
const char* begin() const
|
134
|
-
{
|
135
|
-
return data();
|
136
|
-
}
|
137
|
-
|
138
|
-
const char* end() const
|
139
|
-
{
|
140
|
-
return data() + size();
|
141
|
-
}
|
142
|
-
|
143
|
-
std::string substr(size_t start, size_t len) const
|
144
|
-
{
|
145
|
-
return { c_str() + start, c_str() + start + len };
|
146
|
-
}
|
147
|
-
|
148
|
-
bool operator==(const SharedString& o) const
|
149
|
-
{
|
150
|
-
if (ptr == o.ptr) return true;
|
151
|
-
if (size() != o.size()) return false;
|
152
|
-
return std::equal(begin(), end(), o.begin());
|
153
|
-
}
|
154
|
-
|
155
|
-
bool operator==(const std::string& o) const
|
156
|
-
{
|
157
|
-
if (size() != o.size()) return false;
|
158
|
-
return std::equal(begin(), end(), o.begin());
|
159
|
-
}
|
160
|
-
|
161
|
-
bool operator!=(const SharedString& o) const
|
162
|
-
{
|
163
|
-
return !operator==(o);
|
164
|
-
}
|
165
|
-
|
166
|
-
bool operator!=(const std::string& o) const
|
167
|
-
{
|
168
|
-
return !operator==(o);
|
169
|
-
}
|
170
|
-
};
|
171
|
-
|
172
|
-
namespace serializer
|
173
|
-
{
|
174
|
-
template<>
|
175
|
-
struct Serializer<SharedString>
|
176
|
-
{
|
177
|
-
using VTy = SharedString;
|
178
|
-
void write(std::ostream& ostr, const VTy& v)
|
179
|
-
{
|
180
|
-
writeToStream(ostr, (uint32_t)v.size());
|
181
|
-
if (!ostr.write((const char*)v.data(), v.size()))
|
182
|
-
throw std::ios_base::failure(std::string("writing type 'SharedString' is failed"));
|
183
|
-
}
|
184
|
-
|
185
|
-
void read(std::istream& istr, VTy& v)
|
186
|
-
{
|
187
|
-
auto size = readFromStream<uint32_t>(istr);
|
188
|
-
std::vector<char> t(size);
|
189
|
-
if (!istr.read((char*)t.data(), t.size()))
|
190
|
-
throw std::ios_base::failure(std::string("reading type 'SharedString' is failed"));
|
191
|
-
v = SharedString{ t.data(), t.data() + t.size() };
|
192
|
-
}
|
193
|
-
};
|
194
|
-
}
|
195
|
-
}
|
196
|
-
|
197
|
-
namespace std
|
198
|
-
{
|
199
|
-
template <> struct hash<tomoto::SharedString>
|
200
|
-
{
|
201
|
-
size_t operator()(const tomoto::SharedString& x) const
|
202
|
-
{
|
203
|
-
return hash<string>{}(x);
|
204
|
-
}
|
205
|
-
};
|
206
|
-
}
|