aboutsummaryrefslogtreecommitdiff
path: root/libbutl/prefix-map.txx
diff options
context:
space:
mode:
Diffstat (limited to 'libbutl/prefix-map.txx')
-rw-r--r--libbutl/prefix-map.txx126
1 files changed, 125 insertions, 1 deletions
diff --git a/libbutl/prefix-map.txx b/libbutl/prefix-map.txx
index e9a99c9..80664bf 100644
--- a/libbutl/prefix-map.txx
+++ b/libbutl/prefix-map.txx
@@ -1,7 +1,7 @@
// file : libbutl/prefix-map.txx -*- C++ -*-
// license : MIT; see accompanying LICENSE file
-LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason.
+namespace butl
{
template <typename M>
auto prefix_map_common<M>::
@@ -127,4 +127,128 @@ LIBBUTL_MODEXPORT namespace butl //@@ MOD Clang needs this for some reason.
return i;
#endif
}
+
+ template <typename M>
+ template <typename P>
+ auto prefix_map_common<M>::
+ find_sup_if (const key_type& k, P pred) -> iterator
+ {
+#if 0
+ const auto& c (this->key_comp ());
+
+ for (auto i (this->upper_bound (k)), b (this->begin ()); i != b; )
+ {
+ --i;
+ if (c.prefix (i->first, k) && pred (*i))
+ return i;
+ }
+
+ return this->end ();
+#else
+ auto i (this->find (k)), e (this->end ());
+
+ if (i == e || !pred (*i))
+ {
+ const auto& c (this->key_comp ());
+
+ for (key_type p (k); c.prefix (p); )
+ {
+ i = this->find (p);
+ if (i != e && pred (*i))
+ break;
+ }
+ }
+
+ return i;
+#endif
+ }
+
+ template <typename M>
+ template <typename P>
+ auto prefix_map_common<M>::
+ find_sup_if (const key_type& k, P pred) const -> const_iterator
+ {
+#if 0
+ const auto& c (this->key_comp ());
+
+ for (auto i (this->upper_bound (k)), b (this->begin ()); i != b; )
+ {
+ --i;
+ if (c.prefix (i->first, k) && pred (*i))
+ return i;
+ }
+
+ return this->end ();
+#else
+ auto i (this->find (k)), e (this->end ());
+
+ if (i == e || !pred (*i))
+ {
+ const auto& c (this->key_comp ());
+
+ for (key_type p (k); c.prefix (p); )
+ {
+ i = this->find (p);
+ if (i != e && pred (*i))
+ break;
+ }
+ }
+
+ return i;
+#endif
+ }
+
+ template <typename M>
+ auto prefix_multimap_common<M>::
+ sup_range (const key_type& k) -> std::pair<iterator, iterator>
+ {
+#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 <typename M>
+ auto prefix_multimap_common<M>::
+ sup_range (const key_type& k) const -> std::pair<const_iterator, const_iterator>
+ {
+#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
+ }
}