Add very old versions (for history).
[opsoft_archive.git] / silentbob / silentbob-1.4 / gclib / unit_tests / hv.cxx
blobae5488c9582ba9aa07d30020669b85c7a560eae1
1 /*
2 * (c) Oleg Puchinin 2007
3 * graycardinalster@gmail.com
5 */
7 #include <gclib_c/gclib_c.h>
8 #include <gclib.h>
9 #include <hv.h>
11 int main (int argc, char ** argv)
13 HV * hash;
14 char d_key[512];
15 char d_value[512];
16 int i;
17 int rnd;
18 char *S;
20 hash = new HV;
22 printf ("Stage 1. Prepare.\n");
23 fflush (stdout);
24 Dtimer ();
25 hash->autosort (10000);
26 for (i = 0; i < 100000; ++i) {
27 sprintf (d_key, "_f%i", i);
28 sprintf (d_value, "_value%i", -i);
29 hash->set (d_key, d_value);
31 print_the_time (stdout);
32 fflush (stdout);
34 hash->sort ();
36 printf ("Stage 2. Access (100000 keys).\n");
37 fflush (stdout);
38 Dtimer ();
39 for (i = 0; i < 100000; ++i) {
40 rnd = rand () % 100000;
41 sprintf (d_key, "_f%i", rnd);
42 sprintf (d_value, "_value%i", -rnd);
43 S = hash->get (d_key);
44 if (! S) {
45 printf ("Hash test fail.\nKey not found (%s).\n", d_key);
46 return EXIT_FAILURE;
49 if (NE (S, d_value)) {
50 printf ("Hash test fail.\n");
51 printf ("%i hash[%s]\n", i, d_key);
52 return EXIT_FAILURE;
55 print_the_time (stdout);
56 fflush (stdout);
57 delete hash;