bool BasicSearchTreeIterator::FindPrevSibling() { if (!IsValid()) return false; if (!m_CurNode /* || !m_Stack.size() */) m_Eof = true; SearchTreeNode* node = m_Tree->GetNode(m_CurNode); if (!node) return false; wxChar ch = node->GetChar(m_Tree); node = node->GetParent(m_Tree); if (!node) return false; SearchTreeLinkMap* the_map = &node->m_Children; SearchTreeLinkMap::iterator it = the_map->find(ch); if (it == the_map->end()) m_Eof = true; else { if (it == the_map->begin()) m_Eof = true; else { --it; m_CurNode = it->second; } } return true; }
nSearchTreeNode BasicSearchTree::SplitBranch(nSearchTreeNode n,size_t depth) { if (!n || !m_Nodes[n] || m_Nodes[n]->GetDepth()==depth) return n; // for !n it returns the rootnode // for !m_Nodes[n], it fails by returning n. // for m_Nodes[n]->GetDepth()==depth, it's a special case (given position is a node) // so we just return n. SearchTreeNode* child = m_Nodes[n]; nSearchTreeNode old_parent = child->GetParent(); // Create new node "middle", add it to old_parent in place of child. // Calculate the parent offset and the new labels' parameters. size_t parent_offset = depth - child->GetLabelStartDepth(); nSearchTreeLabel labelno = child->GetLabelNo(); unsigned int oldlabelstart = child->GetLabelStart(); unsigned int oldlabellen = child->GetLabelLen(); unsigned int middle_start = oldlabelstart; unsigned int middle_len = parent_offset; unsigned int child_start = middle_start + middle_len; unsigned int child_len = oldlabellen - middle_len; wxChar middle_char = m_Labels[labelno][middle_start]; wxChar child_char = m_Labels[labelno][child_start]; // Now we're ready to create the middle node and update accordingly SearchTreeNode* newnode = CreateNode(depth,old_parent,labelno,middle_start,middle_len); m_Nodes.push_back(newnode); nSearchTreeNode middle = m_Nodes.size() - 1; // Add child to middle child->SetParent(middle); child->SetLabel(labelno,child_start,child_len); child->RecalcDepth(this); newnode->m_Children[child_char]=n; child->UpdateItems(this); // Add middle to old_parent m_Nodes[old_parent]->m_Children[middle_char]=middle; return middle; }
bool BasicSearchTreeIterator::FindSibling(char ch) { if(!IsValid()) return false; if(!m_CurNode /* || !m_Stack.size() */) m_eof = true; SearchTreeNode* node = m_pTree->GetNode(m_CurNode); if(!node) return false; node = node->GetParent(m_pTree); if(!node) return false; SearchTreeLinkMap* the_map = &node->m_Children; SearchTreeLinkMap::iterator it = the_map->find(ch); if(it == the_map->end()) m_eof = true; else { m_CurNode = it->second; } return true; }