stringhash.h 1.33 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/**
 * Copyright (C) 2003-2004 Scott Wheeler <wheeler@kde.org>
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */
16 17 18 19

#ifndef STRINGHASH_H
#define STRINGHASH_H

20
#include <QSet>
21

22 23 24
/**
 * A simple hash representing an (un-mapped) set of data.
 */
25
template <class T> class Hash : public QSet<T>
26
{
27
public:
28 29
    /**
     * To combine two operations into one (that takes the same amount as each
Yuri Chornoivan's avatar
Yuri Chornoivan committed
30
     * independently) this inserts an item and returns true if the item was
31 32
     * already in the set or false if it did not.
     */
33
    inline bool insert(const T &value)
34
    {
35
        if(this->contains(value))
36 37 38
            return true;
        QSet<T>::insert(value);
        return false;
39
    }
40 41
};

42
typedef Hash<QString> StringHash;
43

44
#endif
45 46

// vim: set et sw=4 tw=0 sta: