-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCBitState.cpp
136 lines (103 loc) · 5.41 KB
/
SCBitState.cpp
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
/*-----------------------------------------------------------------------------+
| |
| SCL - Simulation Class Library |
| |
| (C) 1994-98 Marc Diefenbruch, Axel Hirche |
| University of Essen, Germany |
| |
+---------------+-------------------+---------------+-------------------+------+
| Module | File | Created | Project | |
+---------------+-------------------+---------------+-------------------+------+
| SCBitState | SCBitState.cc | 30. Apr 1996 | SCL | |
+---------------+-------------------+---------------+-------------------+------+
| |
| Change Log |
| |
| Nr. Date Description |
| ----- -------- ------------------------------------------------------ |
| 001 |
| 000 --.--.-- Neu angelegt |
| |
+-----------------------------------------------------------------------------*/
/* Lineal
00000000001111111111222222222233333333334444444444555555555566666666667777777777
01234567890123456789012345678901234567890123456789012345678901234567890123456789
*/
#include <stdlib.h>
#include "SCBitState.h"
#include "SCMem.h"
#include "SCDebug.h"
#include "SCStream.h"
#include "SCScheduler.h"
#if _SC_DMALLOC
#include <dmalloc.h>
#endif
SCBitState::SCBitState (SCNatural hashTablePow,
SCNatural hashFuncIndex,
const SCObject * father):
SCHashTable(scBitStateSpace, hashTablePow, hashFuncIndex, father)
{
assert(hashTablePow >= 3);
do
{
/* Groesse der Hash-Tabelle */
/* 2^hash_table_pow */
hashTableSize = (1L << hashTablePow);
hashTable = (char *) calloc(hashTableSize / 8, 1);
/* allocate memory */
/* divide by 8 because each */
/* byte can store 8 hash */
/* addresses */
}
while ((hashTable == NULL) && ((hashTablePow)-- >= 3));
// Not enough memory. Try to
// reduce the size of the hashtable.
assert(hashTable);
hashTablePower = hashTablePow;
hashMask = (1L << hashTablePower) - 1; // Set mask for hashfunctions.
#if _SC_VALIDATION_DEBUG >= 3
scValidationDebugLog << "SCBitState::SCBitstate(): hashTablePow = " << hashTablePow << std::endl;
scValidationDebugLog << "SCBitState::SCBitstate(): hashTableSize = " << hashTableSize << std::endl;
scValidationDebugLog << "SCBitState::SCBitstate(): hashMask = " << hashMask << std::endl;
#endif
}
SCBitState::~SCBitState (void)
{
free(hashTable); // Deallocate memory for hashtable.
}
SCBoolean SCBitState::IsStateAnalyzed(SCMem *state)
{
register SCBoolean result; // Temporary for result.
register SCNatural hash_value = (this->*hashFunction)(state); // Calculate hash value.
result = hashTable[hash_value >> 3] & (1 << (hash_value & 7L));
// Extract bit at position hash_value.
hashTable[hash_value >> 3] |= (1 << (hash_value & 7L));
// Set bit at position hash_value.
if (!result)
{
analyzedStates++; // Increment counter.
#if _SC_SHOW_PROGRESS
if (!(analyzedStates % _SC_PROGRESS_STEP)) { SCScheduler::outputStream << "#"; SCScheduler::outputStream.GetStream().flush(); }
#endif
}
#if _SC_VALIDATION_DEBUG >= 3
scValidationDebugLog << "SCBitState::IsStateAnalyzed(): hash_value = " << hash_value << std::endl;
scValidationDebugLog << "SCBitState::IsStateAnalyzed(): table index: hash_value >> 3 = " << (hash_value >> 3) << std::endl;
scValidationDebugLog << "SCBitState::IsStateAnalyzed(): hash value lower bits: hash_value & 7L = " << (hash_value & 7L) << std::endl;
scValidationDebugLog << "SCBitState::IsStateAnalyzed(): table bit: 1 << (hash_value & 7L) = " << (1 << (hash_value & 7L)) << std::endl;
scValidationDebugLog << "SCBitState::IsStateAnalyzed(): result = " << (!result? 0:1) << std::endl;
#endif
return(result);
}
SCStream& operator<< (SCStream& pStream,
const SCBitState& pData)
{
return pData.Display(pStream); // virtuelle Funktion aufrufen
}
SCStream& SCBitState::Display (SCStream& pStream) const
{
pStream << "Double states: avoided by bit-state hashing";
pStream << std::endl;
SCHashTable::Display(pStream);
return pStream;
}