fix logic
[personal-kdelibs.git] / kdecore / sycoca / ksycocadict.h
blobc63880e3e00788d4829cce3b849f31ba77d02079
1 /* This file is part of the KDE libraries
2 * Copyright (C) 1999 Waldo Bastian <bastian@kde.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License version 2 as published by the Free Software Foundation;
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
13 * You should have received a copy of the GNU Library General Public License
14 * along with this library; see the file COPYING.LIB. If not, write to
15 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 **/
19 #ifndef KSYCOCADICT_H
20 #define KSYCOCADICT_H
22 #include <kdecore_export.h>
23 #include "ksycocaentry.h"
25 #include <QList>
27 class QString;
28 class QDataStream;
30 /**
31 * @internal
32 * Hash table implementation for the sycoca database file
34 class KDECORE_EXPORT KSycocaDict //krazy:exclude=dpointer (not const because it gets deleted by clear())
36 public:
37 /**
38 * Create an empty dict, for building the database
40 KSycocaDict();
41 /**
42 * Create a dict from an existing database
44 KSycocaDict(QDataStream *str, int offset);
46 ~KSycocaDict();
48 /**
49 * Adds a 'payload' to the dictionary with key 'key'.
51 * 'payload' should have a valid offset by the time
52 * the dictionary gets saved.
53 **/
54 void add(const QString &key, const KSycocaEntry::Ptr& payload);
56 /**
57 * Removes the 'payload' from the dictionary with key 'key'.
59 * Not very fast, use with care O(N)
60 **/
61 void remove(const QString &key);
63 /**
64 * Looks up an entry identified by 'key'.
66 * If 0 is returned, no matching entry exists.
67 * Otherwise, the offset of the entry is returned.
69 * NOTE: It is not guaranteed that this entry is
70 * indeed the one you were looking for.
71 * After loading the entry you should check that it
72 * indeed matches the search key. If it doesn't
73 * then no matching entry exists.
75 int find_string(const QString &key ) const;
77 /**
78 * Looks up all entries identified by 'key'.
79 * This is useful when the dict is used as a multi-hash.
81 * If an empty list is returned, no matching entry exists.
82 * Otherwise, the offset of the matching entries are returned.
84 * NOTE: It is not guaranteed that each entry is
85 * indeed among the ones you were looking for.
86 * After loading each entry you should check that it
87 * indeed matches the search key.
89 QList<int> findMultiString(const QString &key ) const;
91 /**
92 * The number of entries in the dictionary.
94 * Only valid when building the database.
96 uint count();
98 /**
99 * Reset the dictionary.
101 * Only valid when building the database.
103 void clear();
106 * Save the dictionary to the stream
107 * A reasonable fast hash algorithm will be created.
109 * Typically this will find 90% of the entries directly.
110 * Average hash table size: nrOfItems * 20 bytes.
111 * Average duplicate list size: nrOfItms * avgKeyLength / 5.
113 * Unknown keys have an average 20% chance to give a false hit.
114 * (That's why your program should check the result)
116 * Example:
117 * Assume 1000 items with an average key length of 60 bytes.
119 * Approx. 900 items will hash directly to the right entry.
120 * Approx. 100 items require a lookup in the duplicate list.
122 * The hash table size will be approx. 20Kb.
123 * The duplicate list size will be approx. 12Kb.
125 void save(QDataStream &str);
127 private:
128 Q_DISABLE_COPY(KSycocaDict)
129 class Private;
130 Private* d;
133 #endif