RegionsHierarchy: minor modification [#CLICKHOUSE-3427].

This commit is contained in:
Alexey Milovidov 2017-11-16 21:47:59 +03:00
parent edcbf791fb
commit 5ef829c5f3
2 changed files with 21 additions and 19 deletions

View File

@ -86,7 +86,7 @@ void RegionsHierarchy::reload()
if (read_parent_id >= 0)
parent_id = read_parent_id;
RegionType type = read_type;
RegionType type = static_cast<RegionType>(read_type);
if (region_id > max_region_id)
{
@ -122,19 +122,19 @@ void RegionsHierarchy::reload()
/// prescribe the cities and countries for the regions
for (RegionID i = 0; i <= max_region_id; ++i)
{
if (types[i] == REGION_TYPE_CITY)
if (types[i] == RegionType::City)
new_city[i] = i;
if (types[i] == REGION_TYPE_AREA)
if (types[i] == RegionType::Area)
new_area[i] = i;
if (types[i] == REGION_TYPE_DISTRICT)
if (types[i] == RegionType::District)
new_district[i] = i;
if (types[i] == REGION_TYPE_COUNTRY)
if (types[i] == RegionType::Country)
new_country[i] = i;
if (types[i] == REGION_TYPE_CONTINENT)
if (types[i] == RegionType::Continent)
{
new_continent[i] = i;
new_top_continent[i] = i;
@ -156,19 +156,19 @@ void RegionsHierarchy::reload()
if (current > max_region_id)
throw Poco::Exception("Logical error in regions hierarchy: region " + DB::toString(current) + " (specified as parent) doesn't exist");
if (types[current] == REGION_TYPE_CITY)
if (types[current] == RegionType::City)
new_city[i] = current;
if (types[current] == REGION_TYPE_AREA)
if (types[current] == RegionType::Area)
new_area[i] = current;
if (types[current] == REGION_TYPE_DISTRICT)
if (types[current] == RegionType::District)
new_district[i] = current;
if (types[current] == REGION_TYPE_COUNTRY)
if (types[current] == RegionType::Country)
new_country[i] = current;
if (types[current] == REGION_TYPE_CONTINENT)
if (types[current] == RegionType::Continent)
{
if (!new_continent[i])
new_continent[i] = current;

View File

@ -5,13 +5,6 @@
#include <common/Types.h>
#define REGION_TYPE_CITY 6
#define REGION_TYPE_AREA 5
#define REGION_TYPE_DISTRICT 4
#define REGION_TYPE_COUNTRY 3
#define REGION_TYPE_CONTINENT 1
/** A class that lets you know if a region belongs to one RegionID region with another RegionID.
* Information about the hierarchy of regions is downloaded from a text file.
* Can on request update the data.
@ -22,10 +15,19 @@ private:
time_t file_modification_time = 0;
using RegionID = UInt32;
using RegionType = UInt8;
using RegionDepth = UInt8;
using RegionPopulation = UInt32;
enum class RegionType : Int8
{
Hidden = -1,
Continent = 1,
Country = 3,
District = 4,
Area = 5,
City = 6,
};
/// Relationship parent; 0, if there are no parents, the usual lookup table.
using RegionParents = std::vector<RegionID>;
/// type of region