-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCHashTable.inl.h
158 lines (114 loc) · 4.22 KB
/
SCHashTable.inl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*-----------------------------------------------------------------------------+
| |
| SCL - Simulation Class Library |
| |
| (c) 1994-98 Marc Diefenbruch |
| University of Essen, Germany |
| |
+---------------+-------------------+---------------+-------------------+------+
| Module | File | Created | Project | |
+---------------+-------------------+---------------+-------------------+------+
| SCHashTable | SCHashTable.inl.h | 19. Nov 1997 | SCL | |
+---------------+-------------------+---------------+-------------------+------+
| |
| Change Log |
| |
| Nr. Date Description |
| ----- -------- ------------------------------------------------------ |
| 001 |
| 000 --.--.-- Neu angelegt |
| |
+-----------------------------------------------------------------------------*/
/* Lineal
00000000001111111111222222222233333333334444444444555555555566666666667777777777
01234567890123456789012345678901234567890123456789012345678901234567890123456789
*/
#ifndef __SCHASHTABLE_INL__
#define __SCHASHTABLE_INL__
#include <math.h>
#include "SCMem.h"
#if _SC_USE_STANDARD_BYTEORDER
#include <sys/types.h>
#include <netinet/in.h>
#endif
_SCINLINE_ SCNatural SCHashTable::GetNumOfAnalyzedStates(void) const
{
return analyzedStates;
}
_SCINLINE_ SCNatural SCHashTable::GetStateSpaceSize(void) const
{
return hashTableSize;
}
_SCINLINE_ SCNatural SCHashTable::GetTablePower(void) const
{
return hashTablePower;
}
_SCINLINE_ SCNatural SCHashTable::GetFunctionIndex(void) const
{
return hashFunctionIndex;
}
_SCINLINE_ SCInteger SCHashTable::GetCurrentKey(void) const
{
return m;
}
_SCINLINE_ void SCHashTable::CalcBasicHashKey (const SCMem *state)
{
m = -1;
h = state->save_area_size / sizeof(long); // Assumption: save_area is allocated
// to sizeof(long) boundaries.
#if _SC_VALIDATION_DEBUG >= 3
scValidationDebugLog << "SCHashTable::CalcBasicHashKey(): h (save area size) = " << h << std::endl;
#endif
q = (long *)state->save_area; // 4 Strukturbytes als
// long interpretieren
do
{
m += m;
if (m < 0)
{
m ^= z; // m = m XOR z (Bitwise XOR)
}
#if _SC_USE_STANDARD_BYTEORDER
m ^= htonl(*q++);
#else
m ^= *q++;
#endif
} while(--h > 0);
#if _SC_VALIDATION_DEBUG >= 3
scValidationDebugLog << "SCHashTable::CalcBasicHashKey(): m = " << m << std::endl;
#endif
}
_SCINLINE_ SCNatural SCHashTable::Holzmann1(const SCMem *state)
{
CalcBasicHashKey(state);
return (m ^ (m >> (32 - hashTablePower))) & hashMask;
}
_SCINLINE_ SCNatural SCHashTable::Holzmann2(const SCMem *state)
{
unsigned short pos;
register SCNatural hash_value;
CalcBasicHashKey(state);
pos = hashTablePower;
hash_value = m;
while (pos < 32)
{
hash_value ^= m >> pos;
pos += hashTablePower;
}
return hash_value &= hashMask;
}
_SCINLINE_ SCNatural SCHashTable::Multiply(const SCMem *state)
{
long double currentPhi = phi;
long double hashFactor;
CalcBasicHashKey(state);
currentPhi *= m;
hashFactor = currentPhi - floor(currentPhi);
return (SCNatural) floor(hashTableSize * hashFactor);
}
_SCINLINE_ SCNatural SCHashTable::Modulo(const SCMem *state)
{
CalcBasicHashKey(state);
return (m % primes[hashTablePower - 1]);
}
#endif // __SCHASHTABLE_INL__