35 #define _wb_TRIE wb::Trie<KeyT, DataT> 36 #define _wb_LHASH_FOR_TRIE wb::LHash<KeyT, wb::Trie<KeyT, DataT>*> 37 #define _wb_LHASHITER_FOR_TRIE wb::LHashIter<KeyT, wb::Trie<KeyT, DataT>*> 38 #define _wb_UNIT_FOR_TRIE wb::LHash::Unit<KeyT, wb::Trie<KeyT, DataT>*> 40 template <
class KeyT,
class DataT>
class Trie;
41 template <
class KeyT,
class DataT>
class TrieIter;
66 template <
class KeyT,
class DataT>
85 while (ppsub = iter.Next(key)) {
99 size_t nSize =
sizeof(*this);
102 nSize += m_phash->TotalMemCost();
105 while (ppsub = iter.Next(key)) {
106 nSize += (*ppsub)->TotalMemCost();
120 while (ppsub = iter.Next(key)) {
132 DataT*
Find(
const KeyT *p_pIndex,
int nIndexLen,
bool &bFound)
135 if (psub && psub->IsDataLegal()) {
136 return psub->GetData();
142 DataT*
Insert(
const KeyT *p_pIndex,
int nIndexLen,
bool &bFound)
145 return psub->GetData();
150 if (nIndexLen == 0) {
160 _wb_TRIE **ppsub = m_phash->Find(p_pIndex[0], bFound);
161 if (!bFound || !ppsub) {
166 return (*ppsub)->FindTrie(p_pIndex + 1, nIndexLen - 1, bFound);
171 if (nIndexLen == 0) {
178 _wb_TRIE **ppsub = m_phash->Insert(p_pIndex[0], bFound);
182 return (*ppsub)->InsertTrie(p_pIndex + 1, nIndexLen - 1, bFound);
185 DataT*
Find(
const KeyT *p_pIndex,
int nIndexLen)
188 return Find(p_pIndex, nIndexLen, bFound);
191 DataT*
Insert(
const KeyT *p_pIndex,
int nIndexLen)
194 return Insert(p_pIndex, nIndexLen, bFound);
200 return FindTrie(p_pIndex, nIndexLen, bFound);
206 return InsertTrie(p_pIndex, nIndexLen, bFound);
214 template <
class KeyT,
class DataT>
220 : m_Iter(ptrie->m_phash, sort) {};
222 void Init() { m_Iter.Init(); };
227 while (p = Next_1(key)) {
228 if (p->IsDataLegal())
239 return (pp) ? *pp : NULL;
249 template <
class KeyT,
class DataT>
254 : m_ptrie(ptrie), m_pIndex(pIndex), m_nLevel(level),
255 m_iter(ptrie, sort), m_sort(sort){
273 else if (m_nLevel == 1) {
274 return m_iter.Next(*m_pIndex);
279 if (m_pSubIter2 == NULL) {
280 _wb_TRIE *pSub = m_iter.Next_1(*m_pIndex);
287 _wb_TRIE *pNext = m_pSubIter2->Next();
305 bool(*m_sort)(KeyT, KeyT);
_wb_TRIE * Next()
Get next trie.
void Release()
Release all the trie.
bool IsDataLegal()
detect if current trie have legal value
_wb_LHASH_FOR_TRIE * GetHash() const
Get hash pointer.
DataT * Insert(const KeyT *p_pIndex, int nIndexLen)
Insert a value.
DataT * Find(const KeyT *p_pIndex, int nIndexLen, bool &bFound)
Find a value.
_wb_TRIE * InsertTrie(const KeyT *p_pIndex, int nIndexLen, bool &bFound)
Insert a sub-trie.
Get all the values whose indexes are of a fixed length. The returned tries may not contain a legal va...
void Map_noKey(KeyT *&key)
TrieIter(_wb_TRIE *ptrie, bool(*sort)(KeyT, KeyT)=0)
_wb_TRIE * FindTrie(const KeyT *p_pIndex, int nIndexLen)
Find a sub-trie.
DataT * Insert(const KeyT *p_pIndex, int nIndexLen, bool &bFound)
Insert a value.
#define _wb_LHASH_FOR_TRIE
_wb_TRIE * FindTrie(const KeyT *p_pIndex, int nIndexLen, bool &bFound)
Find a sub-trie.
#define _wb_LHASHITER_FOR_TRIE
bool Map_noKeyP(KeyT *key)
_wb_TRIE * Next(KeyT &key)
Get next sub-trie.
DataT * Find(const KeyT *p_pIndex, int nIndexLen)
Find a value.
_wb_TRIE * InsertTrie(const KeyT *p_pIndex, int nIndexLen)
Insert a sub-trie.
void Init()
Initialization.
void Init()
Initialization.
DataT * GetData()
Get value.
size_t TotalMemCost()
Compute the total memory cost of the trie structure.
linear hash, using 'open address' to handle collision
void Fill(DataT d)
set all the values to d
define all the code written by Bin Wang.
TrieIter2(_wb_TRIE *ptrie, KeyT *pIndex, int level, bool(*sort)(KeyT, KeyT)=0)