From bf1e5b6b8b73fed4ab1bfb40a1f362c255fe7029 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 5 Nov 2021 12:39:26 +0200 Subject: Improve prefix multiple support --- libbutl/prefix-map.txx | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'libbutl/prefix-map.txx') diff --git a/libbutl/prefix-map.txx b/libbutl/prefix-map.txx index 502119a..80664bf 100644 --- a/libbutl/prefix-map.txx +++ b/libbutl/prefix-map.txx @@ -197,4 +197,58 @@ namespace butl return i; #endif } + + template + auto prefix_multimap_common:: + sup_range (const key_type& k) -> std::pair + { +#if 0 + // TODO (see above). +#else + // First look for the exact match before making any copies. + // + auto r (this->equal_range (k)); + + if (r.first == r.second) + { + const auto& c (this->key_comp ()); + + for (key_type p (k); c.prefix (p); ) + { + r = this->equal_range (p); + if (r.first != r.second) + break; + } + } + + return r; +#endif + } + + template + auto prefix_multimap_common:: + sup_range (const key_type& k) const -> std::pair + { +#if 0 + // TODO (see above). +#else + // First look for the exact match before making any copies. + // + auto r (this->equal_range (k)); + + if (r.first == r.second) + { + const auto& c (this->key_comp ()); + + for (key_type p (k); c.prefix (p); ) + { + r = this->equal_range (p); + if (r.first != r.second) + break; + } + } + + return r; +#endif + } } -- cgit v1.1