COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
coHashIter.h
Go to the documentation of this file.
1 /* This file is part of COVISE.
2 
3  You can use it under the terms of the GNU Lesser General Public License
4  version 2.1 or later, see lgpl-2.1.txt.
5 
6  * License: LGPL 2+ */
7 
8 #ifndef _CO_HASH_ITER_H_
9 #define _CO_HASH_ITER_H_
10 
11 #include "coMultiHashBase.h"
12 
13 #include <stdlib.h>
14 
15 #ifndef INLINE
16 #define INLINE inline
17 #endif
18 
19 namespace covise
20 {
21 
22 template <class KEY, class DATA>
24 
25 template <class KEY, class DATA>
26 class coHash;
27 
33 template <class KEY, class DATA>
35 {
36 
37  friend class coMultiHash<KEY, DATA>;
38  friend class coHash<KEY, DATA>;
39 
40 public:
42  coHashIter();
43 
46 
49  unsigned long hash);
50 
51  // Copy-Constructor: use default bitcopy
52  // coHashIter(const coHashIter<KEY,DATA> &);
53 
54  // Assignment operator: use default bitcopy
55  // coHashIter &operator =(const coHashIter<KEY,DATA> &);
56 
58  void reset();
59 
61  operator bool();
62 
64  void operator++();
65 
67  DATA &operator()();
68 
70  KEY key();
71 
73  unsigned long hash();
74 
75 private:
76  // pointer to 'my' hashtable
78 
79  // index of the actual element (if running on indices)
80  unsigned long d_index;
81 
82  // actual hash (if running on hashes) (=index+1)
83  unsigned long d_hashIndex;
84 };
85 
86 #define HT_EMPTY coMultiHashBase<KEY, DATA>::EMPTY
87 #define HT_PREVIOUS coMultiHashBase<KEY, DATA>::PREVIOUD
88 #define HT_USED coMultiHashBase<KEY, DATA>::USED
89 
90 // Empty constructor
91 template <class KEY, class DATA>
93 {
94  d_hash = NULL;
95 }
96 
97 // Initialize for sequential access
98 template <class KEY, class DATA>
100 {
101  d_index = 0;
102  d_hashIndex = 0;
103  d_hash = &hash;
104  while ((d_index < d_hash->size) && (d_hash->entryFlags[d_index] != HT_USED))
105  d_index++;
106 }
107 
108 // Initialize to first Element of hash series
109 template <class KEY, class DATA>
111  unsigned long hashIndex)
112 {
113  d_index = hashIndex - 1;
114  d_hashIndex = hashIndex;
115  d_hash = &hash;
116 }
117 
118 // test correctness
119 template <class KEY, class DATA>
121 {
122  return ((d_hash)
123  && (d_index < d_hash->size)
124  && (d_hash->entryFlags[d_index] == HT_USED));
125 }
126 
127 template <class KEY, class DATA>
129 {
130  //static const char flag[3]={'E','P','U'};
131  // running on hashes
132  if (d_hashIndex)
133  {
134  //cerr << " call d_hash->nextHash(" << d_hashIndex << ");" << endl;
135  //for (unsigned long i=0;i<d_hash->size;i++) {
136  // cerr.width(4);
137  // cerr << i << " :" << flag[d_hash->entryFlags[i]]
138  // << " : ";
139  // if (d_hash->entryFlags[i]) {
140  // cerr.width(4);
141  // cerr << d_hash->keys[i] << " : " << d_hash->data[i];
142  // }
143  // cerr << endl;
144  // }
145  d_hashIndex = d_hash->nextHash(d_hashIndex);
146  d_index = d_hashIndex - 1;
147  // cerr << " call d_hash->nextHash() returned " << d_hashIndex << endl;
148  }
149  // running on indices
150  else
151  {
152  d_index++;
153  while ((d_index < d_hash->size) && (d_hash->entryFlags[d_index] != HT_USED))
154  d_index++;
155  }
156 }
157 
158 template <class KEY, class DATA>
160 {
161  assert((d_index < d_hash->size) && (d_hash->entryFlags[d_index] == HT_USED));
162  return d_hash->data[d_index];
163 }
164 
165 template <class KEY, class DATA>
167 {
168  if (!d_hash)
169  return;
170  d_index = 0;
171  d_hashIndex = 0;
172  while ((d_index < d_hash->size) && (d_hash->entryFlags[d_index] != HT_USED))
173  d_index++;
174 }
175 
176 template <class KEY, class DATA>
178 {
179  assert((d_index < d_hash->size) && (d_hash->entryFlags[d_index] == HT_USED));
180  return d_hash->keys[d_index];
181 }
182 
183 template <class KEY, class DATA>
185 {
186  return d_index;
187  //return d_hashIndex;
188 }
189 }
190 #undef HT_EMPTY
191 #undef HT_PREVIOUS
192 #undef HT_USED
193 #endif
coHashIter()
Empty HashIter.
Definition: coHashIter.h:92
#define HT_USED
Definition: coHashIter.h:88
unsigned long d_hashIndex
Definition: coHashIter.h:83
unsigned long hash()
Access: iter.hash() accesses hash value.
Definition: coHashIter.h:184
Definition: coHash.h:31
#define NULL
Definition: covise_list.h:22
void reset()
Initialize to first Element of hash.
Definition: coHashIter.h:166
GLsizeiptr size
Definition: khronos-glext.h:6610
Definition: coIntMultiHash.h:25
void operator++()
Increment.
Definition: coHashIter.h:128
coMultiHashBase< KEY, DATA > * d_hash
Definition: coHashIter.h:77
GLenum GLsizei GLenum GLenum const GLvoid * table
Definition: khronos-glext.h:6347
DATA & operator()()
Access: iter() accesses element.
Definition: coHashIter.h:159
Definition: coHashIter.h:23
unsigned long d_index
Definition: coHashIter.h:80
#define INLINE
Definition: coHashIter.h:16
Definition: coHashIter.h:34
KEY key()
Access: iter.key() accesses element key.
Definition: coHashIter.h:177