1 #ifndef cetlib_map_vector_h 2 #define cetlib_map_vector_h 10 #include "cetlib_except/exception.h" 19 bool operator==(map_vector_key
const&, map_vector_key
const&) noexcept;
20 bool operator!=(map_vector_key
const&, map_vector_key const&) noexcept;
21 bool operator<(map_vector_key const&, map_vector_key const&) noexcept;
22 bool operator>(map_vector_key const&, map_vector_key const&) noexcept;
23 bool operator<=(map_vector_key const&, map_vector_key const&) noexcept;
24 bool operator>=(map_vector_key const&, map_vector_key const&) noexcept;
26 std::ostream& operator<<(
std::ostream&, map_vector_key const&);
28 template <class Value>
38 explicit map_vector_key(
int key);
39 constexpr
explicit map_vector_key(
unsigned const key) noexcept : key_{key} {}
40 constexpr
explicit map_vector_key(
unsigned long key) noexcept;
43 constexpr
unsigned long 48 constexpr
unsigned long 53 void ensure_valid()
const;
64 <<
"Negative key " << key <<
" not valid for map_vector_key.";
75 if (
key_ == static_cast<unsigned long>(-1)) {
77 <<
"Attempt to use an invalid cet::map_vector_key.";
83 template <
class Value>
101 using pointer =
typename allocator_type::pointer;
109 template <
class InIter>
131 return v_.max_size();
136 return v_.capacity();
142 return v_.get_allocator();
154 return v_.empty() ? 0 : 1 + v_.back().first.asInt();
174 return getOrThrow(key);
262 std::pair<iterator, bool> insert(
value_type const&
x);
268 template <
class InIter>
269 void insert(InIter
b, InIter
e);
276 template <
class InIter>
277 void append(InIter b, InIter e);
289 bool class_invariant()
const;
305 return k1.asInt() == k2.asInt();
311 return k1.asInt() != k2.asInt();
317 return k1.asInt() < k2.asInt();
323 return k1.asInt() > k2.asInt();
329 return k1.asInt() <= k2.asInt();
335 return k1.asInt() >= k2.asInt();
344 return os << key.
asInt();
353 template <
class Value>
358 throw cet::exception(
"map_vector::front") <<
"container is empty!\n";
362 template <
class Value>
367 throw cet::exception(
"map_vector::back") <<
"container is empty!\n";
371 template <
class Value>
376 return std::binary_search(v_.begin(), v_.end(), v, lt);
379 template <
class Value>
384 auto const begin = v_.begin(),
end = v_.end();
385 auto it = std::lower_bound(
begin,
end, v, lt);
386 if (it !=
end && it->first != key)
391 template <
class Value>
396 auto const begin = v_.cbegin(),
end = v_.cend();
397 auto it = std::lower_bound(
begin,
end, v, lt);
398 if (it !=
end && it->first != key)
403 template <
class Value>
415 template <
class Value>
420 return it == v_.end() ?
nullptr : &it->second;
423 template <
class Value>
428 return it == v_.cend() ?
nullptr : &it->second;
431 template <
class Value>
435 auto*
p = getOrNull(key);
443 template <
class Value>
447 auto const*
p = getOrNull(key);
455 template <
class Value>
459 auto const begin = v_.begin(),
end = v_.end();
460 auto it = std::lower_bound(
begin,
end, v, lt);
461 if (it ==
end || it->first != key)
469 template <
class Value>
473 v.first.ensure_valid();
474 auto const begin = v_.begin(),
end = v_.end();
475 auto it = std::lower_bound(
begin,
end, v, lt);
476 if (it ==
end || it->first != v.first)
477 return std::make_pair(v_.insert(it, v),
true);
478 return std::make_pair(it,
false);
481 template <
class Value>
482 template <
class InIter>
486 std::for_each(b, e, [](
auto const& pr) {
return pr.first.ensure_valid(); });
489 std::merge(v_.cbegin(), v_.cend(),
b,
e, back_inserter(result), lt);
490 auto new_end = std::unique(result.begin(), result.end(), eq);
491 result.erase(new_end, result.end());
492 result.shrink_to_fit();
496 template <
class Value>
497 template <
class InIter>
501 std::for_each(b, e, [](
auto const& pr) {
return pr.first.ensure_valid(); });
502 v_.insert(v_.cend(),
b,
e);
503 assert(class_invariant());
509 template <
class Value>
513 return std::is_sorted(v_.begin(), v_.end(), lt);
518 template <
class Value>
522 return v1.first < v2.first;
525 template <
class Value>
529 return v1.first == v2.first;
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
reverse_iterator rbegin() noexcept
bool empty() const noexcept
constexpr map_vector_key(unsigned const key) noexcept
allocator_type get_allocator() const noexcept
constexpr unsigned long asUint() const noexcept
constexpr bool operator>=(exempt_ptr< E >, exempt_ptr< E >)
size_type capacity() const noexcept
const_reverse_iterator rend() const noexcept
std::ostream & operator<<(std::ostream &, map_vector_key const &)
const_iterator cend() const noexcept
std::vector< value_type > impl_type
void swap(map_vector< mapped_type > &other)
std::pair< key_type, mapped_type > value_type
bool has(key_type key) const
iterator find(key_type key)
std::pair< iterator, bool > insert(value_type const &x)
map_vector(InIter const b, InIter const e)
const_iterator end() const noexcept
typename allocator_type::reference reference
constexpr map_vector_key() noexcept
typename impl_type::const_reverse_iterator const_reverse_iterator
typename impl_type::allocator_type allocator_type
typename allocator_type::const_reference const_reference
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
typename impl_type::reverse_iterator reverse_iterator
static bool lt(value_type const &, value_type const &) noexcept
const_iterator begin() const noexcept
typename impl_type::size_type size_type
size_type max_size() const noexcept
mapped_type & operator[](key_type key)
constexpr bool operator<(exempt_ptr< E >, exempt_ptr< E >)
typename impl_type::difference_type difference_type
void append(InIter b, InIter e)
typename allocator_type::const_pointer const_pointer
typename allocator_type::pointer pointer
constexpr bool operator<=(exempt_ptr< E >, exempt_ptr< E >)
bool class_invariant() const
constexpr bool operator==(exempt_ptr< E >, exempt_ptr< E >) noexcept
void reserve(size_type const n)
value_type const & front() const
constexpr bool operator>(exempt_ptr< E >, exempt_ptr< E >)
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
reverse_iterator rend() noexcept
mapped_type const & operator[](key_type key) const
constexpr bool operator!=(exempt_ptr< E >, exempt_ptr< E >) noexcept
typename impl_type::iterator iterator
iterator begin() noexcept
value_type const & back() const
const_reverse_iterator crbegin() const
const_reverse_iterator rbegin() const noexcept
constexpr unsigned long asInt() const noexcept
static bool eq(value_type const &, value_type const &) noexcept
void ensure_valid() const
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
mapped_type const & at(key_type key) const
const_iterator findOrThrow(key_type key) const
mapped_type & getOrThrow(key_type key)
static short Class_Version()
size_type size() const noexcept
const_reverse_iterator crend() const noexcept
typename impl_type::const_iterator const_iterator
const_iterator cbegin() const noexcept
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
mapped_type * getOrNull(key_type key)