#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace ProfileEvents { extern const Event PolygonsAddedToPool; extern const Event PolygonsInPoolAllocatedBytes; } namespace DB { namespace ErrorCodes { extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION; extern const int BAD_ARGUMENTS; extern const int ILLEGAL_TYPE_OF_ARGUMENT; } namespace FunctionPointInPolygonDetail { template ColumnPtr callPointInPolygonImplWithPool(const IColumn & x, const IColumn & y, Polygon & polygon) { using Pool = ObjectPoolMap; /// C++11 has thread-safe function-local statics on most modern compilers. static Pool known_polygons; auto factory = [& polygon]() { GeoUtils::normalizePolygon(polygon); auto ptr = std::make_unique(polygon); /// To allocate memory. ptr->init(); ProfileEvents::increment(ProfileEvents::PolygonsAddedToPool); ProfileEvents::increment(ProfileEvents::PolygonsInPoolAllocatedBytes, ptr->getAllocatedBytes()); return ptr.release(); }; std::string serialized_polygon = GeoUtils::serialize(polygon); auto impl = known_polygons.get(serialized_polygon, factory); return GeoUtils::pointInPolygon(x, y, *impl); } template ColumnPtr callPointInPolygonImpl(const IColumn & x, const IColumn & y, Polygon & polygon) { PointInPolygonImpl impl(polygon); return GeoUtils::pointInPolygon(x, y, impl); } } template