Changeset 2269 for XIOS/dev/dev_ym/XIOS_COUPLING/extern/remap/src/node.cpp
- Timestamp:
- 12/07/21 12:00:23 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_ym/XIOS_COUPLING/extern/remap/src/node.cpp
r2198 r2269 79 79 /* On level `level` find the node in our subtree that is closest to `src` and return through argument `closest`. 80 80 The return value is just for recursive calling */ 81 void Node::findClosest(int level, NodePtr src, double& minDist2, NodePtr &closest)81 void Node::findClosest(int level, NodePtr src, double& minDist2, NodePtr& closest) 82 82 { 83 83 double r2; … … 89 89 { 90 90 minDist2 = r2; 91 closest = this;91 closest = shared_from_this(); 92 92 } 93 93 } … … 221 221 }*/ 222 222 223 bool find_in_tree1(Node *node)223 bool find_in_tree1(NodePtr node) 224 224 { 225 225 if (node == node->tree->root) return true; 226 if (node->parent == NULL)226 if (node->parent.lock() == NULL) 227 227 { 228 228 cerr << "Cannot find!" << endl; 229 229 return false; 230 230 } 231 return find_in_tree1(node->parent );231 return find_in_tree1(node->parent.lock()); 232 232 } 233 233 … … 264 264 { 265 265 node->child.push_back(thIs); 266 thIs->parent = node ;266 thIs->parent = node ; 267 267 if (node->child.size() > MAX_NODE_SZ && node->tree->canSplit() ) // with us as additional child `node` is now too large :( 268 return (node->reinserted || node->parent == NULL) ? split(node) : reinsert(node);268 return (node->reinserted || node->parent.lock() == NULL) ? split(node) : reinsert(node); 269 269 } 270 270 else // la < lb - 1 … … 299 299 300 300 /* transfere out children from us to a new node q which will be returned */ 301 NodePtr q = new Node;301 NodePtr q = make_shared<Node>(); 302 302 q->tree = thIs->tree; 303 303 q->child.resize(out); … … 462 462 { 463 463 thIs->tree->increaseLevelSize(thIs->level); 464 NodePtr p = new Node;465 NodePtr q = new Node;464 NodePtr p = make_shared<Node>(); 465 NodePtr q = make_shared<Node>(); 466 466 p->level = q->level = thIs->level; 467 467 p->reinserted = q->reinserted = false; 468 p->parent = q->parent = thIs->parent; 468 p->parent = thIs->parent; 469 q->parent = thIs->parent; 469 470 p->tree = q->tree = thIs->tree; 470 471 … … 476 477 std::sort(thIs->child.begin(), thIs->child.end(), compareDist); 477 478 for (int i = 0; i < MAX_NODE_SZ+1; i++) 478 assert(thIs->child[i]->parent == thIs);479 assert(thIs->child[i]->parent.lock() == thIs); 479 480 for (int i = 0; i < MAX_NODE_SZ/2 + 1; i++) 480 481 q->child[i] = thIs->child[i]; … … 496 497 thIs->reinserted = p->reinserted; 497 498 thIs->update(); 498 delete p;499 p.reset(); 499 500 500 501 if (thIs == thIs->tree->root) // root split … … 593 594 594 595 for (int i = 0; i < childSize; i++) 595 assert(child[i]->parent == this);596 assert(child[i]->parent.lock() == shared_from_this()); 596 597 597 598 if (level>0) for (int i = 0; i < childSize; i++) child[i]->checkParent() ; … … 602 603 cout << "level " << this->level << ", centre "; 603 604 cout << "level " << this->level << ", centre " << this->centre << "\t r = " << this->radius << endl; 604 cout << this << " p: " << this->parent << endl;605 cout << this << " p: " << this->parent.lock() << endl; 605 606 int n = this->child.size(); 606 607 for (int i=0; i<n; i++) … … 656 657 double distMin2 = 0; // squared distance 657 658 closest = NULL; 658 if (tree->root == this)659 if (tree->root == shared_from_this()) 659 660 findClosest(level, node, distMin2, closest); 660 661 661 if (closest != NULL && tree->root == this)662 if (closest != NULL && tree->root == shared_from_this()) 662 663 /* When is this point reached? 663 664 if the preceeding findClosest was called and succesed to set closest … … 690 691 } 691 692 692 void Node::routingIntersecting(vector<Node > *routingList, NodePtr node)693 void Node::routingIntersecting(vector<NodePtr> *routingList, NodePtr node) 693 694 { 694 695 if (level==0) 695 696 { 696 697 int rank = route; 697 routingList[rank].push_back( *node);698 routingList[rank].push_back(node); 698 699 } 699 700 else … … 712 713 child[i]->free_descendants(); 713 714 if (child[i]->level) // do not attempt to delete leafs, they are delete through leafs vector 714 delete child[i];715 child[i].reset(); 715 716 } 716 717 } … … 718 719 void Node::getNodeLevel(int assignLevel, std::list<NodePtr>& NodeList) 719 720 { 720 if (level==assignLevel) NodeList.push_back( this) ;721 if (level==assignLevel) NodeList.push_back(shared_from_this()) ; 721 722 else if (level>0) for (int i = 0; i < child.size(); i++) child[i]->getNodeLevel(assignLevel,NodeList) ; 722 723 return ; … … 737 738 for (int j = 0; j < child[i]->child.size(); j++) tree->push_back(child[i]->child[j]) ; 738 739 tree->decreaseLevelSize(assignLevel) ; 739 delete child[i];740 child[i].reset() ; 740 741 } 741 742 else newChild.push_back(child[i]) ;
Note: See TracChangeset
for help on using the changeset viewer.