Anonymous user
Verify distribution uniformity/Naive: Difference between revisions
Verify distribution uniformity/Naive (view source)
Revision as of 11:01, 11 August 2009
, 14 years ago→{{header|C}}: it was a banal *value++ instead of ++*value or similar ;) however, rewritten to avoid the use of two hashes
(→{{header|C}}: it was a banal *value++ instead of ++*value or similar ;) however, rewritten to avoid the use of two hashes) |
|||
Line 19:
=={{header|C}}==
{{libheader|Judy}}
<lang c>#include <stdio.h>
Line 33 ⟶ 31:
Pvoid_t h = (Pvoid_t) NULL;
PWord_t value;
PWord_t element;
Word_t i;
int
// populate hashes
▲ for(i=0, j=0; i < n; i++) {
int rn = dist();
JLG(value, h, rn);▼
j++;▼
JLI(value, h, rn);
}
JLC(h_length, h, 0, -1);
double target = 1.0 * n / (double)h_length;
while(element != NULL) {
▲ if ( abs(v - target) > 0.01*n*D ) {
fprintf(stderr, "distribution potentially skewed for '%d': expected '%d', got '%d'\n",
return false; // bad distr.
}
}
JudyLFreeArray(&h, PJE0);
return true; // distr. ok
}
int main()
{
distcheck(
return 0;
}</lang>
|