Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / dti_cc / cc_hdict.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /* $XConsortium: cc_hdict.h /main/5 1996/08/21 15:49:02 drk $ */
24
25 #ifndef _cc_hdict_h
26 #define _cc_hdict_h 1
27
28 #include "dti_cc/types.h"
29 #include "dti_cc/cc_pvect.h"
30 #include "dti_cc/CC_Slist.h"
31
32 #include <iostream>
33 using namespace std;
34
35 template <class K, class V> 
36 class kv_pair {
37 public:
38
39    static CC_Boolean f_needRemove;
40
41    kv_pair(K* k, V* v = 0): f_key(k), f_value(v) {};
42    ~kv_pair();
43
44    unsigned int operator==(const kv_pair<K, V>&);
45
46 #ifdef DEBUG
47    ostream& print(ostream&);
48    friend ostream& operator<<(ostream& out, kv_pair<K, V>& kv) {
49      return kv.print(out);
50    }
51 #endif
52
53    K* f_key;
54    V* f_value;
55 };
56
57 #define DEFAULT_BUCKET_NUM 30
58    
59 template <class K, class V> class hashTableIterator;
60
61 template <class K, class V> class hashTable
62 {
63    //template <class K, class V> 
64    //friend class hashTableIterator;
65
66    friend class hashTableIterator<K, V>;
67
68 protected:
69    unsigned (*f_hash_func_ptr)(const K&);
70    pointer_vector<CC_TPtrSlist<kv_pair<K, V> > > f_buckets;
71    size_t f_items;
72
73 protected:
74    kv_pair<K, V>* _find(const K* k) const;
75
76 public:
77    hashTable(const hashTable <K,V> &);
78    hashTable(unsigned (*)(const K&), 
79              size_t init_bucket_num = DEFAULT_BUCKET_NUM
80             );
81    ~hashTable();
82
83    void clearAndDestroy();
84
85    size_t entries() { return f_items; };
86
87    CC_Boolean contains(const K*) const;
88
89    V* findValue(const K*) const;
90    K* findKeyAndValue(const K*, V*&) const;
91
92    void insertKeyAndValue(K*, V*);
93
94    K* remove(const K*);
95
96 #ifdef DEBUG
97    ostream& print(ostream& out);
98
99    friend ostream& operator<<(ostream& out, hashTable<K, V>& ht) {
100     return ht.print(out);
101    };
102 #endif
103
104 };
105
106 template <class K, class V> 
107 class hashTableIterator
108 {
109 protected:
110    size_t f_bucket_num;
111    size_t f_pos;
112    kv_pair<K, V>* f_rec;
113    hashTable<K, V>& f_hashTable;
114
115    CC_Boolean _findNonEmptyBucket();
116    CC_Boolean _findNextRecord();
117
118 public:
119    hashTableIterator(hashTable<K, V>&);
120    ~hashTableIterator();
121
122    CC_Boolean operator++();
123    K* key();
124    V* value() const;
125 };
126
127 #ifdef EXPAND_TEMPLATES
128 #include "cc_hdict.C"
129 #endif
130
131
132 #endif