void Node::insertNode(std::unique_ptr<Node> node) { assert( env->contains(node->getEnvelope()) ); int index = getSubnodeIndex(node->getEnvelope(), centre); assert(index >= 0); if (node->level == level-1) { // We take ownership of node delete subnodes[index]; subnodes[index] = node.release(); //System.out.println("inserted"); } else { // the quad is not a direct child, so make a new child // quad to contain it and recursively insert the quad std::unique_ptr<Node> childNode ( createSubnode(index) ); // childNode takes ownership of node childNode->insertNode(std::move(node)); // We take ownership of childNode delete subnodes[index]; subnodes[index] = childNode.release(); } }
/*public*/ NodeBase* Node::find(const Envelope *searchEnv) { int subnodeIndex=getSubnodeIndex(searchEnv, centre); if (subnodeIndex==-1) return this; if (subnodes[subnodeIndex]!=nullptr) { // query lies in subquad, so search it Node *node=subnodes[subnodeIndex]; return node->find(searchEnv); } // no existing subquad, so return this one anyway return this; }
/*public*/ Node* Node::getNode(const Envelope *searchEnv) { int subnodeIndex=getSubnodeIndex(searchEnv, centre); // if subquadIndex is -1 searchEnv is not contained in a subquad if (subnodeIndex!=-1) { // create the quad if it does not exist Node *node=getSubnode(subnodeIndex); // recursively search the found/created quad return node->getNode(searchEnv); } else { return this; } }
/** * Returns the smallest <i>existing</i> * node containing the envelope. */ NodeBase* Node::find(Interval *searchInterval) { int subnodeIndex=getSubnodeIndex(searchInterval,centre); if (subnodeIndex==-1) return this; if (subnode[subnodeIndex]!=NULL) { // query lies in subnode, so search it Node *node=subnode[subnodeIndex]; return node->find(searchInterval); } // no existing subnode, so return this one anyway return this; }
/** * Returns the subnode containing the envelope. * Creates the node if * it does not already exist. */ Node* Node::getNode(Interval *searchInterval) { int subnodeIndex=getSubnodeIndex(searchInterval,centre); // if index is -1 searchEnv is not contained in a subnode if (subnodeIndex!=-1) { // create the node if it does not exist Node* node=getSubnode(subnodeIndex); // recursively search the found/created node return node->getNode(searchInterval); } else { return this; } }
void Node::insert(Node *node) { assert(interval==NULL || interval->contains(node->interval)); int index=getSubnodeIndex(node->interval,centre); assert(index >= 0); if (node->level==level-1) { subnode[index]=node; } else { // the node is not a direct child, so make a new child node to contain it // and recursively insert the node Node* childNode=createSubnode(index); childNode->insert(node); subnode[index]=childNode; } }
void Node::insertNode(Node* node) { assert(env==NULL || env->contains(node->env)); //System.out.println(env); //System.out.println(quad.env); int index=getSubnodeIndex(node->env, centre); //System.out.println(index); if (node->level==level-1) { subnode[index]=node; //System.out.println("inserted"); } else { // the quad is not a direct child, so make a new child quad to contain it // and recursively insert the quad Node *childNode=createSubnode(index); childNode->insertNode(node); subnode[index]=childNode; } }
/*public*/ void Root::insert(const Envelope *itemEnv, void* item) { #if GEOS_DEBUG std::cerr<< "Root("<<this<<")::insert("<<itemEnv->toString()<<", "<<item<<") called"<<std::endl; #endif int index = getSubnodeIndex(itemEnv, origin); // if index is -1, itemEnv must cross the X or Y axis. if (index==-1) { #if GEOS_DEBUG std::cerr<<" -1 subnode index"<<std::endl; #endif add(item); return; } /* * the item must be contained in one quadrant, so insert it into the * tree for that quadrant (which may not yet exist) */ Node *node = subnode[index]; #if GEOS_DEBUG std::cerr<<"("<<this<<") subnode["<<index<<"] @ "<<node<<std::endl; #endif /* * If the subquad doesn't exist or this item is not contained in it, * have to expand the tree upward to contain the item. */ if (node==NULL || !node->getEnvelope()->contains(itemEnv)) { std::auto_ptr<Node> snode (node); // may be NULL node = 0; subnode[index] = 0; std::auto_ptr<Node> largerNode = Node::createExpanded(snode, *itemEnv); #if GEOS_DEBUG std::cerr<<"("<<this<<") created expanded node " << largerNode.get() << " containing previously reported subnode" << std::endl; #endif // Previous subnode was passed as a child of the larger one assert(!subnode[index]); subnode[index] = largerNode.release(); } #if GEOS_DEBUG std::cerr<<"("<<this<<") calling insertContained with subnode " << subnode[index] << std::endl; #endif /* * At this point we have a subquad which exists and must contain * contains the env for the item. Insert the item into the tree. */ insertContained(subnode[index], itemEnv, item); #if GEOS_DEBUG std::cerr<<"("<<this<<") done calling insertContained with subnode " << subnode[index] << std::endl; #endif //System.out.println("depth = " + root.depth() + " size = " + root.size()); //System.out.println(" size = " + size()); }