ClickHouse/src/Dictionaries/PolygonDictionaryImplementations.h

100 lines
3.0 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-05-24 12:09:36 +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-05-24 12:09:36 +00:00
*/
class PolygonDictionarySimple : public IPolygonDictionary
2020-02-18 13:32:18 +00:00
{
public:
PolygonDictionarySimple(
2020-02-18 13:32:18 +00:00
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;
};
/** A polygon dictionary which generates a recursive grid in order to efficiently cut the number
* of polygons to be checked for a given point.
* For more detail see the GridRoot and FinalCell classes.
* Separately, a slab index is built for each individual polygon. This allows to check the
* candidates more efficiently.
2020-05-24 12:09:36 +00:00
*/
class PolygonDictionaryIndexEach : public IPolygonDictionary
2020-02-18 13:32:18 +00:00
{
public:
PolygonDictionaryIndexEach(
const std::string & database_,
const std::string & name_,
const DictionaryStructure & dict_struct_,
DictionarySourcePtr source_ptr_,
DictionaryLifetime dict_lifetime_,
InputType input_type_,
PointType point_type_,
int min_intersections_,
int max_depth_);
std::shared_ptr<const IExternalLoadable> clone() const override;
2020-05-24 23:16:04 +00:00
static constexpr size_t kMinIntersectionsDefault = 1;
static constexpr size_t kMaxDepthDefault = 5;
private:
bool find(const Point & point, size_t & id) const override;
2020-05-24 12:09:36 +00:00
std::vector<SlabsPolygonIndex> buckets;
2020-05-21 00:50:19 +00:00
GridRoot<FinalCell> grid;
const size_t min_intersections;
const size_t max_depth;
};
2020-05-24 12:09:36 +00:00
/** Uses single SlabsPolygonIndex for all queries. */
class PolygonDictionaryIndexCell : public IPolygonDictionary
2020-03-23 00:16:46 +00:00
{
public:
PolygonDictionaryIndexCell(
2020-03-23 00:16:46 +00:00
const std::string & database_,
const std::string & name_,
const DictionaryStructure & dict_struct_,
DictionarySourcePtr source_ptr_,
DictionaryLifetime dict_lifetime_,
InputType input_type_,
PointType point_type_,
size_t min_intersections_,
size_t max_depth_);
2020-03-23 00:16:46 +00:00
std::shared_ptr<const IExternalLoadable> clone() const override;
2020-05-24 23:16:04 +00:00
static constexpr size_t kMinIntersectionsDefault = 1;
static constexpr size_t kMaxDepthDefault = 5;
2020-03-23 00:16:46 +00:00
private:
bool find(const Point & point, size_t & id) const override;
GridRoot<FinalCellWithSlabs> index;
const size_t min_intersections;
const size_t max_depth;
2020-03-23 00:16:46 +00:00
};
}