ClickHouse/dbms/src/Dictionaries/PolygonDictionaryImplementations.h

81 lines
2.6 KiB
C++
Raw Normal View History

2020-02-18 13:32:18 +00:00
#pragma once
#include "PolygonDictionary.h"
#include "PolygonDictionaryUtils.h"
namespace DB
{
/** Simple implementation of the polygon dictionary. Doesn't generate anything during its construction.
2020-02-21 13:44:07 +00:00
* Iterates over all stored polygons for each query, checking each of them in linear time.
* Retrieves the polygon with the smallest area containing the given point. If there is more than one any such polygon
* may be returned.
2020-02-18 13:32:18 +00:00
*/
class SimplePolygonDictionary : public IPolygonDictionary
{
public:
SimplePolygonDictionary(
const std::string & database_,
const std::string & name_,
const DictionaryStructure & dict_struct_,
DictionarySourcePtr source_ptr_,
DictionaryLifetime dict_lifetime_,
InputType input_type_,
PointType point_type_);
std::shared_ptr<const IExternalLoadable> clone() const override;
private:
bool find(const Point & point, size_t & id) const override;
};
2020-02-21 13:44:07 +00:00
/** A polygon dictionary which generates a recursive grid in order to efficiently cut the number of polygons to be
* checked slowly for a given point. For more detail see the GridRoot class.
* Retrieves the polygon with the smallest area containing the given point. If there is more than one any such polygon
* may be returned.
*/
2020-02-18 13:32:18 +00:00
class GridPolygonDictionary : public IPolygonDictionary
{
public:
GridPolygonDictionary(
const std::string & database_,
const std::string & name_,
const DictionaryStructure & dict_struct_,
DictionarySourcePtr source_ptr_,
DictionaryLifetime dict_lifetime_,
InputType input_type_,
PointType point_type_);
std::shared_ptr<const IExternalLoadable> clone() const override;
private:
bool find(const Point & point, size_t & id) const override;
GridRoot grid;
static constexpr size_t kMinIntersections = 1;
static constexpr size_t kMaxDepth = 7;
2020-02-18 13:32:18 +00:00
};
/** Smart implementation of the polygon dictionary. Uses BucketsPolygonIndex. */
class SmartPolygonDictionary : public IPolygonDictionary
{
public:
SmartPolygonDictionary(
const std::string & database_,
const std::string & name_,
const DictionaryStructure & dict_struct_,
DictionarySourcePtr source_ptr_,
DictionaryLifetime dict_lifetime_,
InputType input_type_,
PointType point_type_);
std::shared_ptr<const IExternalLoadable> clone() const override;
private:
bool find(const Point & point, size_t & id) const override;
BucketsPolygonIndex buckets_idx;
};
}