1 /* ============================================================ 2 * QuiteRSS is a open-source cross-platform RSS/Atom news feeds reader 3 * Copyright (C) 2011-2020 QuiteRSS Team <quiterssteam@gmail.com> 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 * ============================================================ */ 18 /* ============================================================ 19 * QupZilla - WebKit based browser 20 * Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com> 21 * 22 * This program is free software: you can redistribute it and/or modify 23 * it under the terms of the GNU General Public License as published by 24 * the Free Software Foundation, either version 3 of the License, or 25 * (at your option) any later version. 26 * 27 * This program is distributed in the hope that it will be useful, 28 * but WITHOUT ANY WARRANTY; without even the implied warranty of 29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 * GNU General Public License for more details. 31 * 32 * You should have received a copy of the GNU General Public License 33 * along with this program. If not, see <https://www.gnu.org/licenses/>. 34 * ============================================================ */ 35 #ifndef ADBLOCKSEARCHTREE_H 36 #define ADBLOCKSEARCHTREE_H 37 38 #include <QChar> 39 #include <QHash> 40 41 class QNetworkRequest; 42 43 class AdBlockRule; 44 45 class AdBlockSearchTree 46 { 47 public: 48 explicit AdBlockSearchTree(); 49 ~AdBlockSearchTree(); 50 51 void clear(); 52 53 bool add(const AdBlockRule* rule); 54 const AdBlockRule* find(const QNetworkRequest &request, const QString &domain, const QString &urlString) const; 55 56 private: 57 struct Node { 58 QChar c; 59 const AdBlockRule* rule; 60 QHash<QChar, Node*> children; 61 NodeNode62 Node() : c(0) , rule(0) { } 63 }; 64 65 const AdBlockRule* prefixSearch(const QNetworkRequest &request, const QString &domain, 66 const QString &urlString, const QChar* string, int len) const; 67 68 void deleteNode(Node* node); 69 70 Node* m_root; 71 }; 72 73 #endif // ADBLOCKSEARCHTREE_H 74