51     SearchTreeLinkMap::const_iterator it;
    98     SearchTreeLinkMap::const_iterator it;
   154     SearchTreeLinkMap::const_iterator it = the_map->find(ch);
   155     if (it == the_map->end())
   160         if (it == the_map->end())
   183     SearchTreeLinkMap::const_iterator it = the_map->find(ch);
   184     if (it == the_map->end())
   188         if (it == the_map->begin())
   214     SearchTreeLinkMap::const_iterator it = the_map->find(ch);
   215     if (it == the_map->end())
   235                                unsigned int labelstart, 
unsigned int labellen) :
   250     SearchTreeLinkMap::const_iterator found = 
m_Children.find(ch);
   253     return found->second;
   258     SearchTreeItemsMap::const_iterator found = 
m_Items.find(depth);
   261     return found->second;
   267     SearchTreeItemsMap::const_iterator found = 
m_Items.find(depth);
   270     else if (found->second==0)  
   273         itemno = found->second; 
   287     return tree->
GetNode(child,
true);
   346                                                                unsigned int StringStartDepth)
   352         return StringStartDepth + s.
length();
   370     i_limit = s.
length() - startpos;
   374     for (i = 0; i < i_limit; i++)
   385     unsigned int curdepth = 0;
   398     size_t mindepth = parentnode->
GetDepth();
   399     SearchTreeItemsMap::const_iterator i;
   405         if (i->first <= mindepth)
   406             parentnode->
m_Items[i->first]=i->second;
   408             newmap[i->first]=i->second;
   411     for (i = newmap.begin();i!=newmap.end();i++)
   423         revresult <<  (
wxChar)(
_T(
'0') + (u % 10));
   430         result << revresult[i];
   440     result << 
U2S(abs(i));
   446     wxString result,children,sparent,sdepth,slabelno,slabelstart,slabellen;
   447     SearchTreeLinkMap::const_iterator link;
   448     SearchTreeItemsMap::const_iterator item;
   455     result << 
_T(
" <node id=\"") << node_id << 
_T(
"\" parent=\"") << sparent << 
_T(
"\"");
   456     result << _T(
" depth=\"") << sdepth << _T(
"\" label=\"");
   457     result << slabelno << _T(
',') << slabelstart << _T(
',') << slabellen;
   458     result << _T(
"\">\n");
   459     result << _T(
"  <items>\n");
   464             result << _T(
"    <item depth=\"") << 
U2S(item->first)
   465                    << _T(
"\" itemid=\"")       << 
U2S(item->second)
   466                    <<  _T(
"\"") << _T(
" />\n");
   469     result << _T(
"  </items>\n");
   470     result << _T(
"  <children>\n");
   476                    << _T(
"\" nodeid=\"") << 
U2S(link->second) <<  _T(
"\"") << _T(
" />\n");
   480     result << _T(
"  </children>\n");
   481     result << _T(
" </node>\n");
   488                 result << tree->
GetNode(link->second,
false)->
Serialize(tree,link->second,
true);
   500         result << prefix.
substr(0,prefix.
length()-1) << _T(
'+') << suffix << _T(
'\n');
   501     else if (prefix.
length() && prefix[prefix.
length()-1]==
' ')
   502         result << prefix.
substr(0,prefix.
length()-1) << _T(
'\\') << suffix << _T(
'\n');
   504         result << prefix << suffix << _T(
'\n');
   507     newprefix << _T(
"|");
   508     SearchTreeLinkMap::const_iterator i;
   509     unsigned int cnt = 0;
   513             newprefix[newprefix.
length() - 1] = _T(
' ');
   514         tree->
