mn_multimap.hpp
Go to the documentation of this file.
1 
21 #ifndef __MINILIB_BASIC_MULTIMAP_H__
22 #define __MINILIB_BASIC_MULTIMAP_H__
23 
24 #include "../mn_config.hpp"
25 #include "mn_array.hpp"
26 #include "mn_vector.hpp"
27 #include "mn_pair.hpp"
28 
29 #include "../utils/mn_utils.hpp"
30 
31 namespace mn {
32  namespace container {
33 
39  template <typename TKEY, typename TVAL, class TAllocator, TComp = mn::less<TKEY> >
40  class basic_multimap : public vector< pair<TKEY, TVAL>, TAllocator > {
42  public:
43  using key_type = TKEY;
44  using value_type = TVAL;
45 
46  using key_reference = TKEY&;
47  using key_const_reference = const TKEY&;
48  using value_reference = TVAL&;
49  using value_const_reference = const TVAL&;
50 
52 
55  using pointer = typename base_type::pointer;
56  using reference = typename base_type::reference;
59  using iterator = typename base_type::iterator;
62  using size_type = typename base_type::size_type;
63 
66  using key_compare = TComp;
67 
69 
71  : base_type(allocator) {}
72 
73  explicit basic_multimap (size_type initialSize, const allocator_type& allocator = allocator_type())
74  : base_type (initialSize, allocator) {}
75 
77  const allocator_type& allocator = allocator_type())
78  : base_type(first, last, allocator) { }
79 
80  basic_multimap (const self_type& rhs, const allocator_type& allocator = allocator_type())
81  : base_type (rhs, allocator) {}
82 
84  : base_type (mn::move(v)) {}
85 
86  using base_type::size;
87  using base_type::begin;
88  using base_type::end;
89  using base_type::empty;
90  using base_type::capacity;
91  using base_type::front;
92  using base_type::cfront;
93  using base_type::back;
94  using base_type::cback;
95  using base_type::clear;
96  using base_type::erase;
97  using base_type::insert;
99  using base_type::operator[];
100  using base_type::operator= ;
101  using base_type::swap ;
102  using base_type::at;
103 
105  clear(); insert (i1, i2);
106  }
107  void erase (const self_type& k) {
108  erase (const_cast<iterator>(k), const_cast<iterator>(k));
109  }
110 
112  return mn::lower_bound (begin(), end(), k, value_key_compare());
113  }
114 
116  return mn::lower_bound (begin(), end(), k, value_key_compare());
117  }
118 
120  return mn::upper_bound (begin(), end(), k, value_key_compare());
121  }
123  return mn::upper_bound (begin(), end(), k, value_key_compare());
124  }
125 
127  const_iterator i = lower_bound (k);
128  return (i < end() && TComp()(k, i->first)) ? end() : i;
129  }
131  if (!first) first = begin();
132  if (!last) last = end();
133  for (; first != last && first->second != v; ++first) {}
134  return first;
135  }
137  iterator _ip = lower_bound (k);
138 
139  if (ip == end() || TComp()(k, _ip->first) )
140  ip = base_type::insert (ip, make_pair<TKEY, TVAL> (k, TVAL()));
141  return ip->second;
142  }
143 
144  template <typename... Args>
145  iterator emplace (Args&&... args) {
146  return insert (value_type(mn::forward<Args>(args)...));
147  }
148 
149  template <typename... Args>
150  iterator emplace_hint (const_iterator h, Args&&... args) {
151  return insert (h, value_type(mn::forward<Args>(args)...));
152  }
153 
154  template <typename... Args>
155  iterator emplace_back (Args&&... args) {
156  return insert (value_type(mn::forward<Args>(args)...));
157  }
158  };
159 
160  template <typename TKEY, typename TVAL, class TAllocator >
162 
163  }
164 }
165 
166 
167 #endif // __MINILIB_BASIC_MULTIMAP_H__
Definition: mn_initializer_list.hpp:26
A sorted associative container that may container multiple entries for each key.
Definition: mn_multimap.hpp:40
iterator begin()
Definition: mn_vector.hpp:173
typename base_type::const_reference const_reference
Definition: mn_multimap.hpp:57
iterator end()
Definition: mn_vector.hpp:174
TKEY & key_reference
Definition: mn_multimap.hpp:46
TKEY key_type
Definition: mn_multimap.hpp:43
basic_multimap(size_type initialSize, const allocator_type &allocator=allocator_type())
Definition: mn_multimap.hpp:73
const TKEY & key_const_reference
Definition: mn_multimap.hpp:47
TComp key_compare
Definition: mn_multimap.hpp:66
value_reference operator[](key_const_reference k)
Definition: mn_multimap.hpp:136
typename base_type::pointer pointer
Definition: mn_multimap.hpp:55
basic_multimap(const self_type &rhs, const allocator_type &allocator=allocator_type())
Definition: mn_multimap.hpp:80
void assign(const_iterator i1, const_iterator i2)
Definition: mn_multimap.hpp:104
iterator upper_bound(key_const_reference k)
Definition: mn_multimap.hpp:122
iterator emplace_hint(const_iterator h, Args &&... args)
Definition: mn_multimap.hpp:150
TVAL & value_reference
Definition: mn_multimap.hpp:48
iterator emplace(Args &&... args)
Definition: mn_multimap.hpp:145
const_iterator find_value(value_const_reference v, const_iterator first, const_iterator last) const
Definition: mn_multimap.hpp:130
typename base_type::difference_type difference_type
Definition: mn_multimap.hpp:58
void erase(const self_type &k)
Definition: mn_multimap.hpp:107
typename base_type::iterator iterator
Definition: mn_multimap.hpp:59
typename base_type::size_type size_type
Definition: mn_multimap.hpp:62
typename base_type::reference reference
Definition: mn_multimap.hpp:56
const_iterator find(key_const_reference k) const
Definition: mn_multimap.hpp:126
const TVAL & value_const_reference
Definition: mn_multimap.hpp:49
basic_multimap(basic_multimap &&v)
Definition: mn_multimap.hpp:83
basic_multimap(const allocator_type &allocator=allocator_type())
Definition: mn_multimap.hpp:70
const_iterator lower_bound(key_const_reference k) const
Definition: mn_multimap.hpp:111
iterator emplace_back(Args &&... args)
Definition: mn_multimap.hpp:155
typename base_type::const_iterator const_iterator
Definition: mn_multimap.hpp:60
void insert(size_type index, size_type n, const reference val)
Definition: mn_vector.hpp:228
iterator lower_bound(key_const_reference k)
Definition: mn_multimap.hpp:115
basic_multimap(const_iterator first, const_iterator last, const allocator_type &allocator=allocator_type())
Definition: mn_multimap.hpp:76
typename base_type::iterator_category iterator_category
Definition: mn_multimap.hpp:53
void clear()
Definition: mn_vector.hpp:343
TVAL value_type
Definition: mn_multimap.hpp:44
typename base_type::allocator_type allocator_type
Definition: mn_multimap.hpp:61
iterator erase(iterator it)
Definition: mn_vector.hpp:306
const_iterator upper_bound(key_const_reference k) const
Definition: mn_multimap.hpp:119
Definition: mn_vector.hpp:117
reference front()
Definition: mn_vector.hpp:183
const pointer const_iterator
Definition: mn_vector.hpp:128
T value_type
Definition: mn_vector.hpp:121
iterator begin()
Definition: mn_vector.hpp:173
const T & const_reference
Definition: mn_vector.hpp:125
iterator end()
Definition: mn_vector.hpp:174
size_type capacity()
Definition: mn_vector.hpp:179
const reference cfront()
Definition: mn_vector.hpp:184
TAllocator allocator_type
Definition: mn_vector.hpp:129
const reference cback()
Definition: mn_vector.hpp:186
reference at(size_type i)
Definition: mn_vector.hpp:188
size_type size() const
Definition: mn_vector.hpp:176
mn::size_t size_type
Definition: mn_vector.hpp:130
pointer iterator
Definition: mn_vector.hpp:127
void insert(size_type index, size_type n, const reference val)
Definition: mn_vector.hpp:228
reference back()
Definition: mn_vector.hpp:185
random_access_iterator_tag iterator_category
Definition: mn_vector.hpp:119
T * pointer
Definition: mn_vector.hpp:122
void push_back()
Definition: mn_vector.hpp:202
bool empty() const
Definition: mn_vector.hpp:177
T & reference
Definition: mn_vector.hpp:123
void clear()
Definition: mn_vector.hpp:343
mn::ptrdiff_t difference_type
Definition: mn_vector.hpp:126
iterator erase(iterator it)
Definition: mn_vector.hpp:306
Class for a dynamic array. This file is part of the Mini Thread Library (https://github....
Basic vector container This file is part of the Mini Thread Library (https://github....
Definition: mn_allocator_typetraits.hpp:25
constexpr TIter upper_bound(TIter first, TIter last, const TPred &value)
Definition: mn_algorithm.hpp:191
constexpr TIter lower_bound(TIter first, TIter last, const TPred &value)
Definition: mn_algorithm.hpp:160
void move(const T *src, const T *last, T *dest)
Definition: mn_algorithm.hpp:100
Definition: mn_pair.hpp:28
void swap(self_type &other)
Definition: mn_vector.hpp:103