COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
coMultiHash.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_MULTI_HASH_H_
9 #define _CO_MULTI_HASH_H_
10 
11 // 27.02.98
12 
13 #include "coMultiHashBase.h"
14 
15 #include <assert.h>
16 
17 namespace covise
18 {
19 
20 template <class KEY, class DATA>
21 class coMultiHashBase;
22 
23 #ifndef INLINE
24 #define INLINE inline
25 #endif
26 
31 template <class KEY, class DATA>
32 class coMultiHash : protected coMultiHashBase<KEY, DATA>
33 {
34 
35 private:
38  {
39  assert(0);
40  }
41 
44  {
45  assert(0);
46  return *this;
47  }
48 
49 public:
52  : coMultiHashBase<KEY, DATA>()
53  {
54  }
55 
57  coMultiHash(DATA nullelem)
58  : coMultiHashBase<KEY, DATA>(nullelem)
59  {
60  }
61 
63  virtual ~coMultiHash()
64  {
65  }
66 
68  int insert(const KEY &key, const DATA &inData)
69  {
70  return coMultiHashBase<KEY, DATA>::insert(key, inData);
71  }
72 
74  //int remove(const coHashIter<KEY,DATA> &iter )
75  // { return coMultiHashBase<KEY,DATA>::remove(iter.d_hashIndex); }
76  // R.B. hash index not correct !!!
77  int remove(const coHashIter<KEY, DATA> &iter)
78  {
79  return coMultiHashBase<KEY, DATA>::remove(iter.d_index + 1);
80  }
81 
84  {
85  return coHashIter<KEY, DATA>(*this, getHash(key));
86  }
87 
90  {
91  return coHashIter<KEY, DATA>(*this);
92  }
93 
95  void clear()
96  {
97  this->removeAll();
98  }
99 
101  int getNumEntries() const
102  {
104  }
105 
107  const DATA &find(const KEY &key) const;
108 
110  unsigned long getHash(const KEY &key) const;
111 };
112 
113 template <class KEY, class DATA>
114 INLINE const DATA &coMultiHash<KEY, DATA>::find(const KEY &key) const
115 {
116  unsigned long hash = getHash(key);
117  if (hash)
118  return (*((const coMultiHashBase<KEY, DATA> *)(this)))[hash];
119  else
120  return this->getNullElem();
121 }
122 
123 template <class KEY, class DATA>
124 INLINE unsigned long coMultiHash<KEY, DATA>::getHash(const KEY &key) const
125 {
127 }
128 }
129 #endif
coMultiHash & operator=(const coMultiHash &)
Assignment operator: NOT IMPLEMENTED.
Definition: coMultiHash.h:43
unsigned long getHash(const KEY &key) const
get hash index, 0 if no element found
Definition: coMultiHash.h:124
#define INLINE
Definition: coMultiHash.h:24
int getNumEntries() const
get number of entries currently in hash
Definition: coMultiHashBase.h:434
int insert(const KEY &key, const DATA &inData)
insert an entry
Definition: coMultiHash.h:68
coMultiHash(const coMultiHash &)
Copy-Constructor: NOT IMPLEMENTED.
Definition: coMultiHash.h:37
int getNumEntries() const
get number of entries currently in hash
Definition: coMultiHash.h:101
virtual ~coMultiHash()
Destructor.
Definition: coMultiHash.h:63
void clear()
remove all elements
Definition: coMultiHash.h:95
coHashIter< KEY, DATA > operator[](const KEY &key)
get element
Definition: coMultiHash.h:83
unsigned long getHash(const KEY &key) const
get hash index, 0 if no element found
Definition: coMultiHashBase.h:358
void removeAll()
remove an entry by hashIndex
Definition: coMultiHashBase.h:228
Definition: coIntMultiHash.h:25
int remove(unsigned long hashIndex)
remove an entry by hashIndex
Definition: coMultiHashBase.h:339
virtual int insert(const KEY &key, const DATA &inData)
insert an entry (virtual for non-multi hash)
Definition: coMultiHashBase.h:305
coMultiHash(DATA nullelem)
Default constructor with NULL element.
Definition: coMultiHash.h:57
Definition: coHashIter.h:23
const DATA & find(const KEY &key) const
get element (only use with preset NULL element!!!)
Definition: coMultiHash.h:114
Definition: coHashIter.h:34
coHashIter< KEY, DATA > first()
get first to step through
Definition: coMultiHash.h:89
coMultiHash()
Default constructor.
Definition: coMultiHash.h:51