bool Lexicon::containsPrefix(const std::string& prefix) const { if (prefix.empty()) { return true; } std::string scrubbed = prefix; if (!scrub(scrubbed)) { return false; } return containsHelper(m_root, scrubbed, /* isPrefix */ true); }
bool Lexicon::contains(const std::string& word) const { if (word.empty()) { return false; } std::string scrubbed = word; if (!scrub(scrubbed)) { return false; } return containsHelper(m_root, scrubbed, /* isPrefix */ false); }
// pre: word is scrubbed to contain only lowercase a-z letters bool Lexicon::containsHelper(TrieNode* node, const std::string& word, bool isPrefix) const { if (node == NULL) { // base case: no pointer down to here, so prefix must not exist return false; } else if (word.length() == 0) { // base case: Found nodes all the way down. // If we are looking for a prefix, this means this path IS a prefix, // so we should return true. // If we are looking for an exact word match rather than a prefix, // we must check the isWord flag to see that this word was added return (isPrefix ? true : node->isWord()); } else { // recursive case: follow appropriate child pointer for one letter return containsHelper(node->child(word[0]), word.substr(1), isPrefix); } }
void OsmAnd::MapRasterizer_P::rasterizePolygon( const Context& context, SkCanvas& canvas, const std::shared_ptr<const MapPrimitiviser::Primitive>& primitive) { const auto& points31 = primitive->sourceObject->points31; const auto& area31 = context.area31; assert(points31.size() > 2); assert(primitive->sourceObject->isClosedFigure()); assert(primitive->sourceObject->isClosedFigure(true)); ////////////////////////////////////////////////////////////////////////// //if ((primitive->sourceObject->id >> 1) == 9223372032559801460u) //{ // int i = 5; //} ////////////////////////////////////////////////////////////////////////// SkPaint paint = _defaultPaint; if (!updatePaint(context, paint, primitive->evaluationResult, PaintValuesSet::Layer_1, true)) return; // Construct and test geometry against bbox area SkPath path; bool containsAtLeastOnePoint = false; int pointIdx = 0; PointF vertex; Utilities::CHValue prevChValue; QVector< PointI > outerPoints; const auto pointsCount = points31.size(); auto pPoint = points31.constData(); for (auto pointIdx = 0; pointIdx < pointsCount; pointIdx++, pPoint++) { const auto& point = *pPoint; calculateVertex(context, point, vertex); // Hit-test if (!containsAtLeastOnePoint) { if (area31.contains(point)) containsAtLeastOnePoint = true; else outerPoints.push_back(point); const auto chValue = Utilities::computeCohenSutherlandValue(point, area31); if (Q_LIKELY(pointIdx > 0)) { // Check if line crosses area (reject only if points are on the same side) const auto intersectedChValue = prevChValue & chValue; if (static_cast<unsigned int>(intersectedChValue) != 0) containsAtLeastOnePoint = true; } prevChValue = chValue; } // Plot vertex if (pointIdx == 0) path.moveTo(vertex.x, vertex.y); else path.lineTo(vertex.x, vertex.y); } ////////////////////////////////////////////////////////////////////////// //if ((primitive->sourceObject->id >> 1) == 9223372032559801460u) //{ // int i = 5; //} ////////////////////////////////////////////////////////////////////////// if (!containsAtLeastOnePoint) { // Check area is inside polygon bool ok = true; ok = ok || containsHelper(outerPoints, area31.topLeft); ok = ok || containsHelper(outerPoints, area31.bottomRight); ok = ok || containsHelper(outerPoints, PointI(0, area31.bottom())); ok = ok || containsHelper(outerPoints, PointI(area31.right(), 0)); if (!ok) return; } ////////////////////////////////////////////////////////////////////////// //if ((primitive->sourceObject->id >> 1) == 95692962u) //{ // int i = 5; //} ////////////////////////////////////////////////////////////////////////// if (!primitive->sourceObject->innerPolygonsPoints31.isEmpty()) { path.setFillType(SkPath::kEvenOdd_FillType); for (const auto& polygon : constOf(primitive->sourceObject->innerPolygonsPoints31)) { pointIdx = 0; for (auto itVertex = cachingIteratorOf(constOf(polygon)); itVertex; ++itVertex, pointIdx++) { const auto& point = *itVertex; calculateVertex(context, point, vertex); if (pointIdx == 0) path.moveTo(vertex.x, vertex.y); else path.lineTo(vertex.x, vertex.y); } } } canvas.drawPath(path, paint); if (updatePaint(context, paint, primitive->evaluationResult, PaintValuesSet::Layer_2, false)) canvas.drawPath(path, paint); }