ClickHouse/src/Dictionaries/PolygonDictionaryImplementations.h

111 lines
3.5 KiB
C++
Raw Normal View History

2020-02-18 13:32:18 +00:00
#pragma once
#include "PolygonDictionary.h"
#include "PolygonDictionaryUtils.h"
#include <vector>
2020-02-18 13:32:18 +00:00
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;
2020-05-21 02:01:41 +00:00
GridRoot<FinalCell> grid;
static constexpr size_t kMinIntersections = 1;
2020-03-23 00:14:20 +00:00
static constexpr size_t kMaxDepth = 5;
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;
std::vector<BucketsPolygonIndex> buckets;
2020-05-21 00:50:19 +00:00
GridRoot<FinalCell> grid;
2020-03-22 22:26:42 +00:00
static constexpr size_t kMinIntersections = 1;
2020-03-23 00:14:20 +00:00
static constexpr size_t kMaxDepth = 5;
};
2020-03-23 00:16:46 +00:00
/** Uses single BucketsPolygonIndex for all queries. */
class OneBucketPolygonDictionary : public IPolygonDictionary
{
public:
OneBucketPolygonDictionary(
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<FinalCellWithSlabs> index;
static constexpr size_t kMinIntersections = 1;
static constexpr size_t kMaxDepth = 5;
2020-03-23 00:16:46 +00:00
};
}