PinInPy 1.0.2__tar.gz → 1.0.3__tar.gz
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.
- {pininpy-1.0.2 → pininpy-1.0.3}/PKG-INFO +2 -2
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/CMakeLists.txt +1 -1
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/include/PinIn4Cpp/PinIn.h +1 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/include/PinIn4Cpp/TreeSearcher.h +11 -8
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/include/PinIn4Cpp/detail/Accelerator.h +11 -6
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/include/PinIn4Cpp/detail/AdaptiveContainers.h +2 -2
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/src/Keyboard.cpp +3 -13
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/src/PinIn.cpp +6 -1
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/src/TreeSearcher.cpp +7 -5
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/src/utils/Accelerator.cpp +7 -1
- {pininpy-1.0.2 → pininpy-1.0.3}/pyproject.toml +2 -2
- {pininpy-1.0.2 → pininpy-1.0.3}/.editorconfig +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/.github/workflows/python-publish.yml +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/.gitignore +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/.gitmodules +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/CMakeLists.txt +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/LICENSE +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/.editorconfig +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/.gitattributes +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/.gitignore +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/CMakeSettings.json +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/FFIExample/PinInLua.lua +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/LICENSE +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/README.md +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/cmake/PinIn4CppConfig.cmake.in +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/example/PinyinTest.cpp +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/include/PinIn4Cpp/Keyboard.h +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/include/PinIn4Cpp/ParallelSearch.h +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/include/PinIn4Cpp/PinInCAPI.h +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/include/PinIn4Cpp/PinyinFormat.h +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/include/PinIn4Cpp/detail/BinUtils.h +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/include/PinIn4Cpp/detail/IndexSet.h +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/include/PinIn4Cpp/detail/ObjectPool.h +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/include/PinIn4Cpp/detail/StringPool.h +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/include/PinIn4Cpp/detail/StringUtils.h +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/licenses/PinIn.txt +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/licenses/pinyin-data.txt +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/src/PinInCAPI.cpp +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/src/PinyinFormat.cpp +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/src/utils/BinUtils.cpp +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/src/utils/IndexSet.cpp +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/src/utils/StringPool.cpp +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/src/utils/StringUtils.cpp +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/test_data/large.txt +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/test_data/pinyin.txt +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/PinIn4Cpp/test_data/small.txt +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/README.md +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/build_cffi.py +0 -0
- {pininpy-1.0.2 → pininpy-1.0.3}/package/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: PinInPy
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: Python library for Pinyin searching
|
|
5
5
|
Keywords: PinIn,pinyin match,pinyin,cffi
|
|
6
6
|
Author-Email: SajoYukimi <kagiyamahino@gmail.com>
|
|
@@ -25,7 +25,7 @@ Classifier: Natural Language :: Chinese (Traditional)
|
|
|
25
25
|
Project-URL: Homepage, https://github.com/KagiamamaHIna/PinInPy
|
|
26
26
|
Project-URL: Bug Tracker, https://github.com/KagiamamaHIna/PinInPy/issues
|
|
27
27
|
Project-URL: Source, https://github.com/KagiamamaHIna/PinInPy
|
|
28
|
-
Requires-Python: >=3.
|
|
28
|
+
Requires-Python: >=3.10
|
|
29
29
|
Requires-Dist: cffi
|
|
30
30
|
Description-Content-Type: text/markdown
|
|
31
31
|
|
|
@@ -116,7 +116,7 @@ namespace PinInCpp {
|
|
|
116
116
|
private:
|
|
117
117
|
void init() {
|
|
118
118
|
root = detail::SlabUniqueObj<Node>(NDensePool.NewObj());
|
|
119
|
-
acc.
|
|
119
|
+
acc.SetProvider(&strs);
|
|
120
120
|
ticket = context->ticket([this]() {
|
|
121
121
|
for (const auto& i : this->naccs) {
|
|
122
122
|
i->reload(*this);
|
|
@@ -126,7 +126,7 @@ namespace PinInCpp {
|
|
|
126
126
|
}
|
|
127
127
|
void CommonSearch(std::string_view s, std::unordered_set<size_t>& ret) {
|
|
128
128
|
ticket->renew();
|
|
129
|
-
acc.
|
|
129
|
+
acc.SetSearchStr(s);
|
|
130
130
|
root->get(*this, ret, 0);
|
|
131
131
|
}
|
|
132
132
|
enum class NodeType : uint8_t {
|
|
@@ -145,7 +145,7 @@ namespace PinInCpp {
|
|
|
145
145
|
virtual void Serialize(std::vector<uint8_t>& data)const = 0;
|
|
146
146
|
|
|
147
147
|
//将自身载入对象池
|
|
148
|
-
virtual NodeType GetNodeType()const = 0;
|
|
148
|
+
virtual NodeType GetNodeType()const noexcept = 0;
|
|
149
149
|
static detail::SlabUniqueObj<Node> Deserialize(TreeSearcher& p, detail::VecU8Reader& reader);
|
|
150
150
|
};
|
|
151
151
|
//将Node*的所有权通过FreeToPool转移到对象池中,随后放弃其所有权并重设为新指针
|
|
@@ -180,7 +180,7 @@ namespace PinInCpp {
|
|
|
180
180
|
virtual Node* putRange(TreeSearcher& p, size_t start, size_t end);
|
|
181
181
|
virtual void Serialize(std::vector<uint8_t>& data)const;
|
|
182
182
|
static detail::SlabUniqueObj<NDense> Deserialize(TreeSearcher& p, detail::VecU8Reader& reader);
|
|
183
|
-
virtual NodeType GetNodeType()const {
|
|
183
|
+
virtual NodeType GetNodeType()const noexcept {
|
|
184
184
|
return NodeType::NDenseType;
|
|
185
185
|
}
|
|
186
186
|
private:
|
|
@@ -204,7 +204,7 @@ namespace PinInCpp {
|
|
|
204
204
|
virtual Node* putRange(TreeSearcher& p, size_t start, size_t end);
|
|
205
205
|
virtual void Serialize(std::vector<uint8_t>& data)const;
|
|
206
206
|
static detail::SlabUniqueObj<NSlice> Deserialize(TreeSearcher& p, detail::VecU8Reader& reader);
|
|
207
|
-
virtual NodeType GetNodeType()const {
|
|
207
|
+
virtual NodeType GetNodeType()const noexcept {
|
|
208
208
|
return NodeType::NSliceType;
|
|
209
209
|
}
|
|
210
210
|
NSlice(size_t start, size_t end) :start{ start }, end{ end } {}
|
|
@@ -229,7 +229,7 @@ namespace PinInCpp {
|
|
|
229
229
|
virtual void Serialize(std::vector<uint8_t>& data)const;
|
|
230
230
|
static detail::SlabUniqueObj<NMapTemplate> Deserialize(TreeSearcher& p, detail::VecU8Reader& reader);
|
|
231
231
|
|
|
232
|
-
virtual NodeType GetNodeType()const {
|
|
232
|
+
virtual NodeType GetNodeType()const noexcept {
|
|
233
233
|
return NodeType::NMapType;
|
|
234
234
|
}
|
|
235
235
|
private:
|
|
@@ -272,7 +272,7 @@ namespace PinInCpp {
|
|
|
272
272
|
void reload(TreeSearcher& p);
|
|
273
273
|
virtual void Serialize(std::vector<uint8_t>& data)const;
|
|
274
274
|
static detail::SlabUniqueObj<NAcc> Deserialize(TreeSearcher& p, detail::VecU8Reader& reader);
|
|
275
|
-
virtual NodeType GetNodeType()const {
|
|
275
|
+
virtual NodeType GetNodeType()const noexcept {
|
|
276
276
|
return NodeType::NAccType;
|
|
277
277
|
}
|
|
278
278
|
private:
|
|
@@ -296,6 +296,9 @@ namespace PinInCpp {
|
|
|
296
296
|
constexpr static size_t NDenseThreshold = 128;
|
|
297
297
|
//表节点转换临界点
|
|
298
298
|
constexpr static size_t NMapThreshold = 32;
|
|
299
|
+
//预分配多少元素给搜索的结果集,这将影响搜索性能
|
|
300
|
+
// 由于通用内存分配器很慢,而size_t足够廉价,调大点对内存影响不是很大但是对大的搜索集的构建来讲会快
|
|
301
|
+
constexpr static size_t ResultSetPreSize = 10000;
|
|
299
302
|
const Logic logic;
|
|
300
303
|
std::shared_ptr<PinIn> context = nullptr;//PinIn
|
|
301
304
|
detail::Accelerator acc;
|
|
@@ -310,7 +313,7 @@ namespace PinInCpp {
|
|
|
310
313
|
/* NMapTemplate 实现(避免前面的声明过长) */
|
|
311
314
|
template<bool CanUpgrade>
|
|
312
315
|
void TreeSearcher::NMapTemplate<CanUpgrade>::get(TreeSearcher& p, std::unordered_set<size_t>& ret, size_t offset) {
|
|
313
|
-
if (p.acc.
|
|
316
|
+
if (p.acc.GetSearchStr().size() == offset) {
|
|
314
317
|
if (p.logic == Logic::EQUAL) {
|
|
315
318
|
leaves.AddToSTLSet(ret);
|
|
316
319
|
}
|
|
@@ -8,18 +8,19 @@ namespace PinInCpp {
|
|
|
8
8
|
public:
|
|
9
9
|
Accelerator(PinIn& p) : ctx{ p } {
|
|
10
10
|
}
|
|
11
|
-
const Utf8StringView&
|
|
11
|
+
const Utf8StringView& GetSearchStr() {
|
|
12
12
|
return searchStr;
|
|
13
13
|
}
|
|
14
|
-
uint32_t
|
|
14
|
+
uint32_t GetSearchU32FourCC(size_t i) {
|
|
15
15
|
return u32strVec[i];
|
|
16
16
|
}
|
|
17
|
-
void
|
|
17
|
+
void SetSearchStr(std::string_view s) {
|
|
18
18
|
if (s != searchSrcStr) {
|
|
19
19
|
searchSrcStr = s;
|
|
20
20
|
searchStr.reset(searchSrcStr);
|
|
21
21
|
if (cache.size() < searchStr.size()) {
|
|
22
22
|
cache.resize(searchStr.size());
|
|
23
|
+
pinyinCache.resize(searchStr.size());
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
u32strVec.clear();
|
|
@@ -33,9 +34,12 @@ namespace PinInCpp {
|
|
|
33
34
|
for (auto& v : cache) {
|
|
34
35
|
v.clear();//仅清空map容器,避免map对象再构造
|
|
35
36
|
}
|
|
37
|
+
for (auto& v : pinyinCache) {
|
|
38
|
+
v.clear();
|
|
39
|
+
}
|
|
36
40
|
}
|
|
37
41
|
//接收一个外部的、长生命周期的provider,不拥有
|
|
38
|
-
void
|
|
42
|
+
void SetProvider(UTF8StringPool* provider_ptr) {
|
|
39
43
|
provider = provider_ptr;
|
|
40
44
|
}
|
|
41
45
|
void ShrinkToFit() {
|
|
@@ -45,7 +49,6 @@ namespace PinInCpp {
|
|
|
45
49
|
cache.shrink_to_fit();
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
IndexSet get(const PinIn::Pinyin& p, size_t offset);
|
|
49
52
|
IndexSet get(const uint32_t ch, size_t offset);
|
|
50
53
|
size_t common(size_t s1, size_t s2, size_t max);
|
|
51
54
|
bool check(size_t offset, size_t start);
|
|
@@ -56,10 +59,12 @@ namespace PinInCpp {
|
|
|
56
59
|
return searchStr;
|
|
57
60
|
}
|
|
58
61
|
private:
|
|
62
|
+
IndexSet get(const PinIn::Pinyin& p, size_t offset);
|
|
59
63
|
UTF8StringPool* provider = nullptr; //观察者指针,不拥有
|
|
60
64
|
|
|
61
65
|
PinIn& ctx;
|
|
62
|
-
std::vector<
|
|
66
|
+
std::vector<std::unordered_map<uint32_t, IndexSet>> cache;
|
|
67
|
+
std::vector<IndexSet::Storage> pinyinCache;
|
|
63
68
|
Utf8StringView searchStr;
|
|
64
69
|
std::string searchSrcStr;
|
|
65
70
|
std::vector<uint32_t> u32strVec;
|
|
@@ -242,7 +242,7 @@ namespace PinInCpp {
|
|
|
242
242
|
//AdaptiveSet转换临界点
|
|
243
243
|
constexpr static size_t ContainerThreshold = 128;
|
|
244
244
|
|
|
245
|
-
static constexpr uint8_t SVONum = sizeof(std::vector<value>) / sizeof(value);//计算一个合适的长度
|
|
245
|
+
static constexpr uint8_t SVONum = (sizeof(std::vector<value>) - sizeof(size_t)) / sizeof(value);//计算一个合适的长度
|
|
246
246
|
static constexpr bool isSVO = SVONum > 0;//计算是否可以无损SVO优化
|
|
247
247
|
using ObjVector = std::conditional_t<isSVO, SVOArray<value, SVONum>, std::vector<value>>;
|
|
248
248
|
|
|
@@ -405,7 +405,7 @@ namespace PinInCpp {
|
|
|
405
405
|
using KVPair = std::pair<const k, v>;
|
|
406
406
|
//AdaptiveSet转换临界点
|
|
407
407
|
constexpr static size_t ContainerThreshold = 128;
|
|
408
|
-
static constexpr uint8_t SVONum = sizeof(std::vector<KVPair>) / sizeof(KVPair);//计算一个合适的长度
|
|
408
|
+
static constexpr uint8_t SVONum = (sizeof(std::vector<KVPair>) - sizeof(size_t)) / sizeof(KVPair);//计算一个合适的长度
|
|
409
409
|
static constexpr bool isSVO = SVONum > 0;//计算是否可以无损SVO优化
|
|
410
410
|
using ObjVector = std::conditional_t<isSVO, SVOArray<KVPair, SVONum>, std::vector<KVPair>>;
|
|
411
411
|
|
|
@@ -240,16 +240,6 @@ namespace PinInCpp {
|
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
std::vector<std::string_view> Keyboard::Zero(std::string_view s) {
|
|
243
|
-
std::vector<std::string_view> ss = Standard(s);
|
|
244
|
-
if (ss.size() == 1) {//因为职责改变,所以是1,没有声调
|
|
245
|
-
std::string_view finale = ss[0];//取字符串第一个元素
|
|
246
|
-
ss[0] = finale.substr(0, 1);//覆写第一个元素为其字符串开头的字符
|
|
247
|
-
ss.emplace_back(finale);//因为职责改变,去除了声调在这里,所以只有一个音素的情况下,直接最后追加即可
|
|
248
|
-
}
|
|
249
|
-
return ss;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
std::vector<std::string_view> Keyboard::ZeroZiranmaOrXiaohe(std::string_view s) {
|
|
253
243
|
std::vector<std::string_view> ss = Standard(s);
|
|
254
244
|
if (ss.size() == 1) {//因为职责改变,所以是1,没有声调
|
|
255
245
|
std::string_view finale = ss[0];//取字符串第一个元素
|
|
@@ -354,7 +344,7 @@ namespace PinInCpp {
|
|
|
354
344
|
{"ing", "j"}, {"iong", "s"}, {"iu", "y"}, {"ong", "s"}, {"ou", "p"},
|
|
355
345
|
{"sh", "u"}, {"ua", "q"}, {"uai", "y"}, {"uan", "w"}, {"uang", "n"},
|
|
356
346
|
{"ui", "v"}, {"un", "z"}, {"uo", "o"}, {"van", "w"}, {"ve", "x"},
|
|
357
|
-
{"vn", "z"}, {"zh", "v"},
|
|
347
|
+
{"ue", "x"}, {"vn", "z"}, {"zh", "v"},
|
|
358
348
|
});
|
|
359
349
|
|
|
360
350
|
const static std::map<std::string, std::string> MICROSOFT_KEYS = std::map<std::string, std::string>({
|
|
@@ -387,8 +377,8 @@ namespace PinInCpp {
|
|
|
387
377
|
|
|
388
378
|
const Keyboard Keyboard::QUANPIN = Keyboard(std::nullopt, std::nullopt, Keyboard::Standard, false, true);
|
|
389
379
|
const Keyboard Keyboard::DAQIAN = Keyboard(PHONETIC_LOCAL, DAQIAN_KEYS, Keyboard::Standard, false, false);
|
|
390
|
-
const Keyboard Keyboard::XIAOHE = Keyboard(std::nullopt, XIAOHE_KEYS, Keyboard::
|
|
391
|
-
const Keyboard Keyboard::ZIRANMA = Keyboard(std::nullopt, ZIRANMA_KEYS, Keyboard::
|
|
380
|
+
const Keyboard Keyboard::XIAOHE = Keyboard(std::nullopt, XIAOHE_KEYS, Keyboard::Zero, true, false);
|
|
381
|
+
const Keyboard Keyboard::ZIRANMA = Keyboard(std::nullopt, ZIRANMA_KEYS, Keyboard::Zero, true, false);
|
|
392
382
|
const Keyboard Keyboard::SOUGOU = Keyboard(std::nullopt, SOUGOU_KEYS, Keyboard::ZeroOInitial, true, false);
|
|
393
383
|
const Keyboard Keyboard::ZHINENG_ABC = Keyboard(std::nullopt, ZHINENG_ABC_KEYS, Keyboard::ZeroOInitial, true, false);
|
|
394
384
|
const Keyboard Keyboard::GUOBIAO = Keyboard(std::nullopt, GUOBIAO_KEYS, Keyboard::ZeroAInitial, true, false);
|
|
@@ -476,7 +476,7 @@ namespace PinInCpp {
|
|
|
476
476
|
if (empty()) {
|
|
477
477
|
return result;
|
|
478
478
|
}
|
|
479
|
-
for (const auto& str :
|
|
479
|
+
for (const auto& str : ustrs) {
|
|
480
480
|
size_t size = StrCmp(source, str, start);
|
|
481
481
|
if (size == 0) {
|
|
482
482
|
continue;
|
|
@@ -589,11 +589,13 @@ namespace PinInCpp {
|
|
|
589
589
|
|
|
590
590
|
void PinIn::Phoneme::reload() {
|
|
591
591
|
strs.clear();//应该前置,因为是在重载,非法的话就当然置空了
|
|
592
|
+
ustrs.clear();
|
|
592
593
|
if (src.empty()) {//没数据?非法的吧!,不过就直接结束了也算一种处理了
|
|
593
594
|
return;
|
|
594
595
|
}
|
|
595
596
|
if (src.size() == 1 && src[0] >= '0' && src[0] <= '4') {
|
|
596
597
|
strs.emplace_back(src); //声调就是它自己,直接处理完毕返回!
|
|
598
|
+
ustrs.emplace_back(src);
|
|
597
599
|
return;
|
|
598
600
|
}
|
|
599
601
|
if (ctx.keyboard.GetHasFuuzyLocal()) {
|
|
@@ -602,6 +604,9 @@ namespace PinInCpp {
|
|
|
602
604
|
else {
|
|
603
605
|
reloadNoMap();//标准音素,纯逻辑实现
|
|
604
606
|
}
|
|
607
|
+
for (const auto& v : strs) {
|
|
608
|
+
ustrs.emplace_back(v);
|
|
609
|
+
}
|
|
605
610
|
}
|
|
606
611
|
|
|
607
612
|
void PinIn::Pinyin::reload(std::string_view str) {
|
|
@@ -14,6 +14,7 @@ namespace PinInCpp {
|
|
|
14
14
|
|
|
15
15
|
std::vector<std::string> TreeSearcher::ExecuteSearch(std::string_view s) {
|
|
16
16
|
std::unordered_set<size_t> ret;
|
|
17
|
+
ret.reserve(ResultSetPreSize);
|
|
17
18
|
CommonSearch(s, ret);
|
|
18
19
|
|
|
19
20
|
std::vector<std::string> result;
|
|
@@ -26,6 +27,7 @@ namespace PinInCpp {
|
|
|
26
27
|
|
|
27
28
|
std::unordered_set<size_t> TreeSearcher::ExecuteSearchGetSet(std::string_view s) {
|
|
28
29
|
std::unordered_set<size_t> ret;
|
|
30
|
+
ret.reserve(ResultSetPreSize);
|
|
29
31
|
CommonSearch(s, ret);
|
|
30
32
|
return ret;
|
|
31
33
|
}
|
|
@@ -58,7 +60,7 @@ namespace PinInCpp {
|
|
|
58
60
|
|
|
59
61
|
void TreeSearcher::NDense::get(TreeSearcher& p, std::unordered_set<size_t>& ret, size_t offset) {
|
|
60
62
|
bool full = p.logic == Logic::EQUAL;
|
|
61
|
-
if (!full && p.acc.
|
|
63
|
+
if (!full && p.acc.GetSearchStr().size() == offset) {
|
|
62
64
|
get(p, ret);
|
|
63
65
|
}
|
|
64
66
|
else {
|
|
@@ -165,7 +167,7 @@ namespace PinInCpp {
|
|
|
165
167
|
}
|
|
166
168
|
|
|
167
169
|
void TreeSearcher::NAcc::get(TreeSearcher& p, std::unordered_set<size_t>& result, size_t offset) {
|
|
168
|
-
if (p.acc.
|
|
170
|
+
if (p.acc.GetSearchStr().size() == offset) {
|
|
169
171
|
if (p.logic == Logic::EQUAL) {
|
|
170
172
|
NodeMap.leaves.AddToSTLSet(result);
|
|
171
173
|
}
|
|
@@ -174,12 +176,12 @@ namespace PinInCpp {
|
|
|
174
176
|
}
|
|
175
177
|
}
|
|
176
178
|
else {
|
|
177
|
-
auto it = NodeMap.children->find(p.acc.
|
|
179
|
+
auto it = NodeMap.children->find(p.acc.GetSearchU32FourCC(offset));
|
|
178
180
|
if (it != nullptr) {
|
|
179
181
|
it->get()->get(p, result, offset + 1);
|
|
180
182
|
}
|
|
181
183
|
for (const auto& [k, v] : index_node) {
|
|
182
|
-
if (!k->match(p.acc.
|
|
184
|
+
if (!k->match(p.acc.GetSearchStr(), offset, true).empty()) {
|
|
183
185
|
detail::AdaptiveMap<uint32_t, detail::SlabUniqueObj<Node>>& map = *NodeMap.children;
|
|
184
186
|
v.forEach([&](uint32_t c) {
|
|
185
187
|
detail::IndexSet::IndexSetIterObj it = p.acc.get(c, offset).GetIterObj();
|
|
@@ -343,7 +345,7 @@ namespace PinInCpp {
|
|
|
343
345
|
if (this->start + start == end) {
|
|
344
346
|
exit_node->get(p, ret, offset);
|
|
345
347
|
}
|
|
346
|
-
else if (offset == p.acc.
|
|
348
|
+
else if (offset == p.acc.GetSearchStr().size()) {
|
|
347
349
|
if (p.logic != Logic::EQUAL) {
|
|
348
350
|
exit_node->get(p, ret);
|
|
349
351
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
namespace PinInCpp {
|
|
4
4
|
namespace detail {
|
|
5
5
|
IndexSet Accelerator::get(const PinIn::Pinyin& p, size_t offset) {
|
|
6
|
-
IndexSet::Storage& data =
|
|
6
|
+
IndexSet::Storage& data = pinyinCache[offset];
|
|
7
7
|
IndexSet ret = data.get(p.id);
|
|
8
8
|
if (ret == IndexSet::NONE) {
|
|
9
9
|
ret = p.match(searchStr, offset, partial);
|
|
@@ -14,6 +14,10 @@ namespace PinInCpp {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
IndexSet Accelerator::get(const uint32_t ch, size_t offset) {
|
|
17
|
+
auto it = cache[offset].find(ch);
|
|
18
|
+
if (it != cache[offset].end()) {
|
|
19
|
+
return it->second;
|
|
20
|
+
}
|
|
17
21
|
PinIn::Character* c = ctx.GetCharCachePtr(ch);
|
|
18
22
|
if (c == nullptr) {
|
|
19
23
|
PinIn::Character c = ctx.GetChar(ch);
|
|
@@ -21,6 +25,7 @@ namespace PinInCpp {
|
|
|
21
25
|
for (const PinIn::Pinyin* p : c.GetPinyins()) {
|
|
22
26
|
ret.merge(get(*p, offset));
|
|
23
27
|
}
|
|
28
|
+
cache[offset].insert_or_assign(ch, ret);
|
|
24
29
|
return ret;
|
|
25
30
|
}
|
|
26
31
|
else {
|
|
@@ -28,6 +33,7 @@ namespace PinInCpp {
|
|
|
28
33
|
for (const PinIn::Pinyin* p : c->GetPinyins()) {
|
|
29
34
|
ret.merge(get(*p, offset));
|
|
30
35
|
}
|
|
36
|
+
cache[offset].insert_or_assign(ch, ret);
|
|
31
37
|
return ret;
|
|
32
38
|
}
|
|
33
39
|
}
|
|
@@ -4,9 +4,9 @@ build-backend = "scikit_build_core.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "PinInPy"
|
|
7
|
-
version = "1.0.
|
|
7
|
+
version = "1.0.3"
|
|
8
8
|
dependencies = ["cffi"]
|
|
9
|
-
requires-python = ">=3.
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
10
|
authors = [
|
|
11
11
|
{ name = "SajoYukimi", email = "kagiyamahino@gmail.com" },
|
|
12
12
|
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|