move weak_ptr list of tile_data objects to a map for faster lookups

This commit is contained in:
Konstantin Käfer
2014-05-13 12:01:29 +02:00
parent 654520ea34
commit d8fa9aa322
3 changed files with 26 additions and 10 deletions

View File

@@ -12,6 +12,7 @@
#include <vector>
#include <string>
#include <map>
#include <set>
namespace llmr {
@@ -69,7 +70,7 @@ private:
const int32_t max_zoom;
std::forward_list<Tile> tiles;
std::forward_list<std::weak_ptr<TileData>> tile_data;
std::map<Tile::ID, std::weak_ptr<TileData>> tile_data;
};
}

View File

@@ -11,6 +11,23 @@ template<typename T, typename ...Args>
return ::std::unique_ptr<T>(new T(::std::forward<Args>(args)...));
}
template <typename Container, typename ForwardIterator, typename Predicate>
void erase_if(Container &container, ForwardIterator it, const ForwardIterator end, Predicate pred) {
while (it != end) {
if (pred(*it)) {
container.erase(it++);
} else {
++it;
}
}
}
template <typename Container, typename Predicate>
void erase_if(Container &container, Predicate pred) {
erase_if(container, container.begin(), container.end(), pred);
}
}
#endif