diff options
author | vng <viktor.govako@gmail.com> | 2016-02-18 17:37:51 +0300 |
---|---|---|
committer | Sergey Yershov <yershov@corp.mail.ru> | 2016-03-23 16:21:26 +0300 |
commit | ef773229e2da03044e497234ab4a53f6ed1dcc13 (patch) | |
tree | 8c335a583657e6d348df1934eb0b0c5aa5572c1a /indexer/feature_impl.cpp | |
parent | 0cff2e4e4c1416021924a9624f4fcb3a354a0007 (diff) |
Factor out Rank <-> Population functions.
Diffstat (limited to 'indexer/feature_impl.cpp')
-rw-r--r-- | indexer/feature_impl.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/indexer/feature_impl.cpp b/indexer/feature_impl.cpp index b2d53f55e4..a20f19f03d 100644 --- a/indexer/feature_impl.cpp +++ b/indexer/feature_impl.cpp @@ -2,6 +2,7 @@ #include "base/string_utils.hpp" #include "base/logging.hpp" +#include "base/math.hpp" namespace feature @@ -71,4 +72,15 @@ bool IsHouseNumber(strings::UniString const & s) { return (!s.empty() && IsDigit(s[0])); } + +uint8_t PopulationToRank(uint64_t p) +{ + return static_cast<uint8_t>(min(0xFF, my::rounds(log(double(p)) / log(1.1)))); +} + +uint64_t RankToPopulation(uint8_t r) +{ + return (r == 0 ? 1 : static_cast<uint64_t>(my::rounds(pow(1.1, r)))); } + +} // namespace feature |