Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYury Melnichek <melnichek@gmail.com>2011-01-03 20:51:24 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:09:11 +0300
commit22c2ab6839d5bbec9f3a2639483ddfe5732b1fcb (patch)
treec6633a87a210b05913d0522323b6defa0f30b228
parentf2871f3fd2b16fcce0525e0fb4e9af013f60916f (diff)
Refactor index to use FilesContainer and pass occlusionRect (unused for now) with query.
-rw-r--r--geometry/rect2d.hpp11
-rw-r--r--indexer/index.hpp32
-rw-r--r--indexer/indexer_tests/index_builder_test.cpp3
-rw-r--r--indexer/indexer_tests/index_test.cpp28
-rw-r--r--map/feature_vec_model.cpp8
-rw-r--r--map/feature_vec_model.hpp2
6 files changed, 54 insertions, 30 deletions
diff --git a/geometry/rect2d.hpp b/geometry/rect2d.hpp
index 40109415bf..a4cd5a6b79 100644
--- a/geometry/rect2d.hpp
+++ b/geometry/rect2d.hpp
@@ -17,6 +17,7 @@ namespace m2
template <typename T> struct min_max_value<T, true>
{
T get_min() { return numeric_limits<T>::max(); }
+ // TODO: There is an overflow here: -(-128) != 127.
T get_max() { return -get_min(); }
};
template <typename T> struct min_max_value<T, false>
@@ -52,6 +53,16 @@ namespace m2
{
}
+ static Rect GetEmptyRect() { return Rect(); }
+
+ static Rect GetInfiniteRect()
+ {
+ T const tMax = numeric_limits<T>::max();
+ // This works for both ints and floats.
+ T const tMin = min(-tMax, numeric_limits<T>::min());
+ return Rect(tMin, tMin, tMax, tMax);
+ }
+
void MakeEmpty()
{
m_minX = m_minY = impl::min_max_value<T, numeric_limits<T>::is_signed>().get_min();
diff --git a/indexer/index.hpp b/indexer/index.hpp
index 160a31aa45..8f6666291e 100644
--- a/indexer/index.hpp
+++ b/indexer/index.hpp
@@ -6,8 +6,10 @@
#include "scales.hpp"
#include "../geometry/rect2d.hpp"
+#include "../coding/file_container.hpp"
#include "../coding/varint.hpp"
#include "../base/base.hpp"
+#include "../base/macros.hpp"
#include "../base/stl_add.hpp"
#include "../std/string.hpp"
@@ -26,7 +28,8 @@ public:
{
vector<pair<int64_t, int64_t> > intervals = covering::CoverViewportAndAppendLowerLevels(rect);
for (size_t i = 0; i < intervals.size(); ++i)
- BaseT::ForEachInIntervalAndScale(f, intervals[i].first, intervals[i].second, scale, query);
+ BaseT::ForEachInIntervalAndScale(f, intervals[i].first, intervals[i].second, scale,
+ rect, query);
}
template <typename F>
@@ -53,7 +56,8 @@ public:
void ForEachInScale(F const & f, uint32_t scale, Query & query) const
{
int64_t const rootId = RectId("").ToInt64();
- BaseT::ForEachInIntervalAndScale(f, rootId, rootId + RectId("").SubTreeSize(), scale, query);
+ BaseT::ForEachInIntervalAndScale(f, rootId, rootId + RectId("").SubTreeSize(), scale,
+ m2::RectD::GetInfiniteRect(), query);
}
template <typename F>
@@ -76,16 +80,20 @@ public:
template <typename F>
void ForEachInIntervalAndScale(F const & f, int64_t beg, int64_t end, uint32_t scale,
- Query & query) const
+ m2::RectD const & occlusionRect, Query & query) const
{
+ // TODO: Use occlusionRect.
+ UNUSED_VALUE(occlusionRect);
for (size_t i = 0; i < m_Indexes.size(); ++i)
m_Indexes[i]->ForEachInIntervalAndScale(f, beg, end, scale, query);
}
- template <class DatReaderT, class IndexReaderT>
- void Add(FeatureReaders<DatReaderT> const & dataR, IndexReaderT const & indexR)
+ void Add(string const & path)
{
- m_Indexes.push_back(new IndexT(dataR, indexR));
+ uint32_t const logPageSize = 12;
+ uint32_t const logPageCount = 12;
+ FilesContainerR container(path, logPageSize, logPageCount);
+ m_Indexes.push_back(new IndexT(container));
}
bool IsExist(string const & dataPath) const
@@ -123,9 +131,9 @@ template <class FeatureVectorT, class BaseT> class OffsetToFeatureAdapter : publ
public:
typedef typename BaseT::Query Query;
- OffsetToFeatureAdapter( FeatureReaders<typename FeatureVectorT::ReaderType> const & dataR,
- typename BaseT::ReaderType const & indexR)
- : BaseT(indexR), m_FeatureVector(dataR)
+ explicit OffsetToFeatureAdapter(FilesContainerR const & container)
+ : BaseT(container.GetReader(INDEX_FILE_TAG)),
+ m_FeatureVector(FeatureReaders<FileReader>(container))
{
}
@@ -207,14 +215,14 @@ private:
};
};
-template <typename DataReaderT, typename IndexReaderT>
+template <typename ReaderT>
struct Index
{
typedef IndexForEachAdapter<
MultiIndexAdapter<
- OffsetToFeatureAdapter<FeaturesVector<DataReaderT>,
+ OffsetToFeatureAdapter<FeaturesVector<ReaderT>,
UniqueOffsetAdapter<
- ScaleIndex<IndexReaderT>
+ ScaleIndex<ReaderT>
>
>
>
diff --git a/indexer/indexer_tests/index_builder_test.cpp b/indexer/indexer_tests/index_builder_test.cpp
index a6fa3f4827..8ab256bc37 100644
--- a/indexer/indexer_tests/index_builder_test.cpp
+++ b/indexer/indexer_tests/index_builder_test.cpp
@@ -28,7 +28,10 @@ UNIT_TEST(BuildIndexTest)
indexer::BuildIndex(featuresVector, serialWriter, "build_index_test");
}
+ // TODO: Restore unit test!
+ /*
MemReader indexReader(&serial[0], serial.size());
Index<FileReader, MemReader>::Type index;
index.Add(FeatureReaders<FileReader>(container), indexReader);
+ */
}
diff --git a/indexer/indexer_tests/index_test.cpp b/indexer/indexer_tests/index_test.cpp
index fb9f18b5c5..42118fdd1b 100644
--- a/indexer/indexer_tests/index_test.cpp
+++ b/indexer/indexer_tests/index_test.cpp
@@ -1,21 +1,29 @@
-#include "../../base/SRC_FIRST.hpp"
-
+#include "../../testing/testing.hpp"
#include "../index.hpp"
#include "../index_builder.hpp"
-
-#include "../../testing/testing.hpp"
-
+#include "../../platform/platform.hpp"
#include "../../coding/file_container.hpp"
+#include "../../base/macros.hpp"
+#include "../../std/string.hpp"
-#include "../../platform/platform.hpp"
+namespace
+{
-#include "../../std/string.hpp"
+struct NoopFunctor
+{
+ template <typename T> void operator () (T const & value) const
+ {
+ UNUSED_VALUE(value);
+ }
+};
+}
UNIT_TEST(IndexParseTest)
{
- FilesContainerR container(GetPlatform().WritablePathForFile("minsk-pass" DATA_FILE_EXTENSION));
+ Index<FileReader>::Type index;
+ index.Add(GetPlatform().WritablePathForFile("minsk-pass" DATA_FILE_EXTENSION));
- Index<FileReader, FileReader>::Type index;
- index.Add(FeatureReaders<FileReader>(container), container.GetReader(INDEX_FILE_TAG));
+ // Make sure that index is actually parsed.
+ index.ForEachInScale(NoopFunctor(), 15);
}
diff --git a/map/feature_vec_model.cpp b/map/feature_vec_model.cpp
index 4034504494..7b6990b353 100644
--- a/map/feature_vec_model.cpp
+++ b/map/feature_vec_model.cpp
@@ -9,8 +9,6 @@
#include "../indexer/classif_routine.hpp"
#include "../indexer/classificator.hpp"
-#include "../coding/file_container.hpp"
-
#include "../base/logging.hpp"
#include "../std/bind.hpp"
@@ -35,11 +33,7 @@ void FeaturesFetcher::AddMap(string const & fName)
try
{
- uint32_t const logPageSize = 12;
- uint32_t const logPageCount = 12;
-
- FilesContainerR container(fName, logPageSize, logPageCount);
- m_multiIndex.Add(FeatureReaders<FileReader>(container), container.GetReader(INDEX_FILE_TAG));
+ m_multiIndex.Add(fName);
}
catch (Reader::OpenException const & e)
{
diff --git a/map/feature_vec_model.hpp b/map/feature_vec_model.hpp
index 56e3432fb5..f82e76a6aa 100644
--- a/map/feature_vec_model.hpp
+++ b/map/feature_vec_model.hpp
@@ -42,7 +42,7 @@ namespace model
typedef FileReader reader_t;
#endif
- typedef Index<reader_t, reader_t>::Type index_t;
+ typedef Index<reader_t>::Type index_t;
index_t m_multiIndex;