| 1 | /* |
| 2 | * %injeqt copyright begin% |
| 3 | * Copyright 2014 Rafał Malinowski ([email protected]) |
| 4 | * %injeqt copyright end% |
| 5 | * |
| 6 | * type library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * type library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #pragma once |
| 22 | |
| 23 | #include <injeqt/injeqt.h>cxx . . $ `<file>/include/injeqt/injeqt.h`/ |
| 24 | |
| 25 | #include <algorithm> |
| 26 | #include <functional> |
| 27 | #include <vector> |
| 28 | |
| 29 | namespace injeqtcxx . . $ injeqt/ { namespace internalcxx . . $ injeqt/internal/ { |
| 30 | |
| 31 | /** |
| 32 | * @addtogroup Misc |
| 33 | * @{ |
| 34 | */ |
| 35 | |
| 36 | /** |
| 37 | * @class sorted_unique_vector |
| 38 | * @short Vector that stored only unique values thata are always sorted. |
| 39 | * @tparam T type of data |
| 40 | * @tparam LessThanComparator comparator used for sorting |
| 41 | * @tparam EqualityComparator comparator used for uniqueness testing |
| 42 | */ |
| 43 | template<typename K, typename V, K (*KeyExtractor)(const V &)> |
| 44 | class sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector# |
| 45 | { |
| 46 | |
| 47 | public: |
| 48 | using typecxx . . $ injeqt/internal/sorted_unique_vector#type# = sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#<K, V, KeyExtractor>; |
| 49 | using value_typecxx . . $ injeqt/internal/sorted_unique_vector#value_type# = V; |
| 50 | using key_typecxx . . $ injeqt/internal/sorted_unique_vector#key_type# = K; |
| 51 | using storage_typecxx . . $ injeqt/internal/sorted_unique_vector#storage_type# = stdcxx . . $ std/::vectorcxx . . $ std/vector#<value_typecxx . . $ injeqt/internal/sorted_unique_vector#value_type#>; |
| 52 | using const_iteratorcxx . . $ injeqt/internal/sorted_unique_vector#const_iterator# = typename storage_typecxx . . $ injeqt/internal/sorted_unique_vector#storage_type#::const_iterator; |
| 53 | using size_typecxx . . $ injeqt/internal/sorted_unique_vector#size_type# = typename storage_typecxx . . $ injeqt/internal/sorted_unique_vector#storage_type#::size_type; |
| 54 | |
| 55 | private: |
| 56 | static bool compare_keyscxx . . $ injeqt/internal/sorted_unique_vector#compare_keys(e33c049d02097613).(const value_typecxx . . $ injeqt/internal/sorted_unique_vector#value_type# &v1, const value_typecxx . . $ injeqt/internal/sorted_unique_vector#value_type# &v2) |
| 57 | { |
| 58 | auto k1 = KeyExtractor(v1); |
| 59 | auto k2 = KeyExtractor(v2); |
| 60 | return k1 <cxx . . $ injeqt/internal/`operator<`(a47c5f57c455a7c1). k2; |
| 61 | } |
| 62 | |
| 63 | static bool compare_with_keycxx . . $ injeqt/internal/sorted_unique_vector#compare_with_key(dd05d8b9bf604774).(const value_typecxx . . $ injeqt/internal/sorted_unique_vector#value_type# &v, const key_typecxx . . $ injeqt/internal/sorted_unique_vector#key_type# &k) |
| 64 | { |
| 65 | auto vk = KeyExtractor(v); |
| 66 | return vk <cxx . . $ injeqt/v1/`operator<`(24fd26303071bddf). k; |
| 67 | } |
| 68 | |
| 69 | static bool keys_equalcxx . . $ injeqt/internal/sorted_unique_vector#keys_equal(e33c049d02097613).(const value_typecxx . . $ injeqt/internal/sorted_unique_vector#value_type# &v1, const value_typecxx . . $ injeqt/internal/sorted_unique_vector#value_type# &v2) |
| 70 | { |
| 71 | auto k1 = KeyExtractor(v1); |
| 72 | auto k2 = KeyExtractor(v2); |
| 73 | return k1 ==cxx . . $ injeqt/internal/`operator==`(a47c5f57c455a7c1). k2; |
| 74 | } |
| 75 | |
| 76 | public: |
| 77 | /** |
| 78 | * @short Create empty sorted_unique_vector. |
| 79 | */ |
| 80 | sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#`sorted_unique_vector<K, V, KeyExtractor>`(49f6e7a06ebc5aa8).() {} |
| 81 | |
| 82 | /** |
| 83 | * @short Create sorted_unique_vector from given vector. |
| 84 | * @param storage vector to get data from |
| 85 | * |
| 86 | * Copies content of storage, sorts it and removes duplicates. |
| 87 | */ |
| 88 | explicit sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#`sorted_unique_vector<K, V, KeyExtractor>`(26e8deb829554aa).(storage_typecxx . . $ injeqt/internal/sorted_unique_vector#storage_type# storage) : |
| 89 | _contentcxx . . $ injeqt/internal/sorted_unique_vector#_content.{stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(storage)} |
| 90 | { |
| 91 | stdcxx . . $ std/::stable_sortcxx . . $ std/stable_sort(249673c20e2b8d5).(stdcxx . . $ std/::begincxx . . $ std/begin(309ad712043406cf).(_contentcxx . . $ injeqt/internal/sorted_unique_vector#_content.), stdcxx . . $ std/::endcxx . . $ std/end(898c3e9f99adb426).(_contentcxx . . $ injeqt/internal/sorted_unique_vector#_content.), compare_keyscxx . . $ injeqt/internal/sorted_unique_vector#compare_keys(e33c049d02097613).); |
| 92 | ensure_uniquecxx . . $ injeqt/internal/sorted_unique_vector#ensure_unique(adcf2188fbe2a592).(_contentcxx . . $ injeqt/internal/sorted_unique_vector#_content.); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * @short Create sorted_unique_vector from given initialization list. |
| 97 | * @param values vector to get data from |
| 98 | * |
| 99 | * Copies content of storage, sorts it and removes duplicates. |
| 100 | */ |
| 101 | explicit sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#`sorted_unique_vector<K, V, KeyExtractor>`(27fd641105185d40).(stdcxx . . $ std/::initializer_listcxx . . $ std/initializer_list#<value_typecxx . . $ injeqt/internal/sorted_unique_vector#value_type#> values) : |
| 102 | _contentcxx . . $ injeqt/internal/sorted_unique_vector#_content.{stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(values)} |
| 103 | { |
| 104 | stdcxx . . $ std/::stable_sortcxx . . $ std/stable_sort(249673c20e2b8d5).(stdcxx . . $ std/::begincxx . . $ std/begin(a139f8bc8514c5ac).(_contentcxx . . $ injeqt/internal/sorted_unique_vector#_content.), stdcxx . . $ std/::endcxx . . $ std/end(75b65c691aba1eff).(_contentcxx . . $ injeqt/internal/sorted_unique_vector#_content.), compare_keyscxx . . $ injeqt/internal/sorted_unique_vector#compare_keys(e33c049d02097613).); |
| 105 | ensure_uniquecxx . . $ injeqt/internal/sorted_unique_vector#ensure_unique(adcf2188fbe2a592).(_contentcxx . . $ injeqt/internal/sorted_unique_vector#_content.); |
| 106 | } |
| 107 | |
| 108 | const_iteratorcxx . . $ injeqt/internal/sorted_unique_vector#const_iterator# begincxx . . $ injeqt/internal/sorted_unique_vector#begin(10ded2c74433ed1).() const |
| 109 | { |
| 110 | return stdcxx . . $ std/::begincxx . . $ std/begin(8c94f1ffb8cd32fc).(_contentcxx . . $ injeqt/internal/sorted_unique_vector#_content.); |
| 111 | } |
| 112 | |
| 113 | const_iteratorcxx . . $ injeqt/internal/sorted_unique_vector#const_iterator# endcxx . . $ injeqt/internal/sorted_unique_vector#end(10ded2c74433ed1).() const |
| 114 | { |
| 115 | return stdcxx . . $ std/::endcxx . . $ std/end(898c3e9f99adb426).(_contentcxx . . $ injeqt/internal/sorted_unique_vector#_content.); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * @short Add new item to sorted vector. |
| 120 | * @param item new item |
| 121 | * |
| 122 | * Item is added at proper place so vector remains sorted. Item will not be |
| 123 | * added if another one that compares equal (using EqualityComparator) |
| 124 | * already exists. |
| 125 | */ |
| 126 | void addcxx . . $ injeqt/internal/sorted_unique_vector#add(69eed69a60cddb2f).(value_typecxx . . $ injeqt/internal/sorted_unique_vector#value_type# item) |
| 127 | { |
| 128 | if (_contentcxx . . $ injeqt/internal/sorted_unique_vector#_content..emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).()) |
| 129 | { |
| 130 | _contentcxx . . $ injeqt/internal/sorted_unique_vector#_content..emplace_backcxx . . $ std/vector#emplace_back(b3d147e3bb711c35).(stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(item)); |
| 131 | return; |
| 132 | } |
| 133 | |
| 134 | auto upperBound = stdcxx . . $ std/::upper_boundcxx . . $ std/upper_bound(16e024635f5f5018).(stdcxx . . $ std/::begincxx . . $ std/begin(309ad712043406cf).(_contentcxx . . $ injeqt/internal/sorted_unique_vector#_content.), stdcxx . . $ std/::endcxx . . $ std/end(c459d8867450f8b2).(_contentcxx . . $ injeqt/internal/sorted_unique_vector#_content.), item, compare_keyscxx . . $ injeqt/internal/sorted_unique_vector#compare_keys(e33c049d02097613).); |
| 135 | if (upperBound ==cxx . . $ injeqt/v1/`operator==`(24fd26303071bddf). stdcxx . . $ std/::begincxx . . $ std/begin(75b65c691aba1eff).(_contentcxx . . $ injeqt/internal/sorted_unique_vector#_content.) || !keys_equalcxx . . $ injeqt/internal/sorted_unique_vector#keys_equal(e33c049d02097613).(*(upperBound - 1), item)) |
| 136 | _contentcxx . . $ injeqt/internal/sorted_unique_vector#_content..emplacecxx . . $ std/vector#emplace(f067880028bce17f).(upperBound, stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(item)); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * @short Merge with another sorted vector. |
| 141 | * @param sorted_vector vector to merge with |
| 142 | * |
| 143 | * All items from sorted_vector are added at proper places and duplicates are removed. |
| 144 | */ |
| 145 | void mergecxx . . $ injeqt/internal/sorted_unique_vector#merge(9e71efcb105452bc).(const typecxx . . $ injeqt/internal/sorted_unique_vector#type# &sorted_vector) |
| 146 | { |
| 147 | auto result = storage_typecxx . . $ injeqt/internal/sorted_unique_vector#storage_type#{}; |
| 148 | |
| 149 | stdcxx . . $ std/::mergecxx . . $ std/merge(385b6b6ffcd23ab9).(stdcxx . . $ std/::begincxx . . $ std/begin(309ad712043406cf).(_contentcxx . . $ injeqt/internal/sorted_unique_vector#_content.), stdcxx . . $ std/::endcxx . . $ std/end(309ad712043406cf).(_contentcxx . . $ injeqt/internal/sorted_unique_vector#_content.), |
| 150 | stdcxx . . $ std/::begincxx . . $ std/begin(309ad712043406cf).(sorted_vector._contentcxx . . $ injeqt/internal/sorted_unique_vector#_content.), stdcxx . . $ std/::endcxx . . $ std/end(898c3e9f99adb426).(sorted_vector._contentcxx . . $ injeqt/internal/sorted_unique_vector#_content.), |
| 151 | stdcxx . . $ std/::back_insertercxx . . $ std/back_inserter(7b559d6bdd90ff74).(result), compare_keyscxx . . $ injeqt/internal/sorted_unique_vector#compare_keys(e33c049d02097613).); |
| 152 | ensure_uniquecxx . . $ injeqt/internal/sorted_unique_vector#ensure_unique(adcf2188fbe2a592).(result); |
| 153 | |
| 154 | _contentcxx . . $ injeqt/internal/sorted_unique_vector#_content. = stdcxx . . $ std/::movecxx . . $ std/move(88304b602929f6f4).(result); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * @return Data stored in sorted vector. |
| 159 | */ |
| 160 | const storage_typecxx . . $ injeqt/internal/sorted_unique_vector#storage_type# & contentcxx . . $ injeqt/internal/sorted_unique_vector#content(7f5cc961b06f27ae).() const |
| 161 | { |
| 162 | return _contentcxx . . $ injeqt/internal/sorted_unique_vector#_content.; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * @return true if no data is stored |
| 167 | */ |
| 168 | bool emptycxx . . $ injeqt/internal/sorted_unique_vector#empty(50ce9a9e25b4a850).() const |
| 169 | { |
| 170 | return _contentcxx . . $ injeqt/internal/sorted_unique_vector#_content..emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).(); |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * @return true if element with value v is found |
| 175 | */ |
| 176 | bool containscxx . . $ injeqt/internal/sorted_unique_vector#contains(83b2481dfe9844ed).(const value_typecxx . . $ injeqt/internal/sorted_unique_vector#value_type# &v) const |
| 177 | { |
| 178 | auto lower_bound = stdcxx . . $ std/::lower_boundcxx . . $ std/lower_bound(a92da12e15934614).(begincxx . . $ injeqt/internal/sorted_unique_vector#begin(10ded2c74433ed1).(), endcxx . . $ injeqt/internal/sorted_unique_vector#end(10ded2c74433ed1).(), v, compare_keyscxx . . $ injeqt/internal/sorted_unique_vector#compare_keys(e33c049d02097613).); |
| 179 | if (lower_bound ==cxx . . $ injeqt/v1/`operator==`(24fd26303071bddf). endcxx . . $ injeqt/internal/sorted_unique_vector#end(10ded2c74433ed1).()) |
| 180 | return false; |
| 181 | |
| 182 | return *lower_bound ==cxx . . $ injeqt/internal/`operator==`(a47c5f57c455a7c1). v; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * @return true if element with key k is found |
| 187 | */ |
| 188 | bool contains_keycxx . . $ injeqt/internal/sorted_unique_vector#contains_key(8877ebe272b9620d).(const key_typecxx . . $ injeqt/internal/sorted_unique_vector#key_type# &k) const |
| 189 | { |
| 190 | auto lower_bound = stdcxx . . $ std/::lower_boundcxx . . $ std/lower_bound(a92da12e15934614).(begincxx . . $ injeqt/internal/sorted_unique_vector#begin(10ded2c74433ed1).(), endcxx . . $ injeqt/internal/sorted_unique_vector#end(10ded2c74433ed1).(), k, compare_with_keycxx . . $ injeqt/internal/sorted_unique_vector#compare_with_key(dd05d8b9bf604774).); |
| 191 | if (lower_bound ==cxx . . $ injeqt/internal/`operator==`(a47c5f57c455a7c1). endcxx . . $ injeqt/internal/sorted_unique_vector#end(10ded2c74433ed1).()) |
| 192 | return false; |
| 193 | |
| 194 | return k ==cxx . . $ injeqt/v1/`operator==`(24fd26303071bddf). KeyExtractor(*lower_bound); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * @return item with key k |
| 199 | */ |
| 200 | const_iteratorcxx . . $ injeqt/internal/sorted_unique_vector#const_iterator# getcxx . . $ injeqt/internal/sorted_unique_vector#get(f1b725e3c61eba).(const key_typecxx . . $ injeqt/internal/sorted_unique_vector#key_type# &k) const |
| 201 | { |
| 202 | auto lower_bound = stdcxx . . $ std/::lower_boundcxx . . $ std/lower_bound(16e024635f5f5018).(begincxx . . $ injeqt/internal/sorted_unique_vector#begin(10ded2c74433ed1).(), endcxx . . $ injeqt/internal/sorted_unique_vector#end(10ded2c74433ed1).(), k, compare_with_keycxx . . $ injeqt/internal/sorted_unique_vector#compare_with_key(dd05d8b9bf604774).); |
| 203 | if (lower_bound ==cxx . . $ injeqt/internal/`operator==`(a47c5f57c455a7c1). endcxx . . $ injeqt/internal/sorted_unique_vector#end(10ded2c74433ed1).()) |
| 204 | return lower_bound; |
| 205 | |
| 206 | auto vk = KeyExtractor(*lower_bound); |
| 207 | if (vk ==cxx . . $ injeqt/internal/`operator==`(a47c5f57c455a7c1). k) |
| 208 | return lower_bound; |
| 209 | else |
| 210 | return endcxx . . $ injeqt/internal/sorted_unique_vector#end(10ded2c74433ed1).(); |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * @return number of stored items |
| 215 | */ |
| 216 | typename storage_typecxx . . $ injeqt/internal/sorted_unique_vector#storage_type#::size_type sizecxx . . $ injeqt/internal/sorted_unique_vector#size(89f858102beaadab).() const |
| 217 | { |
| 218 | return _contentcxx . . $ injeqt/internal/sorted_unique_vector#_content..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).(); |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * @short Removes all items from sorted vector. |
| 223 | */ |
| 224 | void clearcxx . . $ injeqt/internal/sorted_unique_vector#clear(49f6e7a06ebc5aa8).() |
| 225 | { |
| 226 | _contentcxx . . $ injeqt/internal/sorted_unique_vector#_content..clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).(); |
| 227 | } |
| 228 | |
| 229 | private: |
| 230 | storage_typecxx . . $ injeqt/internal/sorted_unique_vector#storage_type# _contentcxx . . $ injeqt/internal/sorted_unique_vector#_content.; |
| 231 | |
| 232 | void ensure_uniquecxx . . $ injeqt/internal/sorted_unique_vector#ensure_unique(adcf2188fbe2a592).(storage_typecxx . . $ injeqt/internal/sorted_unique_vector#storage_type# &storage) |
| 233 | { |
| 234 | storage.erasecxx . . $ std/vector#erase(351407f384f345bc).(stdcxx . . $ std/::uniquecxx . . $ std/unique(f80f7d6260b3ee3a).(stdcxx . . $ std/::begincxx . . $ std/begin(75b65c691aba1eff).(storage), stdcxx . . $ std/::endcxx . . $ std/end(898c3e9f99adb426).(storage), keys_equalcxx . . $ injeqt/internal/sorted_unique_vector#keys_equal(e33c049d02097613).), stdcxx . . $ std/::endcxx . . $ std/end(75b65c691aba1eff).(storage)); |
| 235 | } |
| 236 | |
| 237 | }; |
| 238 | |
| 239 | /** |
| 240 | * @return begin iterator to content of sorted_unique_vector. |
| 241 | */ |
| 242 | template<typename K, typename V, K (*KeyExtractor)(const V &)> |
| 243 | typename sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#<K, V, KeyExtractor>::const_iterator begincxx . . $ injeqt/internal/begin(9638168a7e9b19c2).(const sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#<K, V, KeyExtractor> &sorted_vector) |
| 244 | { |
| 245 | return stdcxx . . $ std/::begincxx . . $ std/begin(a139f8bc8514c5ac).(sorted_vector.contentcxx . . $ injeqt/internal/sorted_unique_vector#content(7f5cc961b06f27ae).()); |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * @return end iterator to content of sorted_unique_vector. |
| 250 | */ |
| 251 | template<typename K, typename V, K (*KeyExtractor)(const V &)> |
| 252 | typename sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#<K, V, KeyExtractor>::const_iterator endcxx . . $ injeqt/internal/end(9638168a7e9b19c2).(const sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#<K, V, KeyExtractor> &sorted_vector) |
| 253 | { |
| 254 | return stdcxx . . $ std/::endcxx . . $ std/end(75b65c691aba1eff).(sorted_vector.contentcxx . . $ injeqt/internal/sorted_unique_vector#content(7f5cc961b06f27ae).()); |
| 255 | } |
| 256 | |
| 257 | template<typename K, typename V, K (*KeyExtractor)(const V &)> |
| 258 | bool operatorcxx . . $ injeqt/internal/`operator==`(775eccf7ae465e6e). == (const sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#<K, V, KeyExtractor> &x, const sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#<K, V, KeyExtractor> &y) |
| 259 | { |
| 260 | return x.contentcxx . . $ injeqt/internal/sorted_unique_vector#content(7f5cc961b06f27ae).() ==cxx . . $ injeqt/internal/`operator==`(775eccf7ae465e6e). y.contentcxx . . $ injeqt/internal/sorted_unique_vector#content(7f5cc961b06f27ae).(); |
| 261 | } |
| 262 | |
| 263 | template<typename K, typename V, K (*KeyExtractor)(const V &)> |
| 264 | bool operatorcxx . . $ injeqt/internal/`operator!=`(775eccf7ae465e6e). != (const sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#<K, V, KeyExtractor> &x, const sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#<K, V, KeyExtractor> &y) |
| 265 | { |
| 266 | return !(x ==cxx . . $ injeqt/internal/`operator==`(a47c5f57c455a7c1). y); |
| 267 | } |
| 268 | |
| 269 | template<typename K1, typename K2, typename V1, typename V2, K1 (*KeyExtractor1)(const V1 &), K2 (*KeyExtractor2)(const V2 &)> |
| 270 | struct match_resultcxx . . $ injeqt/internal/match_result# |
| 271 | { |
| 272 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<V1, V2>> matchedcxx . . $ injeqt/internal/match_result#matched.; |
| 273 | sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#<K1, V1, KeyExtractor1> unmatched_1cxx . . $ injeqt/internal/match_result#unmatched_1.; |
| 274 | sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#<K2, V2, KeyExtractor2> unmatched_2cxx . . $ injeqt/internal/match_result#unmatched_2.; |
| 275 | }; |
| 276 | |
| 277 | enum class match_increment_modecxx . . $ injeqt/internal/match_increment_mode# |
| 278 | { |
| 279 | bothcxx . . $ injeqt/internal/match_increment_mode#both., |
| 280 | leftcxx . . $ injeqt/internal/match_increment_mode#left. |
| 281 | }; |
| 282 | |
| 283 | template<typename K, typename K1, typename K2, typename V1, typename V2, K1 (*KeyExtractor1)(const V1 &), K2 (*KeyExtractor2)(const V2 &)> |
| 284 | match_resultcxx . . $ injeqt/internal/match_result#<K1, K2, V1, V2, KeyExtractor1, KeyExtractor2> |
| 285 | matchcxx . . $ injeqt/internal/match(cfcd46084eda7e49).( |
| 286 | const sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#<K1, V1, KeyExtractor1> &suv_1, |
| 287 | const sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#<K2, V2, KeyExtractor2> &suv_2, |
| 288 | K(*ke1)(const V1 &), |
| 289 | K(*ke2)(const V2 &), |
| 290 | match_increment_modecxx . . $ injeqt/internal/match_increment_mode# increment_mode = match_increment_modecxx . . $ injeqt/internal/match_increment_mode#::bothcxx . . $ injeqt/internal/match_increment_mode#both.) |
| 291 | { |
| 292 | auto unmatched_1 = stdcxx . . $ std/::vectorcxx . . $ std/vector#<V1>{}; |
| 293 | auto unmatched_2 = stdcxx . . $ std/::vectorcxx . . $ std/vector#<V2>{}; |
| 294 | auto matched = stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<V1, V2>>{}; |
| 295 | |
| 296 | auto suv_1_it = begincxx . . $ injeqt/internal/begin(9638168a7e9b19c2).(suv_1); |
| 297 | auto suv_1_end = endcxx . . $ injeqt/internal/end(9638168a7e9b19c2).(suv_1); |
| 298 | auto suv_2_it = begincxx . . $ injeqt/internal/begin(9638168a7e9b19c2).(suv_2); |
| 299 | auto suv_2_end = endcxx . . $ injeqt/internal/end(9638168a7e9b19c2).(suv_2); |
| 300 | |
| 301 | while (suv_1_it !=cxx . . $ injeqt/internal/`operator!=`(a47c5f57c455a7c1). suv_1_end && suv_2_it !=cxx . . $ injeqt/internal/`operator!=`(775eccf7ae465e6e). suv_2_end) |
| 302 | { |
| 303 | auto suv_1_key = ke1(*suv_1_it); |
| 304 | auto suv_2_key = ke2(*suv_2_it); |
| 305 | if (suv_1_key ==cxx . . $ injeqt/internal/`operator==`(775eccf7ae465e6e). suv_2_key) |
| 306 | { |
| 307 | matched.emplace_back(*suv_1_it, *suv_2_it); |
| 308 | switch (increment_mode) |
| 309 | { |
| 310 | case match_increment_modecxx . . $ injeqt/internal/match_increment_mode#::bothcxx . . $ injeqt/internal/match_increment_mode#both.: |
| 311 | ++suv_1_it; |
| 312 | ++suv_2_it; |
| 313 | break; |
| 314 | case match_increment_modecxx . . $ injeqt/internal/match_increment_mode#::leftcxx . . $ injeqt/internal/match_increment_mode#left.: |
| 315 | ++suv_1_it; |
| 316 | break; |
| 317 | } |
| 318 | } |
| 319 | else if (suv_1_key <cxx . . $ injeqt/internal/`operator<`(a47c5f57c455a7c1). suv_2_key) |
| 320 | { |
| 321 | unmatched_1.emplace_back(*suv_1_it); |
| 322 | ++suv_1_it; |
| 323 | } |
| 324 | else if (suv_2_key <cxx . . $ injeqt/internal/`operator<`(a47c5f57c455a7c1). suv_1_key) |
| 325 | { |
| 326 | unmatched_2.emplace_back(*suv_2_it); |
| 327 | ++suv_2_it; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | while (suv_1_it !=cxx . . $ injeqt/internal/`operator!=`(a47c5f57c455a7c1). suv_1_end) |
| 332 | { |
| 333 | unmatched_1.emplace_back(*suv_1_it); |
| 334 | suv_1_it++; |
| 335 | } |
| 336 | |
| 337 | while (suv_2_it !=cxx . . $ injeqt/internal/`operator!=`(775eccf7ae465e6e). suv_2_end) |
| 338 | { |
| 339 | unmatched_2.emplace_back(*suv_2_it); |
| 340 | suv_2_it++; |
| 341 | } |
| 342 | |
| 343 | return |
| 344 | { |
| 345 | matched, |
| 346 | sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#<K1, V1, KeyExtractor1>{unmatched_1}, |
| 347 | sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#<K2, V2, KeyExtractor2>{unmatched_2} |
| 348 | }; |
| 349 | } |
| 350 | |
| 351 | template<typename K, typename V1, typename V2, K (*KeyExtractor1)(const V1 &), K (*KeyExtractor2)(const V2 &)> |
| 352 | match_resultcxx . . $ injeqt/internal/match_result#<K, K, V1, V2, KeyExtractor1, KeyExtractor2> |
| 353 | matchcxx . . $ injeqt/internal/match(f64fa725a7b4ed06).(const sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#<K, V1, KeyExtractor1> &suv_1, const sorted_unique_vectorcxx . . $ injeqt/internal/sorted_unique_vector#<K, V2, KeyExtractor2> &suv_2) |
| 354 | { |
| 355 | return matchcxx . . $ injeqt/internal/match(f64fa725a7b4ed06).(suv_1, suv_2, KeyExtractor1, KeyExtractor2); |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * @} |
| 360 | */ |
| 361 | |
| 362 | }} |