40 mapping(_In_ T _from, _In_ T _to) : from(_from), to(_to) {}
49 bool operator==(
const mapping& other)
const {
return from == other.from && to == other.to; }
69 return mapping(from + other.from, to + other.to);
73 template <
class T,
class AX = std::allocator<mapping<T>>>
74 using mapping_vector = std::vector<mapping<T>, AX>;
84 template <
class T,
class AX = std::allocator<mapping<T>>>
90 for (
size_t l = 0, r = mapping.size();;) {
93 const auto& el = mapping[m];
94 if (to < el.to) r = m;
95 else if (el.to < to) l = m + 1;
99 const auto& el = mapping[l - 1];
100 return el.from + (to - el.to);
103 const auto& el = mapping[0];
104 return std::min<T>(to, el.from);
118 template <
class T,
class AX = std::allocator<mapping<T>>>
119 T dst2src(_In_
const std::vector<
stdex::mapping<T>, AX>& mapping, _In_ T to, _Inout_opt_
size_t& m)
125 const auto& el = mapping[m];
130 else if (el.to < to) {
131 if (mapping.size() - 1 <= m || to < mapping[m + 1].to)
132 return el.from + (to - el.to);
142 const auto& el = mapping[m];
143 if (to < el.to) r = m;
144 else if (el.to < to) l = m + 1;
148 const auto& el = mapping[m = l - 1];
149 return el.from + (to - el.to);
152 const auto& el = mapping[m = 0];
153 return std::min<T>(to, el.from);
166 template <
class T,
class AX = std::allocator<mapping<T>>>
172 for (
size_t l = 0, r = mapping.size();;) {
174 auto m = (l + r) / 2;
175 const auto& el = mapping[m];
176 if (from < el.from) r = m;
177 else if (el.from < from) l = m + 1;
181 const auto& el = mapping[l - 1];
182 return el.to + (from - el.from);
185 const auto& el = mapping[0];
186 return std::min<T>(from, el.to);
200 template <
class T,
class AX = std::allocator<mapping<T>>>
201 T src2dst(_In_
const std::vector<
stdex::mapping<T>, AX>& mapping, _In_ T from, _Inout_opt_
size_t& m)
207 const auto& el = mapping[m];
208 if (from < el.from) {
212 else if (el.from < from) {
213 if (mapping.size() - 1 <= m || from < mapping[m + 1].from)
214 return el.to + (from - el.from);
224 const auto& el = mapping[m];
225 if (from < el.from) r = m;
226 else if (el.from < from) l = m + 1;
230 const auto& el = mapping[m = l - 1];
231 return el.to + (from - el.from);
234 const auto& el = mapping[m = 0];
235 return std::min<T>(from, el.to);
Maps index in source string to index in destination string.
Definition mapping.hpp:18
mapping(T x)
Constructs an id mapping.
Definition mapping.hpp:32
bool operator==(const mapping &other) const
Are mappings identical?
Definition mapping.hpp:49
mapping()
Constructs a zero to zero mapping.
Definition mapping.hpp:25
bool operator!=(const mapping &other) const
Are mappings different?
Definition mapping.hpp:58
mapping operator+(const mapping &other) const
Adds two mappings by components.
Definition mapping.hpp:67
mapping(T _from, T _to)
Constructs a mapping.
Definition mapping.hpp:40