Minor refactoring.

This commit is contained in:
vng 2014-11-04 17:01:53 +01:00 committed by Alex Zolotarev
parent 6291aab695
commit 7805af6881
3 changed files with 23 additions and 44 deletions

View file

@ -31,7 +31,7 @@ UNIT_TEST(BuildIndexTest)
FeaturesVector featuresVector(originalContainer, header);
MemWriter<vector<char> > serialWriter(serialIndex);
indexer::BuildIndex(ScaleIndexBase::NUM_BUCKETS,
indexer::BuildIndex(ScaleIndexBase::GetBucketsCount(),
scales::GetUpperScale(),
featuresVector, serialWriter,
"build_index_test");

View file

@ -1,4 +1,19 @@
#include "scale_index.hpp"
uint32_t const ScaleIndexBase::kScaleBuckets[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 };
/// Using default one to one mapping.
uint32_t ScaleIndexBase::GetBucketsCount()
{
return 18;
}
uint32_t ScaleIndexBase::BucketByScale(uint32_t scale)
{
return scale;
}
pair<uint32_t, uint32_t> ScaleIndexBase::ScaleRangeForBucket(uint32_t bucket)
{
return make_pair(bucket, bucket + 1);
}

View file

@ -5,56 +5,20 @@
#include "../coding/var_serial_vector.hpp"
#include "../base/assert.hpp"
#include "../base/base.hpp"
#include "../base/macros.hpp"
#include "../base/stl_add.hpp"
#include "../std/algorithm.hpp"
#include "../std/bind.hpp"
/// Index bucket <--> Draw scale range.
class ScaleIndexBase
{
public:
enum { NUM_BUCKETS = 18 };
ScaleIndexBase()
{
#ifdef DEBUG
for (size_t i = 0; i < ARRAY_SIZE(kScaleBuckets); ++i)
{
ASSERT_LESS(kScaleBuckets[i], static_cast<uint32_t>(NUM_BUCKETS), (i));
ASSERT(i == 0 || kScaleBuckets[i] >= kScaleBuckets[i-1],
(i, kScaleBuckets[i-1], kScaleBuckets[i]));
}
#endif
}
static uint32_t BucketByScale(uint32_t scale)
{
ASSERT_LESS(scale, ARRAY_SIZE(kScaleBuckets), ());
return scale >= ARRAY_SIZE(kScaleBuckets) ? NUM_BUCKETS - 1 : kScaleBuckets[scale];
}
static pair<uint32_t, uint32_t> ScaleRangeForBucket(uint32_t bucket)
{
// TODO: Cache ScaleRangeForBucket in class member?
ASSERT_LESS(bucket, static_cast<uint32_t>(NUM_BUCKETS), ());
pair<uint32_t, uint32_t> res(ARRAY_SIZE(kScaleBuckets), 0);
for (uint32_t i = 0; i < ARRAY_SIZE(kScaleBuckets); ++i)
{
if (kScaleBuckets[i] == bucket)
{
res.first = min(res.first, i);
res.second = max(res.second, i + 1);
}
}
return res;
}
private:
static uint32_t const kScaleBuckets[18];
static uint32_t GetBucketsCount();
static uint32_t BucketByScale(uint32_t scale);
/// @return Range like [x, y).
static pair<uint32_t, uint32_t> ScaleRangeForBucket(uint32_t bucket);
};
template <class ReaderT>