GetNode(i->second,
false)->
Dump(tree,i->second,newprefix,result);
   531     for (
int i = m_Nodes.size() - 1; i >= 0; --i)
   544     for (
int i = m_Nodes.size() - 1; i >= 0; --i)
   558     if (n >= m_Points.size())
   560     return GetString(m_Points[n],0);
   567     if (!nn.
n || nn.
n==top)
   570     std::vector<wxString> the_strings;
   572     for (curnode = m_Nodes[nn.
n];curnode && curnode->
GetDepth();curnode = curnode->
GetParent(
this))
   576         the_strings.push_back(curnode->
GetLabel(
this));
   578             the_strings[the_strings.size()-1] = the_strings[the_strings.size()-1].substr(0,nn.
depth - curnode->
GetLabelStartDepth());
   582     for (
size_t i = the_strings.size();i > 0;--i)
   583         result << the_strings[i - 1];
   590     if ((n || !NullOnZero) && n < m_Nodes.size())
   599     size_t top_depth = m_Nodes[nparent]->
GetDepth();
   608             result->
depth = m_Nodes[result->
n]->GetDepth();
   615         parentnode = m_Nodes[nparent];
   629         childnode = GetNode(nchild,
true);
   646             result->
depth = newdepth;
   648         found =(newdepth == childnode->
GetDepth() || newdepth == top_depth + s.
length());
   649         curpos = newdepth - top_depth;
   661                                             unsigned int labelstart,
   662                                             unsigned int labellen)
   664     return new SearchTreeNode(depth,parent,label,labelstart,labellen);
   671     bool found = this->FindNode(s,nparent,&result);
   684         if (m_Nodes[middle]->
IsLeaf())
   689             newnode = m_Nodes[n];
   699             if (oldlen < newlabel.
length()) 
   710             size_t newdepth = m_Nodes[nparent]->GetDepth() + s.
length();
   716             m_Labels.push_back(newlabel);
   718             m_Labels[nlabel].Shrink();
   721             newnode = CreateNode(newdepth,middle,nlabel,0,newlabel.
length());
   722             m_Nodes.push_back(newnode);
   723             n = m_Nodes.size()-1;
   737     if (!itemno && !s.
empty())
   745     if ( !FindNode(s, 0, &resultpos) )
   747     return m_Nodes[resultpos.
n]->GetItemNo(resultpos.
depth);
   758     SearchTreeItemsMap::const_iterator it2;
   767         bool matches = 
false;
   768         curnode = m_Nodes[*it];
   781                     curcmp = curcmp.
Lower();
   782                 matches = (s3 == curcmp);
   794                     curcmp = curcmp.
Lower();
   805                     if (it2 != curnode->
m_Items.end())
   806                         result.insert(it2->second);
   811                         result.insert(it2->second);
   819     return result.size();
   825     size_t itemno = m_Points.size();
   828     resultpos = AddNode(s, 0); 
   830     result = m_Nodes[resultpos.
n]->AddItemNo(resultpos.
depth, itemno);
   832     if (m_Points.size() < result)   
   835         m_Points[result] = resultpos;
   837     else if (m_Points.size() == result) 
   838         m_Points.push_back(resultpos);
   845     m_Nodes.push_back(CreateNode(0,0,0,0,0));
   851     if (!n || !m_Nodes[n] || m_Nodes[n]->
GetDepth()==depth)
   871     unsigned int middle_start = oldlabelstart;
   872     unsigned int middle_len = parent_offset;
   874     unsigned int child_start = middle_start + middle_len;
   875     unsigned int child_len = oldlabellen - middle_len;
   877     wxChar middle_char = m_Labels[labelno][middle_start];
   878     wxChar child_char = m_Labels[labelno][child_start];
   882     SearchTreeNode* newnode = CreateNode(depth,old_parent,labelno,middle_start,middle_len);
   883     m_Nodes.push_back(newnode);
   888     child->
