mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
add find xxx in trie
This commit is contained in:
parent
a36782ca76
commit
03dfe02b12
6
Makefile
6
Makefile
@ -33,7 +33,11 @@ $(CMLIB): $(CMDIR)
|
||||
|
||||
#unit test
|
||||
Trie.ut: Trie.cpp Trie.h $(CMLIB)
|
||||
g++ -o $@ $< -DTRIE_UT $(CMLIB)
|
||||
$(CC) -o $@ $< -DTRIE_UT $(CMLIB)
|
||||
|
||||
Segment.ut: Segment.cpp Trie.cpp Segment.h Trie.h $(CMLIB)
|
||||
$(CC) -o $@ Segment.cpp Trie.cpp -DSEGMENT_UT $(CMLIB)
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o *.ut $(CMLIB) main
|
||||
|
18
Trie.cpp
18
Trie.cpp
@ -91,6 +91,24 @@ namespace CppJieba
|
||||
return p->isLeaf;
|
||||
}
|
||||
|
||||
bool Trie::find(const vector<ChUnicode>& uniVec)
|
||||
{
|
||||
TrieNode * p = _root;
|
||||
for(size_t i = 0; i < uniVec.size(); i++)
|
||||
{
|
||||
ChUnicode chUni = uniVec[i];
|
||||
if(p->hmap.find(chUni) == p->hmap.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
p = p-> hmap[chUni];
|
||||
}
|
||||
}
|
||||
return p->isLeaf;
|
||||
}
|
||||
|
||||
bool Trie::cut(const ChUnicode* chUniStr, size_t len, vector< vector<size_t> >& res)
|
||||
{
|
||||
res.clear();
|
||||
|
Loading…
x
Reference in New Issue
Block a user