void QuadTree<T>::insert (vertex v, T data, QTNode<T>* node, unsigned depth) { // by design, vertices are stored only in leaf nodes // newly created nodes are leaf nodes by default if (node->leaf){ // there is room in this node's bucket if (node->bucket.size() < maxBucketSize){ node->bucket.push_back ({v, data}); } // bucket is full, so push all vertices to next depth, // clear the current node's bucket and make it a stem else if (depth < maxDepth){ node->leaf = false; insert (v, data, childNode (v, node), depth+1); for (int i=0; i < node->bucket.size(); ++i){ insert (node->bucket[i].first, data, childNode(node->bucket[i].first, node), depth+1); } node->bucket.clear(); } } // current node is a stem node used for navigation else{ insert (v, data, childNode (v, node), depth+1); } }
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(); } }
void VFSNodeUnit::_testWindowsDrivePaths(const VString& driveLetter, const VString& childNodeName, bool adornedWithSlash, bool childIsDirectory) { VString driveLetterNodeName(VSTRING_ARGS("%s:", driveLetter.chars())); VString adornedDriveLetterPath(VSTRING_ARGS("%s:%s", driveLetter.chars(), (adornedWithSlash ? VFSNode::PATH_SEPARATOR_CHARS : ""))); VFSNode driveLetterNode(adornedDriveLetterPath); this->logStatus(VSTRING_FORMAT("Testing '%s'...", adornedDriveLetterPath.chars())); VUNIT_ASSERT_EQUAL_LABELED(driveLetterNode.getName(), driveLetterNodeName, "drive letter node name"); VUNIT_ASSERT_EQUAL_LABELED(driveLetterNode.getParentPath(), "", "drive letter node parent path"); VUNIT_ASSERT_EQUAL_LABELED(driveLetterNode.isDirectory(), true, "drive letter node is dir"); // this test assumes that drive C: exists; not true in some installations VUNIT_ASSERT_EQUAL_LABELED(driveLetterNode.isFile(), false, "drive letter node is not file"); VString adornedChildNodePath(VSTRING_ARGS("%s:%s%s", driveLetter.chars(), (adornedWithSlash ? VFSNode::PATH_SEPARATOR_CHARS : ""), childNodeName.chars())); VFSNode childNode(driveLetterNode, childNodeName); this->logStatus(VSTRING_FORMAT("Testing '%s'...", adornedChildNodePath.chars())); VUNIT_ASSERT_EQUAL_LABELED(childNode.getName(), childNodeName, "drive letter child node name"); VUNIT_ASSERT_EQUAL_LABELED(childNode.getParentPath(), driveLetterNodeName, "drive letter child node parent path"); VUNIT_ASSERT_EQUAL_LABELED(childNode.isDirectory(), childIsDirectory, "drive letter child node is/not dir check"); // this test assumes that C:Windows dir exists; not true in some installations VUNIT_ASSERT_EQUAL_LABELED(childNode.isFile(), !childIsDirectory, "drive letter child node is/not file check"); VString childFileName("child.txt"); VString expectedChildPath(VSTRING_ARGS("%s:%c%s", driveLetter.chars(), VFSNode::PATH_SEPARATOR_CHAR, childFileName.chars())); VFSNode childFileNode(driveLetterNode, childFileName); this->logStatus(VSTRING_FORMAT("Testing '%s + %s'...", adornedDriveLetterPath.chars(), childFileName.chars())); VUNIT_ASSERT_EQUAL_LABELED(childFileNode.getName(), childFileName, "drive letter child file node name"); VUNIT_ASSERT_EQUAL_LABELED(childFileNode.getParentPath(), driveLetterNodeName, "drive letter child file node parent path"); VUNIT_ASSERT_EQUAL_LABELED(childFileNode.getPath(), expectedChildPath, "drive letter child file node path"); }
void OsmAnd::ObfMapSectionReader_P::readTreeNodeChildren( const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<const ObfMapSectionInfo>& section, const std::shared_ptr<ObfMapSectionLevelTreeNode>& treeNode, MapFoundationType& foundation, QList< std::shared_ptr<ObfMapSectionLevelTreeNode> >* nodesWithData, const AreaI* bbox31, IQueryController* controller) { auto cis = reader->_codedInputStream.get(); for(;;) { auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: return; case OBF::OsmAndMapIndex_MapDataBox::kBoxesFieldNumber: { auto length = ObfReaderUtilities::readBigEndianInt(cis); auto offset = cis->CurrentPosition(); auto oldLimit = cis->PushLimit(length); std::shared_ptr<ObfMapSectionLevelTreeNode> childNode(new ObfMapSectionLevelTreeNode()); childNode->_foundation = treeNode->_foundation; childNode->_offset = offset; childNode->_length = length; readTreeNode(reader, section, treeNode->_area31, childNode); if(bbox31 && !bbox31->intersects(childNode->_area31)) { cis->Skip(cis->BytesUntilLimit()); cis->PopLimit(oldLimit); break; } cis->PopLimit(oldLimit); if(childNode->_foundation != MapFoundationType::Undefined) { if(foundation == MapFoundationType::Undefined) foundation = childNode->_foundation; else if(foundation != childNode->_foundation) foundation = MapFoundationType::Mixed; } if(nodesWithData && childNode->_dataOffset > 0) nodesWithData->push_back(childNode); cis->Seek(offset); oldLimit = cis->PushLimit(length); cis->Skip(childNode->_childrenInnerOffset); readTreeNodeChildren(reader, section, childNode, foundation, nodesWithData, bbox31, controller); assert(cis->BytesUntilLimit() == 0); cis->PopLimit(oldLimit); } break; default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }
node makeChild() { Board childBoard = board; int move; if (!clockwiseChild) { clockwiseChild = true; childBoard.moveForward(); move = 0; } else if (!counterChild) { counterChild = true; childBoard.moveBackwards(); move = 1; } else if (!rotateChild) { rotateChild = true; childBoard.rotate(); move = 2; } else if( rotateChild && clockwiseChild && counterChild) { std::cout << "tried to makechild of full node" << std::endl; } else { } node childNode(depth + 1, childBoard, this); childNode.lastMove = move; return childNode; }
QXmlTreeNode* QXmlTreeNode::child(const QDomNode &node) { unsigned int childCount = childs(); for (unsigned int i = 0; i < childCount; ++i) { QXmlTreeNode* childNode(m_childItems[i]); if (childNode->xmlNode() == node) return childNode; // Depth Search childNode = childNode->child(node); if (childNode) return childNode; } return 0; }
void OsmAnd::ObfMapSectionReader_P::readTreeNodeChildren( const std::unique_ptr<ObfReader_P>& reader, const std::shared_ptr<const ObfMapSectionInfo>& section, const std::shared_ptr<ObfMapSectionLevelTreeNode>& treeNode, MapFoundationType& foundation, QList< std::shared_ptr<ObfMapSectionLevelTreeNode> >* nodesWithData, const AreaI* bbox31, const IQueryController* const controller, ObfMapSectionReader_Metrics::Metric_loadMapObjects* const metric) { auto cis = reader->_codedInputStream.get(); foundation = MapFoundationType::Undefined; for(;;) { auto tag = cis->ReadTag(); switch(gpb::internal::WireFormatLite::GetTagFieldNumber(tag)) { case 0: return; case OBF::OsmAndMapIndex_MapDataBox::kBoxesFieldNumber: { auto length = ObfReaderUtilities::readBigEndianInt(cis); auto offset = cis->CurrentPosition(); auto oldLimit = cis->PushLimit(length); std::shared_ptr<ObfMapSectionLevelTreeNode> childNode(new ObfMapSectionLevelTreeNode(treeNode->level)); childNode->_foundation = treeNode->_foundation; childNode->_offset = offset; childNode->_length = length; readTreeNode(reader, section, treeNode->_area31, childNode); // Update metric if(metric) metric->visitedNodes++; if(bbox31) { const auto shouldSkip = !bbox31->contains(childNode->_area31) && !childNode->_area31.contains(*bbox31) && !bbox31->intersects(childNode->_area31); if(shouldSkip) { cis->Skip(cis->BytesUntilLimit()); cis->PopLimit(oldLimit); break; } } cis->PopLimit(oldLimit); // Update metric if(metric) metric->acceptedNodes++; if(nodesWithData && childNode->_dataOffset > 0) nodesWithData->push_back(childNode); auto childrenFoundation = MapFoundationType::Undefined; if(childNode->_childrenInnerOffset > 0) { cis->Seek(offset); oldLimit = cis->PushLimit(length); cis->Skip(childNode->_childrenInnerOffset); readTreeNodeChildren(reader, section, childNode, childrenFoundation, nodesWithData, bbox31, controller, metric); assert(cis->BytesUntilLimit() == 0); cis->PopLimit(oldLimit); } const auto foundationToMerge = (childrenFoundation != MapFoundationType::Undefined) ? childrenFoundation : childNode->_foundation; if(foundationToMerge != MapFoundationType::Undefined) { if(foundation == MapFoundationType::Undefined) foundation = foundationToMerge; else if(foundation != foundationToMerge) foundation = MapFoundationType::Mixed; } } break; default: ObfReaderUtilities::skipUnknownField(cis, tag); break; } } }