2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: HashTable.h /main/1 1996/07/29 16:52:57 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
27 #ifndef HashTable_INCLUDED
28 #define HashTable_INCLUDED 1
31 #include "OwnerTable.h"
34 #include "HashTableItemBase.h"
37 namespace SP_NAMESPACE {
40 template<class K, class V>
41 class HashTableItem : public HashTableItemBase<K> {
43 HashTableItem(const K &k, const V &v);
44 HashTableItemBase<K> *copy() const;
48 template<class K, class V> class HashTableIter;
50 template<class K, class V>
54 void insert(const K &key, const V &value, Boolean replace = 1);
55 const V *lookup(const K &key) const {
56 HashTableItem<K, V> *tem = (HashTableItem<K, V> *)table_.lookup(key);
57 return tem ? &tem->value : 0;
59 size_t count() const { return table_.count(); }
61 CopyOwnerTable<HashTableItemBase<K>, K, Hash, HashTableKeyFunction<K> > table_;
62 friend class HashTableIter<K,V>;
65 template<class K, class V>
68 HashTableIter(const HashTable<K, V> &table) : iter_(table.table_) { }
69 Boolean next(const K *&key, const V *&value) {
70 HashTableItem<K, V> *p = (HashTableItem<K, V> *)iter_.next();
80 OwnerTableIter<HashTableItemBase<K>, K, Hash, HashTableKeyFunction<K> > iter_;
87 #endif /* not HashTable_INCLUDED */
89 #ifdef SP_DEFINE_TEMPLATES
90 #include "HashTable.C"