1 /* $XConsortium: HashTable.h /main/1 1996/07/29 16:52:57 cde-hp $ */
2 // Copyright (c) 1994 James Clark
3 // See the file COPYING for copying permission.
5 #ifndef HashTable_INCLUDED
6 #define HashTable_INCLUDED 1
9 #include "OwnerTable.h"
12 #include "HashTableItemBase.h"
15 namespace SP_NAMESPACE {
18 template<class K, class V>
19 class HashTableItem : public HashTableItemBase<K> {
21 HashTableItem(const K &k, const V &v);
22 HashTableItemBase<K> *copy() const;
26 template<class K, class V> class HashTableIter;
28 template<class K, class V>
32 void insert(const K &key, const V &value, Boolean replace = 1);
33 const V *lookup(const K &key) const {
34 HashTableItem<K, V> *tem = (HashTableItem<K, V> *)table_.lookup(key);
35 return tem ? &tem->value : 0;
37 size_t count() const { return table_.count(); }
39 CopyOwnerTable<HashTableItemBase<K>, K, Hash, HashTableKeyFunction<K> > table_;
40 friend class HashTableIter<K,V>;
43 template<class K, class V>
46 HashTableIter(const HashTable<K, V> &table) : iter_(table.table_) { }
47 Boolean next(const K *&key, const V *&value) {
48 HashTableItem<K, V> *p = (HashTableItem<K, V> *)iter_.next();
58 OwnerTableIter<HashTableItemBase<K>, K, Hash, HashTableKeyFunction<K> > iter_;
65 #endif /* not HashTable_INCLUDED */
67 #ifdef SP_DEFINE_TEMPLATES
68 #include "HashTable.C"