| 1 | /* |
| 2 | * permute.c -- a permutation generator for the query |
| 3 | * sequences in TPC-H and TPC-R |
| 4 | */ |
| 5 | |
| 6 | #ifdef TEST |
| 7 | #define DECLARER |
| 8 | #endif |
| 9 | #include "config.h" |
| 10 | #include "dss.h" |
| 11 | #ifdef TEST |
| 12 | #include <stdlib.h> |
| 13 | #if (defined(_POSIX_) || !defined(WIN32)) /* Change for Windows NT */ |
| 14 | #include <unistd.h> |
| 15 | #endif /* WIN32 */ |
| 16 | #include <ctype.h> |
| 17 | #include <errno.h> |
| 18 | #include <limits.h> |
| 19 | #include <math.h> |
| 20 | #include <signal.h> |
| 21 | #include <stdio.h> /* */ |
| 22 | #include <string.h> |
| 23 | #ifdef HP |
| 24 | #include <strings.h> |
| 25 | #endif |
| 26 | #if (defined(WIN32) && !defined(_POSIX_)) |
| 27 | #include <process.h> |
| 28 | #pragma warning(disable : 4201) |
| 29 | #pragma warning(disable : 4214) |
| 30 | #pragma warning(disable : 4514) |
| 31 | #define WIN32_LEAN_AND_MEAN |
| 32 | #define NOATOM |
| 33 | #define NOGDICAPMASKS |
| 34 | #define NOMETAFILE |
| 35 | #define NOMINMAX |
| 36 | #define NOMSG |
| 37 | #define NOOPENFILE |
| 38 | #define NORASTEROPS |
| 39 | #define NOSCROLL |
| 40 | #define NOSOUND |
| 41 | #define NOSYSMETRICS |
| 42 | #define NOTEXTMETRIC |
| 43 | #define NOWH |
| 44 | #define NOCOMM |
| 45 | #define NOKANJI |
| 46 | #define NOMCX |
| 47 | #include <windows.h> |
| 48 | #pragma warning(default : 4201) |
| 49 | #pragma warning(default : 4214) |
| 50 | #endif |
| 51 | #endif |
| 52 | |
| 53 | DSS_HUGE NextRand(DSS_HUGE seed); |
| 54 | void permute(long *set, int cnt, long stream); |
| 55 | void permute_dist(distribution *d, long stream); |
| 56 | long seed; |
| 57 | char *eol[2] = {" " , "}," }; |
| 58 | extern seed_t Seed[]; |
| 59 | #ifdef TEST |
| 60 | tdef tdefs = {NULL}; |
| 61 | #endif |
| 62 | |
| 63 | #define MAX_QUERY 22 |
| 64 | #define ITERATIONS 1000 |
| 65 | #define UNSET 0 |
| 66 | |
| 67 | void permute(long *a, int c, long s) { |
| 68 | int i; |
| 69 | static DSS_HUGE source; |
| 70 | static long temp; |
| 71 | |
| 72 | if (a != (long *)NULL) { |
| 73 | for (i = 0; i < c; i++) { |
| 74 | RANDOM(source, (long)i, (long)(c - 1), s); |
| 75 | temp = *(a + source); |
| 76 | *(a + source) = *(a + i); |
| 77 | *(a + i) = temp; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | void permute_dist(distribution *d, long stream) { |
| 85 | int i; |
| 86 | |
| 87 | if (d != NULL) { |
| 88 | if (d->permute == (long *)NULL) { |
| 89 | d->permute = (long *)malloc(sizeof(long) * DIST_SIZE(d)); |
| 90 | MALLOC_CHECK(d->permute); |
| 91 | } |
| 92 | for (i = 0; i < DIST_SIZE(d); i++) |
| 93 | *(d->permute + i) = i; |
| 94 | permute(d->permute, DIST_SIZE(d), stream); |
| 95 | } else |
| 96 | INTERNAL_ERROR("Bad call to permute_dist" ); |
| 97 | |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | #ifdef TEST |
| 102 | |
| 103 | int main(int ac, char *av[]) { |
| 104 | long *sequence, i, j, streams = UNSET, *a; |
| 105 | char sep; |
| 106 | int index = 0; |
| 107 | |
| 108 | set_seeds = 0; |
| 109 | sequence = (long *)malloc(MAX_QUERY * sizeof(long)); |
| 110 | a = sequence; |
| 111 | for (i = 0; i < MAX_QUERY; i++) |
| 112 | *(sequence + i) = i; |
| 113 | if (ac < 3) |
| 114 | goto usage; |
| 115 | Seed[0].value = (long)atoi(av[1]); |
| 116 | streams = atoi(av[2]); |
| 117 | if (Seed[0].value == UNSET || streams == UNSET) |
| 118 | goto usage; |
| 119 | |
| 120 | index = 0; |
| 121 | printf("long permutation[%d][%d] = {\n" , streams, MAX_QUERY); |
| 122 | for (j = 0; j < streams; j++) { |
| 123 | sep = '{'; |
| 124 | printf("%s\n" , eol[index]); |
| 125 | for (i = 0; i < MAX_QUERY; i++) { |
| 126 | printf("%c%2d" , sep, *permute(a, MAX_QUERY, 0) + 1); |
| 127 | a = (long *)NULL; |
| 128 | sep = ','; |
| 129 | } |
| 130 | a = sequence; |
| 131 | index = 1; |
| 132 | } |
| 133 | printf("}\n};\n" ); |
| 134 | return (0); |
| 135 | |
| 136 | usage: |
| 137 | printf("Usage: %s <seed> <streams>\n" , av[0]); |
| 138 | printf(" uses <seed> to start the generation of <streams> permutations of " |
| 139 | "[1..%d]\n" , |
| 140 | MAX_QUERY); |
| 141 | return (-1); |
| 142 | } |
| 143 | #endif /* TEST */ |
| 144 | |