aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/common/bistrhash.h
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2016-06-13 18:42:42 -0400
committerLibravatarUnit 193 <unit193@ubuntu.com>2016-06-13 18:42:42 -0400
commit5d9314f134ddd3dc4c853e398ac90ba247fb2e4f (patch)
tree5c457fc188036988d7abd29a3eb09931e406510f /SQLiteStudio3/coreSQLiteStudio/common/bistrhash.h
parent8e640722c62692818ab840d50b3758f89a41a54e (diff)
Imported Upstream version 3.1.0upstream/3.1.0
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/common/bistrhash.h')
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/common/bistrhash.h213
1 files changed, 23 insertions, 190 deletions
diff --git a/SQLiteStudio3/coreSQLiteStudio/common/bistrhash.h b/SQLiteStudio3/coreSQLiteStudio/common/bistrhash.h
index 65c907b..2089010 100644
--- a/SQLiteStudio3/coreSQLiteStudio/common/bistrhash.h
+++ b/SQLiteStudio3/coreSQLiteStudio/common/bistrhash.h
@@ -2,6 +2,7 @@
#define BISTRHASH_H
#include "bihash.h"
+#include "coreSQLiteStudio_global.h"
#include <QHash>
#include <QString>
@@ -14,7 +15,7 @@
*
* Just like BiHash, the BiStrHash doesn't provide operator[]. For more details see BiHash.
*/
-class BiStrHash
+class API_EXPORT BiStrHash
{
public:
/**
@@ -26,11 +27,7 @@ class BiStrHash
* @brief Creates pre-initialized hash.
* @param list C++11 style initializer list, like: <tt>{{"x"="y"}, {"a"="b"}}</tt>
*/
- BiStrHash(std::initializer_list<std::pair<QString, QString>> list)
- {
- hash = QHash<QString,QString>(list);
- initInvertedAndLower();
- }
+ BiStrHash(std::initializer_list<std::pair<QString, QString>> list);
/**
* @brief Creates BiStrHash basing on QHash.
@@ -39,17 +36,13 @@ class BiStrHash
* Any conflicting values from the \p other hash will overwrite
* current values in the hash.
*/
- BiStrHash(const QHash<QString, QString> & other)
- {
- unite(other);
- }
+ BiStrHash(const QHash<QString, QString> & other);
/**
* @brief Copy constructor.
* @param other Other hash to copy.
*/
- BiStrHash(const BiStrHash& other) : hash(other.hash), inverted(other.inverted),
- lowerHash(other.lowerHash), lowerInverted(other.lowerInverted) {}
+ BiStrHash(const BiStrHash& other);
/**
* @brief Inserts entry into the hash.
@@ -59,19 +52,7 @@ class BiStrHash
* Inserting to the hash is done in case-insensitive manner, hence any conflicting
* values matched with case insensitive method will be replaced with the new entry.
*/
- void insert(const QString& left, const QString& right)
- {
- if (lowerHash.contains(left.toLower()))
- removeLeft(left, Qt::CaseInsensitive);
-
- if (lowerInverted.contains(right.toLower()))
- removeRight(right, Qt::CaseInsensitive);
-
- inverted.insert(right, left);
- hash.insert(left, right);
- lowerHash.insert(left.toLower(), left);
- lowerInverted.insert(right.toLower(), right);
- }
+ void insert(const QString& left, const QString& right);
/**
* @brief Tests if given value is in the left values of the hash.
@@ -79,13 +60,7 @@ class BiStrHash
* @param cs Case sensitivity flag.
* @return true if the key was matched in left side values, or false otherwise.
*/
- bool containsLeft(const QString& left, Qt::CaseSensitivity cs = Qt::CaseSensitive)
- {
- if (cs == Qt::CaseSensitive)
- return hash.contains(left);
- else
- return lowerHash.contains(left.toLower());
- }
+ bool containsLeft(const QString& left, Qt::CaseSensitivity cs = Qt::CaseSensitive);
/**
* @brief Tests if given value is in the right values of the hash.
@@ -93,13 +68,7 @@ class BiStrHash
* @param cs Case sensitivity flag.
* @return true if the key was matched in right side values, or false otherwise.
*/
- bool containsRight(const QString& right, Qt::CaseSensitivity cs = Qt::CaseSensitive)
- {
- if (cs == Qt::CaseSensitive)
- return inverted.contains(right);
- else
- return lowerInverted.contains(right.toLower());
- }
+ bool containsRight(const QString& right, Qt::CaseSensitivity cs = Qt::CaseSensitive);
/**
* @brief Removes entry matching given value in left-side values.
@@ -107,34 +76,7 @@ class BiStrHash
* @param cs Case sensitivity flag.
* @return Number of entries removed.
*/
- int removeLeft(const QString& left, Qt::CaseSensitivity cs = Qt::CaseSensitive)
- {
- if (cs == Qt::CaseSensitive)
- {
- if (!hash.contains(left))
- return 0;
-
- inverted.remove(hash.value(left));
- hash.remove(left);
-
- return 1;
- }
- else
- {
- QString lowerLeft = left.toLower();
- if (!lowerHash.contains(lowerLeft))
- return 0;
-
- QString right = hash.value(lowerHash.value(lowerLeft));
-
- hash.remove(inverted.value(right));
- inverted.remove(right);
- lowerHash.remove(lowerLeft);
- lowerInverted.remove(right.toLower());
-
- return 1;
- }
- }
+ int removeLeft(const QString& left, Qt::CaseSensitivity cs = Qt::CaseSensitive);
/**
* @brief Removes entry matching given value in right-side values.
@@ -142,34 +84,7 @@ class BiStrHash
* @param cs Case sensitivity flag.
* @return Number of entries removed.
*/
- int removeRight(const QString& right, Qt::CaseSensitivity cs = Qt::CaseSensitive)
- {
- if (cs == Qt::CaseSensitive)
- {
- if (!inverted.contains(right))
- return 0;
-
- hash.remove(inverted.value(right));
- inverted.remove(right);
-
- return 1;
- }
- else
- {
- QString lowerRight = right.toLower();
- if (!lowerInverted.contains(lowerRight))
- return 0;
-
- QString left = inverted.value(lowerInverted.value(lowerRight));
-
- inverted.remove(hash.value(left));
- hash.remove(left);
- lowerHash.remove(left.toLower());
- lowerInverted.remove(lowerRight);
-
- return 1;
- }
- }
+ int removeRight(const QString& right, Qt::CaseSensitivity cs = Qt::CaseSensitive);
/**
* @brief Removes entry from hash and returns it.
@@ -177,21 +92,7 @@ class BiStrHash
* @param cs Case sensitivity flag.
* @return Right side value, or null string if the \p left was not matched.
*/
- QString takeLeft(const QString& left, Qt::CaseSensitivity cs = Qt::CaseSensitive)
- {
- if (cs == Qt::CaseSensitive)
- {
- QString right = hash.take(left);
- inverted.remove(right);
- return right;
- }
- else
- {
- QString right = hash.take(lowerHash.take(left.toLower()));
- inverted.remove(lowerInverted.take(right.toLower()));
- return right;
- }
- }
+ QString takeLeft(const QString& left, Qt::CaseSensitivity cs = Qt::CaseSensitive);
/**
* @brief Removes entry from hash and returns it.
@@ -199,44 +100,19 @@ class BiStrHash
* @param cs Case sensitivity flag.
* @return Left side value, or null string if the \p left was not matched.
*/
- QString takeRight(const QString& right, Qt::CaseSensitivity cs = Qt::CaseSensitive)
- {
- if (cs == Qt::CaseSensitive)
- {
- QString left = inverted.take(right);
- hash.remove(left);
- return left;
- }
- else
- {
- QString left = inverted.take(lowerInverted.take(right.toLower()));
- hash.remove(lowerHash.take(left.toLower()));
- return left;
- }
- }
+ QString takeRight(const QString& right, Qt::CaseSensitivity cs = Qt::CaseSensitive);
/**
* @brief Copies all entries from the other hash to this hash.
* @param other Other hash to copy values from.
* @return Reference to this hash, after update.
*/
- BiStrHash& unite(const BiStrHash& other)
- {
- unite(other.hash);
- return *this;
- }
+ BiStrHash& unite(const BiStrHash& other);
/**
* @overload
*/
- BiStrHash& unite(const QHash<QString,QString>& other)
- {
- QHashIterator<QString, QString> it(other);
- while (it.hasNext())
- insert(it.next().key(), it.value());
-
- return *this;
- }
+ BiStrHash& unite(const QHash<QString,QString>& other);
/**
* @brief Finds right-side value by matching the left-side value.
@@ -244,13 +120,7 @@ class BiStrHash
* @param cs Case sensitivity flag.
* @return Right-side value, or null string if left-side value was not matched.
*/
- QString valueByLeft(const QString& left, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
- {
- if (cs == Qt::CaseSensitive)
- return hash.value(left);
- else
- return hash.value(lowerHash.value(left.toLower()));
- }
+ QString valueByLeft(const QString& left, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
/**
* @brief Finds left-side value by matching the right-side value.
@@ -258,85 +128,48 @@ class BiStrHash
* @param cs Case sensitivity flag.
* @return Left-side value, or null string if right-side value was not matched.
*/
- QString valueByRight(const QString& right, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
- {
- if (cs == Qt::CaseSensitive)
- return inverted.value(right);
- else
- return inverted.value(lowerInverted.value(right.toLower()));
- }
+ QString valueByRight(const QString& right, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
/**
* @brief Gives all left-side values.
* @return List of values.
*/
- QStringList leftValues() const
- {
- return hash.keys();
- }
+ QStringList leftValues() const;
/**
* @brief Gives all right-side values.
* @return List of values.
*/
- QStringList rightValues() const
- {
- return inverted.keys();
- }
+ QStringList rightValues() const;
/**
* @brief Provides java-style iterator for this hash.
* @return Iterator object.
*/
- QHashIterator<QString,QString> iterator() const
- {
- return QHashIterator<QString,QString>(hash);
- }
+ QHashIterator<QString,QString> iterator() const;
/**
* @brief Removes all entries from the hash.
*/
- void clear()
- {
- hash.clear();
- inverted.clear();
- lowerHash.clear();
- lowerInverted.clear();
- }
+ void clear();
/**
* @brief Counts all entries in the hash.
* @return Number of entries in the hash.
*/
- int count() const
- {
- return hash.count();
- }
+ int count() const;
/**
* @brief Tests whether the hash is empty or not.
* @return true if the hash is empty, false otherwise.
*/
- bool isEmpty() const
- {
- return hash.isEmpty();
- }
+ bool isEmpty() const;
private:
/**
* @brief Fills inverted and lower internal hashes basing on the main hash class member.
*/
- void initInvertedAndLower()
- {
- QHashIterator<QString,QString> it(hash);
- while (it.hasNext())
- {
- it.next();
- inverted[it.value()] = it.key();
- lowerHash[it.key().toLower()] = it.key();
- lowerInverted[it.value().toLower()] = it.value();
- }
- }
+ void initInvertedAndLower();
/**
* @brief Standard mapping - left to right.