COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
coHash.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_H_
9 #define _CO_HASH_H_
10 
11 // 27.02.98
12 
13 #include "coHashBase.h"
14 #include "coHashIter.h"
15 
16 #ifndef INLINE
17 #define INLINE inline
18 #endif
19 
20 namespace covise
21 {
22 
23 template <class KEY, class DATA>
24 class coHashBase;
25 
30 template <class KEY, class DATA>
31 class coHash : protected coHashBase<KEY, DATA>
32 {
33 
34 private:
36  coHash(const coHash &);
37 
39  coHash &operator=(const coHash &);
40 
41 public:
44  : coHashBase<KEY, DATA>(){};
45 
47  coHash(const DATA &nullelem)
48  : coHashBase<KEY, DATA>(nullelem){};
49 
51  virtual ~coHash(){};
52 
54  int insert(const KEY &key, const DATA &inData)
55  {
56  return coHashBase<KEY, DATA>::insert(key, inData);
57  }
58 
60  int remove(const coHashIter<KEY, DATA> &iter)
61  {
62  {
63  return coMultiHashBase<KEY, DATA>::remove(iter.d_hashIndex);
64  }
65  }
66 
69  {
70  return coHashIter<KEY, DATA>(*this, getHash(key));
71  }
72 
75  {
76  return coHashIter<KEY, DATA>(*this);
77  }
78 
80  void clear()
81  {
82  this->removeAll();
83  }
84 
86  int getNumEntries() const
87  {
89  }
90 
92  const DATA &find(const KEY &key) const;
93 
95  unsigned long getHash(const KEY &key) const;
96 };
97 
98 template <class KEY, class DATA>
99 INLINE const DATA &coHash<KEY, DATA>::find(const KEY &key) const
100 {
101  unsigned long hash = getHash(key);
102  if (hash)
103  return (*((const coHashBase<KEY, DATA> *)(this)))[hash];
104  else
105  return this->getNullElem();
106 }
107 
108 template <class KEY, class DATA>
109 INLINE unsigned long coHash<KEY, DATA>::getHash(const KEY &key) const
110 {
111  return coHashBase<KEY, DATA>::getHash(key);
112 }
113 }
114 #endif
coHash(const DATA &nullelem)
Default constructor with NULL element.
Definition: coHash.h:47
coHash & operator=(const coHash &)
Assignment operator: NOT IMPLEMENTED.
int getNumEntries() const
get number of entries currently in hash
Definition: coMultiHashBase.h:434
virtual ~coHash()
Destructor.
Definition: coHash.h:51
Definition: coHash.h:31
coHash()
Default constructor.
Definition: coHash.h:43
coHashIter< KEY, DATA > first()
get first to step through
Definition: coHash.h:74
unsigned long getHash(const KEY &key) const
get hash index, 0 if no element found
Definition: coMultiHashBase.h:358
void clear()
remove all elements
Definition: coHash.h:80
void removeAll()
remove an entry by hashIndex
Definition: coMultiHashBase.h:228
coHashIter< KEY, DATA > operator[](const KEY &key)
get element
Definition: coHash.h:68
int remove(unsigned long hashIndex)
remove an entry by hashIndex
Definition: coMultiHashBase.h:339
const DATA & find(const KEY &key) const
get element (only use with preset NULL element!!!)
Definition: coHash.h:99
int insert(const KEY &key, const DATA &inData)
insert an entry
Definition: coHash.h:54
Definition: coHashIter.h:34
int getNumEntries() const
get number of entries currently in hash
Definition: coHash.h:86
virtual int insert(const KEY &key, const DATA &inData)
insert: if existing element, replace it
Definition: coHashBase.h:59
unsigned long getHash(const KEY &key) const
get hash index, 0 if no element found
Definition: coHash.h:109
#define INLINE
Definition: coDLList.h:49
Definition: coHash.h:24