COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
coIntMultiHash.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_INT_MULTI_HASH_H_
9 #define _CO_INT_MULTI_HASH_H_
10 
11 #include "coMultiHash.h"
12 
13 // 27.02.98
14 
15 // maximum of two values
16 namespace covise
17 {
18 
19 inline int Max(int v1, int v2)
20 {
21  return (v1 >= v2 ? v1 : v2);
22 }
23 
24 template <class KEY, class DATA>
26 
31 template <class DATA>
32 class coIntMultiHash : public coMultiHash<int, DATA>
33 {
34 
35 public:
36  // constructor with NULL element
37  coIntMultiHash(const DATA &nullelem)
38  : coMultiHash<int, DATA>(nullelem){};
39 
40  // constructor without NULL element
42  : coMultiHash<int, DATA>(){};
43 
44  // maximum key number in use
45  int getMaxKey() const;
46 
47 private:
49  virtual unsigned long hash1(const int &key) const
50  {
51  return (key % this->size);
52  }
53 
55  virtual unsigned long hash2(const int &key) const
56  {
57  return (this->size - 2 - key % (this->size - 2));
58  }
59 
61  virtual bool equal(const int &key1, const int &key2) const
62  {
63  return (key1 == key2);
64  }
65 };
66 
67 template <class DATA>
69 {
70  int maxKey;
71  int count = 0;
72  int first = 0;
73  unsigned int i;
74 
75  for (i = 0L; i < this->size; i++)
76  if (this->entryFlags[i] == this->USED)
77  {
78  count++;
79  if (count == 1)
80  first = this->keys[i];
81  }
82 
83  if (count == 0)
84  exit(-1); // R.B.: better exception throwing but not yet implemented
85 
86  // initialize
87  maxKey = first;
88 
89  for (i = 0L; i < this->size; i++)
90  if (this->entryFlags[i] == this->USED)
91  maxKey = Max(maxKey, this->keys[i]);
92 
93  return maxKey;
94 }
95 }
96 #endif
GLfloat GLfloat GLfloat v2
Definition: khronos-glext.h:6754
virtual unsigned long hash2(const int &key) const
2nd Hash function
Definition: coIntMultiHash.h:55
GLuint64EXT GLuint GLuint GLenum GLenum GLuint GLuint GLenum GLuint GLuint key1
Definition: khronos-glext.h:11877
GLuint GLuint GLsizei count
Definition: khronos-glext.h:6343
int getMaxKey() const
Definition: coIntMultiHash.h:68
GLsizeiptr size
Definition: khronos-glext.h:6610
Definition: coIntMultiHash.h:32
coIntMultiHash()
Definition: coIntMultiHash.h:41
Definition: coIntMultiHash.h:25
int Max(int v1, int v2)
Definition: coIntMultiHash.h:19
virtual bool equal(const int &key1, const int &key2) const
Equal function.
Definition: coIntMultiHash.h:61
Definition: coHashIter.h:23
virtual unsigned long hash1(const int &key) const
1st Hash function
Definition: coIntMultiHash.h:49
coIntMultiHash(const DATA &nullelem)
Definition: coIntMultiHash.h:37
const GLint * first
Definition: khronos-glext.h:6529
GLfloat GLfloat v1
Definition: khronos-glext.h:6753