| 1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 4 |
> |
static char SCCSid[] = "$SunId$ SGI"; |
| 5 |
|
#endif |
| 6 |
|
|
| 7 |
|
/* |
| 14 |
|
|
| 15 |
|
extern char *malloc(); |
| 16 |
|
|
| 17 |
< |
short *urperm; /* urand() permutation */ |
| 17 |
> |
short *urperm = NULL; /* urand() permutation */ |
| 18 |
|
int urmask; /* bits used in permutation */ |
| 19 |
|
|
| 20 |
|
|
| 21 |
+ |
int |
| 22 |
|
initurand(size) /* initialize urand() for size entries */ |
| 23 |
|
int size; |
| 24 |
|
{ |
| 25 |
|
int order, n; |
| 26 |
|
register int i, offset; |
| 27 |
|
|
| 28 |
+ |
if (urperm != NULL) |
| 29 |
+ |
free((char *)urperm); |
| 30 |
|
size--; |
| 31 |
|
for (i = 1; size >>= 1; i++) |
| 32 |
|
; |
| 47 |
|
else |
| 48 |
|
urperm[i+offset]++; |
| 49 |
|
} |
| 50 |
+ |
return(1<<order); |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
|
| 63 |
|
while (n-- > 0) |
| 64 |
|
hval += *d++ * tab[n&7]; |
| 65 |
|
return(hval); |
| 62 |
– |
} |
| 63 |
– |
|
| 64 |
– |
|
| 65 |
– |
static char bctab[256] = { |
| 66 |
– |
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, |
| 67 |
– |
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, |
| 68 |
– |
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, |
| 69 |
– |
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, |
| 70 |
– |
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, |
| 71 |
– |
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, |
| 72 |
– |
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, |
| 73 |
– |
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, |
| 74 |
– |
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, |
| 75 |
– |
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, |
| 76 |
– |
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, |
| 77 |
– |
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, |
| 78 |
– |
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, |
| 79 |
– |
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, |
| 80 |
– |
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, |
| 81 |
– |
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, |
| 82 |
– |
}; |
| 83 |
– |
|
| 84 |
– |
|
| 85 |
– |
#define NBITS 32 |
| 86 |
– |
|
| 87 |
– |
#if NBITS==32 |
| 88 |
– |
#define bitcount(i) (bctab[(i)>>24&0xff]+bctab[(i)>>16&0xff]+ \ |
| 89 |
– |
bctab[(i)>>8&0xff]+bctab[(i)&0xff]) |
| 90 |
– |
#endif |
| 91 |
– |
#if NBITS==16 |
| 92 |
– |
#define bitcount(i) (bctab[(i)>>8&0xff]+bctab[(i)&0xff]) |
| 93 |
– |
#endif |
| 94 |
– |
|
| 95 |
– |
|
| 96 |
– |
int |
| 97 |
– |
urind(s, i) /* compute i'th index from seed s */ |
| 98 |
– |
int s, i; |
| 99 |
– |
{ |
| 100 |
– |
register int ss, k; |
| 101 |
– |
int left; |
| 102 |
– |
|
| 103 |
– |
ss = s*1103515245 + 12345; |
| 104 |
– |
left = 0; |
| 105 |
– |
for (k = i/NBITS; k--; ) { |
| 106 |
– |
left += bitcount(ss); |
| 107 |
– |
ss = ss*1103515245 + 12345; |
| 108 |
– |
} |
| 109 |
– |
for (k = i&(NBITS-1); k--; ss >>= 1) |
| 110 |
– |
left += ss & 1; |
| 111 |
– |
if (ss & 1) |
| 112 |
– |
return(s-left-1); |
| 113 |
– |
return(s-left+i); |
| 66 |
|
} |