PIByteArray compare operators

This commit is contained in:
2021-08-12 21:41:22 +03:00
parent ee131921a0
commit 39a3a23a24
2 changed files with 23 additions and 23 deletions

View File

@@ -190,10 +190,16 @@ public:
return true;
}
inline bool operator !=(const PIDeque<T> & t) const {return !(*this == t);}
inline bool operator <(const PIDeque<T> & t) const {
if (pid_size != t.pid_size) return pid_size < t.pid_size;
for (size_t i = 0; i < pid_size; ++i)
if ((*this)[i] != t[i]) return (*this)[i] < t[i];
return false;
}
inline bool operator >(const PIDeque<T> & t) const {
if (pid_size != t.pid_size) return pid_size > t.pid_size;
for (size_t i = 0; i < pid_size; ++i)
if (t[i] != (*this)[i]) return t[i] > (*this)[i];
if ((*this)[i] != t[i]) return (*this)[i] > t[i];
return false;
}
inline bool contains(const T & v) const {

View File

@@ -190,10 +190,8 @@ public:
//! \relatesalso PIByteArray @brief Byte arrays compare operator
inline bool operator <(const PIByteArray & v0, const PIByteArray & v1) {
if (v0.size() == v1.size()) {
for (uint i = 0; i < v0.size(); ++i)
if (v0[i] != v1[i])
return v0[i] < v1[i];
return false;
if (v0.isEmpty()) return false;
return memcmp(v0.data(), v1.data(), v0.size()) < 0;
}
return v0.size() < v1.size();
}
@@ -201,32 +199,28 @@ inline bool operator <(const PIByteArray & v0, const PIByteArray & v1) {
//! \relatesalso PIByteArray @brief Byte arrays compare operator
inline bool operator >(const PIByteArray & v0, const PIByteArray & v1) {
if (v0.size() == v1.size()) {
for (uint i = 0; i < v0.size(); ++i)
if (v0[i] != v1[i])
return v0[i] > v1[i];
return false;
if (v0.isEmpty()) return false;
return memcmp(v0.data(), v1.data(), v0.size()) > 0;
}
return v0.size() > v1.size();
}
//! \relatesalso PIByteArray @brief Byte arrays compare operator
inline bool operator ==(PIByteArray & f, PIByteArray & s) {
if (f.size_s() != s.size_s())
return false;
for (int i = 0; i < f.size_s(); ++i)
if (f[i] != s[i])
return false;
return true;
inline bool operator ==(const PIByteArray & v0, const PIByteArray & v1) {
if (v0.size() == v1.size()) {
if (v0.isEmpty()) return true;
return memcmp(v0.data(), v1.data(), v0.size()) == 0;
}
return false;
}
//! \relatesalso PIByteArray @brief Byte arrays compare operator
inline bool operator !=(PIByteArray & f, PIByteArray & s) {
if (f.size_s() != s.size_s())
return true;
for (int i = 0; i < f.size_s(); ++i)
if (f[i] != s[i])
return true;
return false;
inline bool operator !=(const PIByteArray & v0, const PIByteArray & v1) {
if (v0.size() == v1.size()) {
if (v0.isEmpty()) return false;
return memcmp(v0.data(), v1.data(), v0.size()) != 0;
}
return true;
}
#ifdef PIP_STD_IOSTREAM