23 Private(
const Private &other)
41 Private(
const Private &other)
43 , intervals(other.intervals)
81 return (d->begin == other.d->begin && d->end == other.d->end);
86 if (!d->begin && !d->end) {
89 if (d->begin && !d->end) {
90 return Q_INT64_C(0x7FFFFFFFFFFFFFFF) - d->begin + 1;
92 return d->end - d->begin + 1;
115 return std::numeric_limits<qint64>::max();
120 Q_ASSERT(value >= 0);
127 Q_ASSERT(value >= 0);
157 Id begin = values[0].toLongLong(&ok);
165 if (values.
size() == 1) {
171 end = values[1].toLongLong(&ok);
208 if (
this != &other) {
216 if (d->intervals.size() != other.d->intervals.size()) {
220 for (
const ImapInterval &interval : std::as_const(d->intervals)) {
221 if (!other.d->intervals.contains(interval)) {
237 std::sort(vals.
begin(), vals.
end());
238 for (
int i = 0; i < vals.
count(); ++i) {
239 const Id begin = vals[i];
240 Q_ASSERT(begin >= 0);
241 if (i == vals.
count() - 1) {
247 Q_ASSERT(vals[i] >= 0);
248 if (vals[i] != (vals[i - 1] + 1)) {
252 }
while (i < vals.
count() - 1);
259 d->intervals << interval;
265 rv.
reserve(d->intervals.count());
266 for (
const ImapInterval &interval : std::as_const(d->intervals)) {
267 rv << interval.toImapSequence();
277 for (; it != end; ++it) {
278 result +=
',' + (*it);
292 if (!interval.isEmpty()) {
307 return d->intervals.isEmpty();
313 if (d->intervals.size() < 2) {
319 return lhs.begin() < rhs.begin();
322 auto it = d->intervals.begin();
323 while (it != d->intervals.end() && it != std::prev(d->intervals.end())) {
324 auto next = std::next(it);
326 if (it->hasDefinedEnd() && it->end() + 1 >= next->begin()) {
327 next->setBegin(it->begin());
328 if (next->hasDefinedEnd() && it->end() > next->end()) {
329 next->setEnd(it->end());
331 it = d->intervals.erase(it);
332 }
else if (!it->hasDefinedEnd()) {
334 it = d->intervals.erase(next, d->intervals.end());
Represents a single interval in an ImapSet.
bool hasDefinedBegin() const
Returns true if this interval has a defined begin.
ImapInterval()
Constructs an interval that covers all positive numbers.
ImapInterval & operator=(const ImapInterval &other)
Assignment operator.
static ImapInterval fromImapSequence(const QByteArray &sequence)
Return the interval corresponding to the given IMAP-compatible QByteArray representation.
~ImapInterval()
Destructor.
Id end() const
Returns the end of this interval.
Id begin() const
Returns the begin of this interval.
void setEnd(Id value)
Sets the end of this interval.
Id size() const
Returns the size of this interval.
bool operator==(const ImapInterval &other) const
Comparison operator.
bool hasDefinedEnd() const
Returns true if this intercal has been defined.
void setBegin(Id value)
Sets the begin of the interval.
qint64 Id
Describes the ids stored in the interval.
QByteArray toImapSequence() const
Converts this set into an IMAP compatible sequence.
Represents a set of natural numbers (1->∞) in a as compact as possible form.
qint64 Id
Describes the ids stored in the set.
bool isEmpty() const
Returns true if this set doesn't contains any values.
ImapSet()
Constructs an empty set.
void optimize()
Optimizes the ImapSet by sorting and merging overlapping intervals.
QByteArray toImapSequenceSet() const
Returns a IMAP-compatible QByteArray representation of this set.
void add(Id value)
Adds a single positive integer numbers to the set.
static ImapSet fromImapSequenceSet(const QByteArray &sequence)
Return the set corresponding to the given IMAP-compatible QByteArray representation.
bool operator==(const ImapSet &other) const
Comparison operator.
ImapInterval::List intervals() const
Returns the intervals this set consists of.
ImapSet & operator=(const ImapSet &other)
Assignment operator.
QByteArray number(double n, char format, int precision)
QList< QByteArray > split(char sep) const const
const_iterator constBegin() const const
const_iterator constEnd() const const
qsizetype count() const const
bool isEmpty() const const
void reserve(qsizetype size)
qsizetype size() const const