[base] Updated IsSortedAndUnique function.

Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
Viktor Govako
2025-07-03 20:01:54 -03:00
committed by Konstantin Pastbin
parent b7b87f5530
commit 7b4862b442
7 changed files with 12 additions and 12 deletions

View File

@@ -172,7 +172,7 @@ void BuildRoadAltitudes(std::string const & mwmPath, AltitudeGetter & altitudeGe
} }
{ {
// Altitude offsets serialization. // Altitude offsets serialization.
CHECK(base::IsSortedAndUnique(offsets.begin(), offsets.end()), ()); CHECK(base::IsSortedAndUnique(offsets), ());
succinct::elias_fano::elias_fano_builder builder(offsets.back(), offsets.size()); succinct::elias_fano::elias_fano_builder builder(offsets.back(), offsets.size());
for (uint32_t offset : offsets) for (uint32_t offset : offsets)

View File

@@ -89,7 +89,7 @@ public:
m_version = Version::V0; m_version = Version::V0;
} }
ASSERT(std::is_sorted(std::cbegin(m_data), std::cend(m_data)), ()); CHECK(base::IsSortedAndUnique(m_data), ());
} }
private: private:

View File

@@ -304,6 +304,12 @@ bool IsSortedAndUnique(Iter beg, Iter end, Compare comp)
return true; return true;
} }
template <typename ContT>
bool IsSortedAndUnique(ContT const & cont)
{
return IsSortedAndUnique(cont.begin(), cont.end(), std::less<>());
}
template <typename Iter, typename Compare> template <typename Iter, typename Compare>
Iter RemoveIfKeepValid(Iter beg, Iter end, Compare comp) Iter RemoveIfKeepValid(Iter beg, Iter end, Compare comp)
{ {
@@ -328,12 +334,6 @@ Iter RemoveIfKeepValid(Iter beg, Iter end, Compare comp)
return end; return end;
} }
template <typename Iter>
bool IsSortedAndUnique(Iter beg, Iter end)
{
return IsSortedAndUnique(beg, end, std::less<typename std::iterator_traits<Iter>::value_type>());
}
struct DeleteFunctor struct DeleteFunctor
{ {
template <typename T> template <typename T>

View File

@@ -50,7 +50,7 @@ std::string_view GetUnitsGroupingSeparator(Locale const & locale)
bool IsUnitsOrderValid(std::initializer_list<Duration::Units> units) bool IsUnitsOrderValid(std::initializer_list<Duration::Units> units)
{ {
return base::IsSortedAndUnique(units.begin(), units.end()); return base::IsSortedAndUnique(units);
} }
} // namespace } // namespace

View File

@@ -73,7 +73,7 @@ std::vector<uint32_t> const & FeaturesLayerMatcher::GetPlaceAddrFeatures(uint32_
res.first.push_back(fid); res.first.push_back(fid);
}); });
ASSERT(base::IsSortedAndUnique(res.first.begin(), res.first.end()), ()); ASSERT(base::IsSortedAndUnique(res.first), ());
} }
return res.first; return res.first;
} }

View File

@@ -833,7 +833,7 @@ int HouseDetector::LoadStreets(vector<FeatureID> const & ids)
{ {
// LOG(LDEBUG, ("IDs = ", ids)); // LOG(LDEBUG, ("IDs = ", ids));
ASSERT(base::IsSortedAndUnique(ids.begin(), ids.end()), ()); ASSERT(base::IsSortedAndUnique(ids), ());
// Check if the cache is obsolete and need to be cleared. // Check if the cache is obsolete and need to be cleared.
if (!m_id2st.empty()) if (!m_id2st.empty())

View File

@@ -58,7 +58,7 @@ public:
vector<Id> StrictQuery(string const & query, string const & lang) const vector<Id> StrictQuery(string const & query, string const & lang) const
{ {
auto prev = m_index.GetAllIds(); auto prev = m_index.GetAllIds();
TEST(base::IsSortedAndUnique(prev.cbegin(), prev.cend()), ()); TEST(base::IsSortedAndUnique(prev), ());
ForEachNormalizedToken(query, [&](strings::UniString const & token) ForEachNormalizedToken(query, [&](strings::UniString const & token)
{ {