00001 /* 00002 00003 Copyright (C) 2005-2007 by Peter Dimov. 00004 00005 This file is part of Calitko (http://www.calitko.org). 00006 00007 Calitko is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 Calitko is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with Calitko; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 00021 */ 00022 00023 #ifndef GNUTELLA__PACKET_PROCESSING__QUERY_ROUTING__QUERY_ROUTING_TABLE_H 00024 #define GNUTELLA__PACKET_PROCESSING__QUERY_ROUTING__QUERY_ROUTING_TABLE_H 00025 00026 #include "Imports.h" 00027 00028 namespace Gnutella { 00029 namespace PacketProcessing { 00030 namespace QueryRouting { 00031 00035 class QueryRoutingTable{ 00036 00037 public: 00038 QueryRoutingTable(); 00039 ~QueryRoutingTable(); 00040 00041 void reset (quint32 size); 00042 void setRawTable (const QByteArray &rawTable); 00043 void applyPatch (QByteArray &patchBuffer, quint8 entryBits); 00044 QByteArray makePatchTo (const QueryRoutingTable &newTable, 00045 quint8 entryBits) const; 00046 void addTable (const QueryRoutingTable &other); 00047 void scaledCopy (const QueryRoutingTable &other); 00048 00049 bool isEntrySet (quint32 index) const; 00050 void setEntry (quint32 index); 00051 void resetEntry (quint32 index); 00052 00053 bool hasString (QString x) const; 00054 void add (QString x); 00055 void remove (QString x); 00056 00057 quint32 size() const; 00058 QByteArray rawTable() const; 00059 00060 private: 00061 int hash (QString x, int start, int end, quint8 bits) const; 00062 int hashFast (int x, quint8 bits) const; 00063 00064 QByteArray rawTable_; 00065 quint32 size_; 00066 quint32 sizeBits_; 00067 }; 00068 00069 inline void QueryRoutingTable::setRawTable (const QByteArray &rawTable) 00070 { Q_ASSERT (size_ == quint32 (rawTable.size() * 8)); rawTable_ = rawTable; } 00071 00072 inline quint32 QueryRoutingTable::size() const 00073 { return size_; } 00074 00075 inline QByteArray QueryRoutingTable::rawTable() const 00076 { return rawTable_; } 00077 00078 } //namespace QueryRouting 00079 } // namespace QueryRouting 00080 } // namespace Gnutella 00081 00082 #endif // GNUTELLA__PACKET_PROCESSING__QUERY_ROUTING__QUERY_ROUTING_TABLE_H