mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
add iterator and bak
This commit is contained in:
parent
34c99994cb
commit
ba0cdb3e92
17
Trie.cpp
17
Trie.cpp
@ -2,6 +2,16 @@
|
||||
|
||||
namespace CppJieba
|
||||
{
|
||||
Trie::iterator Trie::begin()
|
||||
{
|
||||
return Trie::iterator(_root);
|
||||
}
|
||||
|
||||
Trie::iterator Trie::end()
|
||||
{
|
||||
return Trie::iterator(NULL);
|
||||
}
|
||||
|
||||
Trie::Trie()
|
||||
{
|
||||
_root = NULL;
|
||||
@ -167,8 +177,11 @@ using namespace CppJieba;
|
||||
int main()
|
||||
{
|
||||
Trie trie;
|
||||
//trie.init("test/dict.txt");
|
||||
trie.init("dict.txt");
|
||||
trie.init("test/dict.txt");
|
||||
cout<<trie.begin()->count<<endl;
|
||||
|
||||
return 0;
|
||||
//trie.init("dict.txt");
|
||||
//trie.display();
|
||||
//const char * utf = "B";
|
||||
//ChUnicode chUniStr[16];
|
||||
|
49
Trie.h
49
Trie.h
@ -30,10 +30,59 @@ namespace CppJieba
|
||||
}
|
||||
};
|
||||
|
||||
struct TrieNodeIterator
|
||||
{
|
||||
TrieNode* ptNode;
|
||||
|
||||
TrieNodeIterator():ptNode(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
TrieNodeIterator(TrieNode* ptr):ptNode(NULL)
|
||||
{
|
||||
ptNode = ptr;
|
||||
}
|
||||
|
||||
const int operator++(int)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
TrieNodeIterator& operator++()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
TrieNode& operator*() const
|
||||
{
|
||||
return *ptNode;
|
||||
}
|
||||
|
||||
TrieNode* operator->() const
|
||||
{
|
||||
return ptNode;
|
||||
}
|
||||
|
||||
bool operator==(const TrieNodeIterator& x) const
|
||||
{
|
||||
return ptNode == x.ptNode;
|
||||
}
|
||||
|
||||
bool operator!=(const TrieNodeIterator& x) const
|
||||
{
|
||||
return ptNode != x.ptNode;
|
||||
}
|
||||
};
|
||||
|
||||
class Trie
|
||||
{
|
||||
private:
|
||||
TrieNode* _root;
|
||||
public:
|
||||
typedef TrieNodeIterator iterator;
|
||||
public:
|
||||
iterator begin();
|
||||
iterator end();
|
||||
public:
|
||||
Trie();
|
||||
~Trie();
|
||||
|
Loading…
x
Reference in New Issue
Block a user