diff options
author | David <david@xagasoft.com> | 2011-04-04 19:57:40 +0000 |
---|---|---|
committer | David <david@xagasoft.com> | 2011-04-04 19:57:40 +0000 |
commit | f90231fc35f3405a276da0debfb7d83fffd0c44a (patch) | |
tree | c75a07b6ac5e21c24115794d4d5dc78e2d7bef97 /src | |
parent | 6ff23ac5097f7d92ac8840c2ba17d1dbf1eb80a5 (diff) | |
download | libbu++-f90231fc35f3405a276da0debfb7d83fffd0c44a.tar.gz libbu++-f90231fc35f3405a276da0debfb7d83fffd0c44a.tar.bz2 libbu++-f90231fc35f3405a276da0debfb7d83fffd0c44a.tar.xz libbu++-f90231fc35f3405a276da0debfb7d83fffd0c44a.zip |
david - tried to make hash crash
Diffstat (limited to 'src')
-rw-r--r-- | src/unit/hash.unit | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/src/unit/hash.unit b/src/unit/hash.unit index d2217e7..7148693 100644 --- a/src/unit/hash.unit +++ b/src/unit/hash.unit | |||
@@ -100,19 +100,69 @@ suite Hash | |||
100 | unitTest( !h3.isCoreShared( h ) ); | 100 | unitTest( !h3.isCoreShared( h ) ); |
101 | } | 101 | } |
102 | 102 | ||
103 | test reHashSpecial | ||
104 | { | ||
105 | IntStrHash hTest; | ||
106 | |||
107 | setStepCount( 1000000 ); | ||
108 | for( int i=0; i<1000000; ++i ) | ||
109 | { | ||
110 | char buf[40]; snprintf(buf,40,"num%d",i); | ||
111 | incProgress(); | ||
112 | |||
113 | if( ((double)random()/(double)RAND_MAX)<.01 ) | ||
114 | { | ||
115 | //printf("ERASE: %d (%s)\n",i%64,buf); | ||
116 | hTest.erase(i%64); | ||
117 | } | ||
118 | else | ||
119 | { | ||
120 | hTest[i%64]=buf; | ||
121 | } | ||
122 | |||
123 | /*printf("(%d) size: %u fill: %u cap:%u\n", | ||
124 | i, | ||
125 | hTest.getSize(), | ||
126 | hTest.getFill(), | ||
127 | hTest.getCapacity() | ||
128 | );*/ | ||
129 | } | ||
130 | } | ||
131 | |||
103 | test stress | 132 | test stress |
104 | { | 133 | { |
105 | srandom(time(NULL)); | 134 | srandom(time(NULL)); |
106 | 135 | ||
107 | IntStrHash hTest; | 136 | IntStrHash hTest; |
108 | setStepCount( 1000000 ); | 137 | IntStrHash hReUse; |
138 | setStepCount( 100000 ); | ||
109 | 139 | ||
110 | for( int i=0; i<1000000; ++i ) | 140 | for( int i=0; i<100000; ++i ) |
111 | { | 141 | { |
112 | char buf[40]; snprintf(buf,40,"num%d",i); | 142 | char buf[40]; snprintf(buf,40,"num%d",i); |
113 | hTest[i] = buf; | 143 | hTest[i] = buf; |
114 | incProgress(); | 144 | incProgress(); |
115 | 145 | ||
146 | |||
147 | if( ((double)random()/(double)RAND_MAX)<.01 ) | ||
148 | { | ||
149 | Bu::List<int> lKeys = hReUse.getKeys(); | ||
150 | Bu::List<int>::const_iterator it = lKeys.begin(); | ||
151 | int iIdx = (int)(((double)random()/(double)RAND_MAX) | ||
152 | *lKeys.getSize()); | ||
153 | for( int l=0; it; ++it, ++l ) | ||
154 | { | ||
155 | if( l==iIdx ) | ||
156 | { | ||
157 | int iVal = *it; | ||
158 | hReUse.erase( *it ); | ||
159 | char buf[40]; snprintf(buf,40,"num%d",iVal); | ||
160 | hTest[i] = buf; | ||
161 | //printf("re-use: %s\n",buf); | ||
162 | } | ||
163 | } | ||
164 | } | ||
165 | |||
116 | /*printf("(%s) size: %u fill: %u cap:%u\n", | 166 | /*printf("(%s) size: %u fill: %u cap:%u\n", |
117 | buf, | 167 | buf, |
118 | hTest.getSize(), | 168 | hTest.getSize(), |
@@ -129,7 +179,10 @@ suite Hash | |||
129 | for( int k=0; it; ++it, ++k ) | 179 | for( int k=0; it; ++it, ++k ) |
130 | { | 180 | { |
131 | if( k == iIdx ) | 181 | if( k == iIdx ) |
182 | { | ||
183 | hReUse.insert(*it,"yo"); | ||
132 | hTest.erase( *it ); | 184 | hTest.erase( *it ); |
185 | } | ||
133 | } | 186 | } |
134 | } | 187 | } |
135 | 188 | ||
@@ -146,6 +199,7 @@ suite Hash | |||
146 | { | 199 | { |
147 | if( k == iIdx ) | 200 | if( k == iIdx ) |
148 | { | 201 | { |
202 | hReUse.insert(*it,"yo"); | ||
149 | hTest.erase( *it ); | 203 | hTest.erase( *it ); |
150 | break; | 204 | break; |
151 | } | 205 | } |