72 bool FindPrev(
bool includechildren =
true);
74 bool FindNext(
bool includechildren =
true);
166 unsigned int labelstart,
167 unsigned int labellen);
182 size_t GetItemNo(
size_t depth);
185 size_t AddItemNo(
size_t depth,
size_t itemno);
214 void SetLabel(
nSearchTreeLabel label,
unsigned int labelstart,
unsigned int labellen);
228 unsigned int GetLabelStartDepth()
const;
231 bool IsLeaf()
const {
return m_Children.empty() && (m_Depth != 0); }
237 unsigned int GetDeepestMatchingPosition(
BasicSearchTree* tree,
const wxString& s,
unsigned int StringStartDepth);
245 static wxString U2S(
unsigned int u);
248 static bool S2U(
const wxString& s,
unsigned int& u);
249 static bool S2I(
const wxString& s,
int& i);
283 virtual size_t size()
const {
return m_Points.size(); }
284 virtual size_t GetCount()
const {
return m_Points.size(); }
285 virtual void clear();
299 size_t GetItemNo(
const wxString& s);
302 const wxString GetString(
size_t n)
const;
308 size_t FindMatches(
const wxString& s, std::set<size_t>& result,
bool caseSensitive,
bool is_prefix);
323 unsigned int labelstart,
324 unsigned int labellen);
352 void CreateRootNode();
379 virtual void clear();
380 size_t GetCount()
const;
381 virtual size_t size()
const;
382 bool SaveCacheTo(
const wxString& filename);
383 bool LoadCacheFrom(
const wxString& filename);
390 T GetItem(
const wxChar* s);
393 size_t AddItem(
const wxString& s, T item,
bool replaceexisting =
false);
396 T& GetItemAtPos(
size_t i);
399 void SetItemAtPos(
size_t i,T item);
414 virtual void ClearItems();
417 virtual bool AddFirstNullItem();
440 size_t result =
m_Items.size() -1;
446 size_t result =
m_Items.size() -1;
469 if (!itemno && !s.
empty())
476 size_t itemno =
insert(s);
480 else if (itemno ==
m_Items.size())
482 else if (replaceexisting)
490 if (i>=
m_Items.size() || i < 1)
528 result <<
_T(
"<SearchTree>\n");
530 result << _T(
"<nodes>\n");
531 for (
size_t i = 0; i <
m_Nodes.size(); ++i)
533 result << _T(
"</nodes>\n");
534 result << _T(
" <items>\n");
535 for (
size_t i = 1; i <
m_Items.size(); ++i)
537 result << _T(
" </items>\n");
538 result << _T(
"</SearchTree>\n");
542 #endif // SEARCHTREE_H 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
virtual void clear()
Gets the number of items stored.
this is a class template derived from BasicSearchTree class, the type T was stored in a vector...
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 ...
T & operator[](const wxString &s)
Gets the item found at position s.
bool FindNextSibling()
go to the next node under the same parent's link map
T & GetItemAtPos(size_t i)
Gets the item found at position i, the i is the item index.
std::vector< SearchTreePoint > SearchTreePointsArray
SearchTreePointsArray contains a list of tree points defining strings (keys),.
size_t count(const wxString &s)
std::map compatibility for the above
bool Eof()
reach the end of the tree
virtual void clear()
Gets the number of items stored.
BasicSearchTreeIterator()
default constructor
bool FindNext(bool includechildren=true)
SearchTreePoint(nSearchTreeNode nn, size_t dd)
virtual size_t GetCount() const
How many string keys are stored.
bool FindPrevSibling()
go to the previous node under the same parent's link map
SearchTreeItemsMap m_Items
depth->item number map,
SearchTreeNodesArray m_Nodes
Nodes array.
bool IsLeaf() const
check to see this node is a leaf node.
nSearchTreeNode GetParent() const
return the parent node index
bool SaveCacheTo(const wxString &filename)
Same as GetCount.
size_t AddItem(const wxString &s, T item, bool replaceexisting=false)
Adds an item to position defined by s and return the item number.
std::vector< wxString > SearchTreeLabelsArray
SearchTreeLabelsArray contains the labels used by the nodes, each node contains an incoming edge stri...
SearchTreeLabelsArray m_Labels
Labels used by the nodes' incoming edges.
wxUSE_UNICODE_dependent wxChar
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)
std::map< wxChar, nSearchTreeNode, std::less< wxChar > > SearchTreeLinkMap
SearchTreeLinkMap is the list of the edges towards child nodes.
void SetItemAtPos(size_t i, T item)
Replaces the item found at position(index) i.
bool FindSibling(wxChar ch)
check to see a sibling node with the first character 'ch' exists
const BasicSearchTreeIterator & operator--()
go to previous node
bool m_Eof
current pointed node index
std::vector< SearchTreeNode * > SearchTreeNodesArray
SearchTreeNodesArray contains all the nodes for a search tree, currently the vector should have all t...
This class is generally a string -> size_t map, the tree details (graph) is already show in the decla...
virtual size_t size() const
Gets the number of items stored.
size_t GetCount() const
Clears the tree.
virtual void * UnserializeItem(cb_unused const wxString &s)
Unserializes the items to be stored.
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
wxString Serialize()
Loads the Tree and items from a file.
virtual ~BasicSearchTreeIterator()
destructor
virtual void ClearItems()
The actual stored items.
size_t m_LastTreeSize
pointer to tree instance
void SetParent(nSearchTreeNode newparent)
set the parent node index
unsigned int GetLabelStart() const
the first character index in the full label
wxString SerializeLabels()
Serializes the labels into an XML-compatible string.
SearchTreePointsArray m_Points
Points array.
size_t insert(const wxString &s)
Clear items and tree.
virtual bool AddFirstNullItem()
Adds a null item to position 0.
nSearchTreeLabel GetLabelNo() const
the index of the full label in tree->m_Labels array
virtual wxString SerializeItem(cb_unused size_t idx)
Serializes the stored items.
SearchTreeIterator lets us iterate through the nodes of a BasicSearchTree.
T GetItem(const wxString &s)
Gets the item at position defined by key string s.
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.
const nSearchTreeNode & operator*() const
overload the *() operator, get the node index pointed by the iterator
SearchTreePoint()
At what depth is the string's end located?
bool LoadCacheFrom(const wxString &filename)
Stores the Tree and items into a file.
const BasicSearchTreeIterator & operator++()
go to next node
nSearchTreeNode m_CurNode
size_t depth
Which node are we pointing to?
virtual size_t size() const