SetLabel(labelno,child_start,child_len);
   894     m_Nodes[old_parent]->m_Children[middle_char]=middle;
   906     for (i = 0;mode >=0 && i<s.
length();i++)
   909         if (ch==
_T(
'"') || ch==
_T(
'>') || ch==
_T(
'<'))
   930                 else if (ch==
_T(
';'))
   933                     if      (entity==
_T(
"quot"))
   935                     else if (entity==
_T(
"amp"))
   937                     else if (entity==
_T(
"apos"))
   939                     else if (entity==
_T(
"lt"))
   941                     else if (entity==
_T(
"gt"))
   943                     else if (entity[0]==
_T(
'#') && 
S2U(entity.
substr(1),u))
   968     for (i = 0; is_ok && i < s.
length();i++)
   971         if (ch >= 
_T(
'0') && ch <= 
_T(
'9'))
   974             u+=((
unsigned int)ch) & 15;
  1015     for (i=0;i<s.
length();i++)
  1021                 result << 
_T(
""");
break;
  1023                 result << _T(
"'");
break;
  1025                 result << _T(
"<");
break;
  1027                 result << _T(
">");
break;
  1029                 result << _T(
"&");
break;
  1031                 if (ch >= 32 && ch <= 126)
  1043     wxString label = m_Labels[labelno];
  1051     result << 
_T(
" <labels>\n");
  1052     for (
unsigned int i=0;i<m_Labels.size();i++)
  1054         result << _T(
"  <label id=\"") << 
SearchTreeNode::U2S(i) << _T(
"\" data=\"") << SerializeLabel(i) << _T(
"\" />\n");
  1056     result << _T(
" </labels>\n");
  1063     m_Nodes[0]->Dump(
this, 0, 
_T(
""), result);
 unsigned int GetDepth() const
the depth of node is the string length from root node to the last character of the incoming edge ...
unsigned int GetLabelLen() const
the length of the incoming label, in the above example, it is 4 for node"hysi"(2) ...
bool FindPrev(bool includechildren=true)
nSearchTreeLabel m_Label
the string index, the edge is a sub-string of the label in the label array 
size_t AddItemNo(size_t depth, size_t itemno)
set the item value in the item map 
virtual ~SearchTreeNode()
size_t GetItemNo(const wxString &s)
Gets the array position defined by s. 
bool IsValid()
check to see whether the last newest added node is the last element of the node array ...
wxString substr(size_t nStart=0, size_t nLen=npos) const
static bool S2U(const wxString &s, unsigned int &u)
bool FindNextSibling()
go to the next node under the same parent's link map 
size_t GetItemNo(size_t depth)
the element stored in the item map is currently size_t item number 
void RecalcDepth(BasicSearchTree *tree)
Updates the depth by recalculate the m_Depth of the node, this happens the parent node has changed...
nSearchTreeNode SplitBranch(nSearchTreeNode n, size_t depth)
Splits the Branch that leads to node n, at the given depth. 
bool Eof()
reach the end of the tree 
void UpdateItems(BasicSearchTree *tree)
Updates items with parent, move some items upward to its parent node. 
virtual void clear()
Gets the number of items stored. 
BasicSearchTreeIterator()
default constructor 
bool FindNext(bool includechildren=true)
wxString & append(const wxString &str, size_t pos, size_t n)
bool FindPrevSibling()
go to the previous node under the same parent's link map 
unsigned int GetDeepestMatchingPosition(BasicSearchTree *tree, const wxString &s, unsigned int StringStartDepth)
Gets the deepest position where the string matches the edge's label. 
SearchTreeItemsMap m_Items
depth->item number map, 
nSearchTreeNode GetChild(wxChar ch)
This will loop of the link map of the node, and find the child node with its edge beginning with the ...
bool FindNode(const wxString &s, nSearchTreeNode nparent, SearchTreePoint *result)
Finds the node that starts from node 'parent', and has the suffix s. 
SearchTreeNodesArray m_Nodes
Nodes array. 
size_t FindMatches(const wxString &s, std::set< size_t > &result, bool caseSensitive, bool is_prefix)
Finds items that match a given string. 
static wxString SerializeString(const wxString &s)
static wxString I2S(int i)
bool IsLeaf() const
check to see this node is a leaf node. 
nSearchTreeNode GetParent() const
return the parent node index 
const wxString & GetActualLabel(const BasicSearchTree *tree) const
get the full label string, note the incoming edge is only a sub string of the full label ...
SearchTreePoint AddNode(const wxString &s, nSearchTreeNode nparent=0)
Adds Suffix s starting from node nparent. 
SearchTreeLabelsArray m_Labels
Labels used by the nodes' incoming edges. 
wxUSE_UNICODE_dependent wxChar
virtual SearchTreeNode * CreateNode(unsigned int depth, nSearchTreeNode parent, nSearchTreeLabel label, unsigned int labelstart, unsigned int labellen)
Creates a new node. 
SearchTreeLinkMap m_Children
link to descent nodes, 
unsigned int m_Depth
the string length from the root node to the current node (end of the edge) 
wxString Serialize(BasicSearchTree *tree, nSearchTreeNode node_id, bool withchildren=false)
serialize the node information to a string 
std::map< wxChar, nSearchTreeNode, std::less< wxChar > > SearchTreeLinkMap
SearchTreeLinkMap is the list of the edges towards child nodes. 
static bool UnSerializeString(const wxString &s, wxString &result)
bool FindSibling(wxChar ch)
check to see a sibling node with the first character 'ch' exists 
bool m_Eof
current pointed node index 
SearchTreeNode * GetNode(nSearchTreeNode n, bool NullOnZero=false)
Obtains the node with number n,NULL if n is invalid. 
void SetLabel(nSearchTreeLabel label, unsigned int labelstart, unsigned int labellen)
specify the incoming edge of the current node 
This class is generally a string -> size_t map, the tree details (graph) is already show in the decla...
wxString dump()
Dumps a graphical version of the tree. 
size_t nSearchTreeNode
node index, we hold the node address in a vector and reference it by index 
size_t nSearchTreeLabel
label index, we put the labels (strings) in a vector, and access them by index 
SearchTreeNode * m_LastAddedNode
For checking validity. 
BasicSearchTree * m_Tree
whether the iterator reaches end of tree 
std::map< size_t, size_t, std::less< size_t > > SearchTreeItemsMap
SearchTreeItemsMap contains all the items belonging to an node, the key is the depth of the point...
unsigned int m_LabelLen
label length in the string 
unsigned int m_LabelStart
label start index in the string 
size_t m_LastTreeSize
pointer to tree instance 
wxChar GetChar(const BasicSearchTree *tree) const
get first character of the incoming edge, in the above example, it is 'h' for node(2) ...
void SetParent(nSearchTreeNode newparent)
set the parent node index 
unsigned int GetLabelStart() const
the first character index in the full label 
virtual ~BasicSearchTree()
wxString SerializeLabels()
Serializes the labels into an XML-compatible string. 
static wxString U2S(unsigned int u)
void Dump(BasicSearchTree *tree, nSearchTreeNode node_id, const wxString &prefix, wxString &result)
pretty print the node to a string, used for debugging 
size_t insert(const wxString &s)
Clear items and tree. 
nSearchTreeLabel GetLabelNo() const
the index of the full label in tree->m_Labels array 
bool StartsWith(const wxString &prefix, wxString *rest=NULL) const
SearchTreeIterator lets us iterate through the nodes of a BasicSearchTree. 
nSearchTreeNode m_Parent
parent node index 
This class represents a node of the tree, we still take an example E.g. 
This class is used to access items of the tree, each node may contains a lot of items, E.g. 
unsigned int GetLabelStartDepth() const
Returns the depth of the start of the node's incoming label In other words, returns the (calculated) ...
const wxString GetString(size_t n) const
Gets the key string for item n. 
void CreateRootNode()
Creates the tree's root node. 
static bool S2I(const wxString &s, int &i)
wxString SerializeLabel(nSearchTreeLabel labelno)
Serializes given label into an XML-escaped string. 
nSearchTreeNode m_CurNode
wxString GetLabel(const BasicSearchTree *tree) const
get the incoming edge string of the node, in the above example, it is "hysi" for node(2) ...
bool HasItem(const wxString &s)
Tells if there is an item for string s. 
size_t depth
Which node are we pointing to?