diff --git a/cmake/core-files.txt b/cmake/core-files.txt index 7c52e08cc..9e83ceb66 100644 --- a/cmake/core-files.txt +++ b/cmake/core-files.txt @@ -726,6 +726,7 @@ src/mbgl/util/geo.cpp src/mbgl/util/geojson_impl.cpp src/mbgl/util/grid_index.cpp src/mbgl/util/grid_index.hpp +src/mbgl/util/hash.hpp src/mbgl/util/http_header.cpp src/mbgl/util/http_header.hpp src/mbgl/util/http_timeout.cpp diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp index 1129bd0b2..ba14655ca 100644 --- a/src/mbgl/geometry/line_atlas.cpp +++ b/src/mbgl/geometry/line_atlas.cpp @@ -2,8 +2,7 @@ #include #include #include - -#include +#include #include #include @@ -22,7 +21,7 @@ LinePatternPos LineAtlas::getDashPosition(const std::vector& dasharray, size_t key = patternCap == LinePatternCap::Round ? std::numeric_limits::min() : std::numeric_limits::max(); for (const float part : dasharray) { - boost::hash_combine(key, part); + util::hash_combine(key, part); } // Note: We're not handling hash collisions here. diff --git a/src/mbgl/layout/merge_lines.cpp b/src/mbgl/layout/merge_lines.cpp index 2a3afa42b..616a8a3ff 100644 --- a/src/mbgl/layout/merge_lines.cpp +++ b/src/mbgl/layout/merge_lines.cpp @@ -1,7 +1,6 @@ #include #include - -#include +#include namespace mbgl { namespace util { @@ -43,10 +42,7 @@ size_t mergeFromLeft(std::vector& features, } size_t getKey(const std::u16string& text, const GeometryCoordinate& coord) { - auto hash = std::hash()(text); - boost::hash_combine(hash, coord.x); - boost::hash_combine(hash, coord.y); - return hash; + return util::hash(text, coord.x, coord.y); } void mergeLines(std::vector& features) { diff --git a/src/mbgl/text/glyph.hpp b/src/mbgl/text/glyph.hpp index 55cd50fd9..034784dc2 100644 --- a/src/mbgl/text/glyph.hpp +++ b/src/mbgl/text/glyph.hpp @@ -115,7 +115,7 @@ MBGL_CONSTEXPR WritingModeType operator~(WritingModeType value) { return WritingModeType(~mbgl::underlying_type(value)); } -using GlyphDependencies = std::map; -using GlyphRangeDependencies = std::map; +using GlyphDependencies = std::map; +using GlyphRangeDependencies = std::map>; } // end namespace mbgl diff --git a/src/mbgl/text/glyph_manager.cpp b/src/mbgl/text/glyph_manager.cpp index c4a7a2de6..b947ef72c 100644 --- a/src/mbgl/text/glyph_manager.cpp +++ b/src/mbgl/text/glyph_manager.cpp @@ -31,7 +31,7 @@ void GlyphManager::getGlyphs(GlyphRequestor& requestor, GlyphDependencies glyphD Entry& entry = entries[fontStack]; const GlyphIDs& glyphIDs = dependency.second; - GlyphRangeSet ranges; + std::unordered_set ranges; for (const auto& glyphID : glyphIDs) { if (localGlyphRasterizer->canRasterizeGlyph(fontStack, glyphID)) { if (entry.glyphs.find(glyphID) == entry.glyphs.end()) { diff --git a/src/mbgl/text/glyph_range.hpp b/src/mbgl/text/glyph_range.hpp index 74afb73df..35a1f74b9 100644 --- a/src/mbgl/text/glyph_range.hpp +++ b/src/mbgl/text/glyph_range.hpp @@ -3,21 +3,24 @@ #include #include #include -#include +#include namespace mbgl { using GlyphRange = std::pair; -struct GlyphRangeHash { - std::size_t operator()(const GlyphRange& glyphRange) const { - return boost::hash_value(glyphRange); - } -}; - -using GlyphRangeSet = std::unordered_set; - constexpr uint32_t GLYPHS_PER_GLYPH_RANGE = 256; constexpr uint32_t GLYPH_RANGES_PER_FONT_STACK = 256; } // end namespace mbgl + +namespace std { + +template <> +struct hash { + std::size_t operator()(const mbgl::GlyphRange& range) const { + return mbgl::util::hash(range.first, range.second); + } +}; + +} // namespace std diff --git a/src/mbgl/tile/tile_id_hash.cpp b/src/mbgl/tile/tile_id_hash.cpp index 4a1f18581..d4a7d8807 100644 --- a/src/mbgl/tile/tile_id_hash.cpp +++ b/src/mbgl/tile/tile_id_hash.cpp @@ -1,28 +1,27 @@ #include - -#include +#include namespace std { size_t hash::operator()(const mbgl::CanonicalTileID& id) const { std::size_t seed = 0; - boost::hash_combine(seed, id.x); - boost::hash_combine(seed, id.y); - boost::hash_combine(seed, id.z); + mbgl::util::hash_combine(seed, id.x); + mbgl::util::hash_combine(seed, id.y); + mbgl::util::hash_combine(seed, id.z); return seed; } size_t hash::operator()(const mbgl::UnwrappedTileID& id) const { std::size_t seed = 0; - boost::hash_combine(seed, std::hash{}(id.canonical)); - boost::hash_combine(seed, id.wrap); + mbgl::util::hash_combine(seed, std::hash{}(id.canonical)); + mbgl::util::hash_combine(seed, id.wrap); return seed; } size_t hash::operator()(const mbgl::OverscaledTileID& id) const { std::size_t seed = 0; - boost::hash_combine(seed, std::hash{}(id.canonical)); - boost::hash_combine(seed, id.overscaledZ); + mbgl::util::hash_combine(seed, std::hash{}(id.canonical)); + mbgl::util::hash_combine(seed, id.overscaledZ); return seed; } diff --git a/src/mbgl/util/font_stack.cpp b/src/mbgl/util/font_stack.cpp index fb1b716fb..4093a2179 100644 --- a/src/mbgl/util/font_stack.cpp +++ b/src/mbgl/util/font_stack.cpp @@ -1,8 +1,8 @@ #include #include #include +#include -#include #include namespace mbgl { @@ -14,7 +14,11 @@ std::string fontStackToString(const FontStack& fontStack) { } FontStackHash FontStackHasher::operator()(const FontStack& fontStack) const { - return boost::hash_range(fontStack.begin(), fontStack.end()); + std::size_t seed = 0; + for (const auto& font : fontStack) { + util::hash_combine(seed, font); + } + return seed; } std::set fontStacks(const std::vector>& layers) { diff --git a/src/mbgl/util/hash.hpp b/src/mbgl/util/hash.hpp new file mode 100644 index 000000000..987a8bd8d --- /dev/null +++ b/src/mbgl/util/hash.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include + +#include + +namespace mbgl { +namespace util { + +template +inline void hash_combine(std::size_t& seed, const T& v) { + seed ^= std::hash()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); +} + +template +inline std::size_t hash(Args&&... args) { + std::size_t seed = 0; + ignore({ (hash_combine(seed, args), 0)... }); + return seed; +} + +} // namespace util +} // namespace mbgl