diff --git a/indexer/displacement_manager.hpp b/indexer/displacement_manager.hpp index ab3af38ad1..0b062dda03 100644 --- a/indexer/displacement_manager.hpp +++ b/indexer/displacement_manager.hpp @@ -82,7 +82,7 @@ public: // Pass feature to the index otherwise. for (auto const & cell : cells) - m_sorter.Add(CellFeatureBucketTuple(CellFeaturePair(cell, index), bucket)); + m_sorter(CellFeatureBucketTuple(CellFeaturePair(cell, index), bucket)); } /// Check features intersection and supress drawing of intersected features. @@ -211,7 +211,7 @@ private: void AddNodeToSorter(DisplaceableNode const & node, uint32_t scale) { for (auto const & cell : node.m_cells) - m_sorter.Add(CellFeatureBucketTuple(CellFeaturePair(cell, node.m_index), scale)); + m_sorter(CellFeatureBucketTuple(CellFeaturePair(cell, node.m_index), scale)); } Sorter & m_sorter; diff --git a/indexer/scale_index_builder.hpp b/indexer/scale_index_builder.hpp index 0f0d397674..ca3794c3c1 100644 --- a/indexer/scale_index_builder.hpp +++ b/indexer/scale_index_builder.hpp @@ -122,33 +122,30 @@ private: template void IndexScales(feature::DataHeader const & header, FeaturesVector const & features, - Writer & writer, std::string const & tmpFilePrefix) + Writer & writer, std::string const &) { // TODO: Make scale bucketing dynamic. uint32_t const bucketsCount = header.GetLastScale() + 1; - std::string const cellsToFeatureAllBucketsFile = - tmpFilePrefix + CELL2FEATURE_SORTED_EXT + ".allbuckets"; - SCOPE_GUARD(cellsToFeatureAllBucketsFileGuard, - bind(&FileWriter::DeleteFileX, cellsToFeatureAllBucketsFile)); + std::vector cellsToFeaturesAllBuckets; { - FileWriter cellsToFeaturesAllBucketsWriter(cellsToFeatureAllBucketsFile); + auto const PushCFT = [&cellsToFeaturesAllBuckets](CellFeatureBucketTuple const & v) + { + cellsToFeaturesAllBuckets.push_back(v); + }; + using TDisplacementManager = DisplacementManager; - using TSorter = FileSorter>; - using TDisplacementManager = DisplacementManager; - WriterFunctor out(cellsToFeaturesAllBucketsWriter); - TSorter sorter(1024 * 1024 /* bufferBytes */, tmpFilePrefix + CELL2FEATURE_TMP_EXT, out); // Heuristically rearrange and filter single-point features to simplify // the runtime decision of whether we should draw a feature // or sacrifice it for the sake of more important ones. - TDisplacementManager manager(sorter); + TDisplacementManager manager(PushCFT); std::vector featuresInBucket(bucketsCount); std::vector cellsInBucket(bucketsCount); features.ForEach( FeatureCoverer(header, manager, featuresInBucket, cellsInBucket)); manager.Displace(); - sorter.SortAndFinish(); + std::sort(cellsToFeaturesAllBuckets.begin(), cellsToFeaturesAllBuckets.end()); for (uint32_t bucket = 0; bucket < bucketsCount; ++bucket) { @@ -161,35 +158,24 @@ void IndexScales(feature::DataHeader const & header, FeaturesVector const & feat } } - FileReader reader(cellsToFeatureAllBucketsFile); - DDVector cellsToFeaturesAllBuckets(reader); - VarSerialVectorWriter recordWriter(writer, bucketsCount); auto it = cellsToFeaturesAllBuckets.begin(); for (uint32_t bucket = 0; bucket < bucketsCount; ++bucket) { - std::string const cellsToFeatureFile = tmpFilePrefix + CELL2FEATURE_SORTED_EXT; - SCOPE_GUARD(cellsToFeatureFileGuard, bind(&FileWriter::DeleteFileX, cellsToFeatureFile)); + /// @todo Can avoid additional vector here with the smart iterator adapter. + std::vector cellsToFeatures; + while (it < cellsToFeaturesAllBuckets.end() && it->GetBucket() == bucket) { - FileWriter cellsToFeaturesWriter(cellsToFeatureFile); - WriterFunctor out(cellsToFeaturesWriter); - while (it < cellsToFeaturesAllBuckets.end() && it->GetBucket() == bucket) - { - out(it->GetCellFeaturePair()); - ++it; - } + cellsToFeatures.push_back(it->GetCellFeaturePair()); + ++it; } - { - FileReader reader(cellsToFeatureFile); - DDVector cellsToFeatures( - reader); - SubWriter subWriter(writer); - LOG(LINFO, ("Building interval index for bucket:", bucket)); - BuildIntervalIndex(cellsToFeatures.begin(), cellsToFeatures.end(), subWriter, - RectId::DEPTH_LEVELS * 2 + 1); - } + SubWriter subWriter(writer); + LOG(LINFO, ("Building interval index for bucket:", bucket)); + BuildIntervalIndex(cellsToFeatures.begin(), cellsToFeatures.end(), subWriter, + RectId::DEPTH_LEVELS * 2 + 1); + recordWriter.FinishRecord(); }