/** * put a leaf in the tree */ void insertLeaf(SString & fullPubName, SArray<SString> &pathToLeaf, int indexOfChildName){ if ((unsigned)indexOfChildName == pathToLeaf.size()){ // we are in the leaf node if ((getType() & LEAF) == LEAF){ // node already leaf - should NEVER happen - we are trying to //insert a leaf where there is already one throw BrowseException(); } // make the node a leaf (or leaf branch) nodeType = (TreeNodeType)(nodeType | LEAF); pubName = fullPubName; return; } // make the node a branch (or leaf branch) nodeType = (TreeNodeType)(nodeType | BRANCH); SString childNameToLookFor = pathToLeaf[indexOfChildName]; TreeNode * child = children[childNameToLookFor]; if (child == NULL){ child = new TreeNode(childNameToLookFor); AddChild(child); } // Insert leaf lower down the tree child->insertLeaf(fullPubName, pathToLeaf, indexOfChildName+1); }
// copy values of another array void copy (SArray<T> const& orig) { assert(size()==orig.size()); for (size_t idx = 0; idx<size(); ++idx) { storage[idx] = orig.storage[idx]; } }
// copy constructor SArray (SArray<T> const& orig) : storage(new T[orig.size()]), storage_size(orig.size()) { copy(orig); }