File size: 8,152 Bytes
d5062c8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
#ifndef RUNN_H
#define RUNN_H
#include <fstream>
#include <iostream>
#include <cctype>
#include <cstring>
#include <cstdlib>
using namespace std;
namespace iret {
const int word_cnt = 5000; //Maximum number of words in a document.
const int word_len = 1500; //Maximum word length.
const long max_str=1500; //Maximum string length.
int get_pathw(char *cn,const char *dfl,const char *dex,const char *a);
//Reads the path from a file "path_(*dfl)" and constructs the
//file name from as "(*dfl)_(*dex).(*a)". Cats path and file
//name and returns the full info in cn.
char *add_num(const char *ptr,long n,char *buf); //converts long to ascii
//and cats to end of string and returns pointer to new string
//that results. Does not change input string. The new string is
//held in buffer space and this is overwritten at each call.
int get_qflag();
//This function gets the value of the print flag pflag that is
//used to control output.
int mark(int,long,int,const char*);
//This function is used to print out information that indicates
//how a function is progressing. It is dependent on the value of
//pflag.
long gseed(int,char**,const char*);
//This function is called to allow the input of a seed value for
//the random number generator. It must be called in main or the
//arguments of main must be passed down to it if it is to allow
//command line entry. Otherwise the first argument may be set to
//zero and it may be used to enter the seed at run time from the
//console.
long clnga(int,char**,const char*,const char*);
//Allows a long to be entered from the console at run time if the
//first argument is set to zero. If the first two arguments are
//the arguments of main, then it allows command line entry with
//the flag that is the third argument and with a statement about
//the input that is the fourth argument.
double cdbla(int,char**,const char*,const char*);
char *cstra(int,char**,const char*,const char*);
long zrand(long);
//Produces a random long integer that is in the range [0,argument).
//Machinery of the random number generator.
void shuffle(long n,long *idx); //Randomly shuffles an array of longs.
void dshuffle(long n,long *idx); //Randomly shuffles an array of longs.
//Improved version suggested by Don Comeau
long rnd(double);
//Rounds off a double and returns the integer that results.
//Reads in a string including white space and ends the string
//just before the character a.
inline int get_string(char *cnam,ifstream &ifile,char a){
char *pch = cnam;
long j=1;
start:
if((*(pch++)=ifile.get())!=EOF){
if(*(pch-1)==a){pch--;goto start;}
while(((*(pch++)=ifile.get())!=a)&&(j<max_str))j++;
if(j<max_str){
*(--pch)='\0';
return(j);
}
else return(0);
}
return(0);
}
inline int get_strinf(char *cnam,fstream &ifile,char a){
char *pch = cnam;
long j=1;
if((*(pch++)=ifile.get())!=EOF){
while(((*(pch++)=ifile.get())!=a)&&(j<max_str))j++;
if(j<max_str){
*(--pch)='\0';
return(j);
}
else return(0);
}
return(0);
}
//Function to lower case a string.
inline void lower_case(char *cnam){
int i=0;
char ch;
while((ch=cnam[i])!='\0'){
cnam[i++]=tolower(ch);
}
}
//Note that ordering functions beginning with sS or hS
//produce an order that is increasing with increasing
//index, while sR or hR produces the reverse order.
template <class X>
void sSort(const long ix, X *idx){
long k, j, ir, i;
X rra;
if(ix<=1)return;
k=(ix>>1);
ir=ix-1;
for(;;) {
if(k>0) {
rra=idx[--k];
}
else {
rra=idx[ir];
idx[ir] = idx[0];
if(--ir ==0) {
idx[0]=rra;
return;
}
}
i=k;
j=((k+1)<<1)-1;
while(j<=ir) {
if(j<ir && (idx[j]<idx[j+1])) ++j;
if(rra<idx[j]) {
idx[i]=idx[j];
j +=(i=j)+1;
}
else j=ir+1;
}
idx[i]=rra;
}
}
template <class X>
void sRort(const long ix, X *idx){
long k, j, ir, i;
X rra;
if(ix<=1)return;
k=(ix>>1);
ir=ix-1;
for(;;) {
if(k>0) {
rra=idx[--k];
}
else {
rra=idx[ir];
idx[ir] = idx[0];
if(--ir ==0) {
idx[0]=rra;
return;
}
}
i=k;
j=((k+1)<<1)-1;
while(j<=ir) {
if(j<ir && (idx[j]>idx[j+1])) ++j;
if(rra>idx[j]) {
idx[i]=idx[j];
j +=(i=j)+1;
}
else j=ir+1;
}
idx[i]=rra;
}
}
template <class X, class Y>
void hSort(const long n, X *ra, Y *rb) {
long k, j, ir, i;
X rra;
Y rrb;
if(n<=1)return;
k=(n>>1);
ir=n-1;
for(;;) {
if(k>0) {
rra=ra[--k];
rrb=rb[k];
}
else {
rra=ra[ir];
rrb=rb[ir];
ra[ir] = ra[0];
rb[ir] = rb[0];
if(--ir ==0) {
ra[0]=rra;
rb[0]=rrb;
return;
}
}
i=k;
j=((k+1)<<1)-1;
while(j<=ir) {
if(j<ir && ra[j] < ra[j+1]) ++j;
if(rra<ra[j]) {
ra[i]=ra[j];
rb[i]=rb[j];
j +=(i=j)+1;
}
else j=ir+1;
}
ra[i]=rra;
rb[i]=rrb;
}
}
template <class X, class Y, class Z>
void hSort(const long n, X *ra, Y *rb, Z *rc) {
long k, j, ir, i;
X rra;
Y rrb;
Z rrc;
if(n<=1)return;
k=(n>>1);
ir=n-1;
for(;;) {
if(k>0) {
rra=ra[--k];
rrb=rb[k];
rrc=rc[k];
}
else {
rra=ra[ir];
rrb=rb[ir];
rrc=rc[ir];
ra[ir] = ra[0];
rb[ir] = rb[0];
rc[ir] = rc[0];
if(--ir ==0) {
ra[0]=rra;
rb[0]=rrb;
rc[0]=rrc;
return;
}
}
i=k;
j=((k+1)<<1)-1;
while(j<=ir) {
if(j<ir && ra[j] < ra[j+1]) ++j;
if(rra<ra[j]) {
ra[i]=ra[j];
rb[i]=rb[j];
rc[i]=rc[j];
j +=(i=j)+1;
}
else j=ir+1;
}
ra[i]=rra;
rb[i]=rrb;
rc[i]=rrc;
}
}
template <class X, class Y>
void hRort(const long n, X *ra, Y *rb) {
long k, j, ir, i;
X rra;
Y rrb;
if(n<=1)return;
k=(n>>1);
ir=n-1;
for(;;) {
if(k>0) {
rra=ra[--k];
rrb=rb[k];
}
else {
rra=ra[ir];
rrb=rb[ir];
ra[ir] = ra[0];
rb[ir] = rb[0];
if(--ir ==0) {
ra[0]=rra;
rb[0]=rrb;
return;
}
}
i=k;
j=((k+1)<<1)-1;
while(j<=ir) {
if(j<ir && ra[j] > ra[j+1]) ++j;
if(rra>ra[j]) {
ra[i]=ra[j];
rb[i]=rb[j];
j +=(i=j)+1;
}
else j=ir+1;
}
ra[i]=rra;
rb[i]=rrb;
}
}
template <class X, class Y, class Z>
void hRort(const long n, X *ra, Y *rb, Z *rc) {
long k, j, ir, i;
X rra;
Y rrb;
Z rrc;
if(n<=1)return;
k=(n>>1);
ir=n-1;
for(;;) {
if(k>0) {
rra=ra[--k];
rrb=rb[k];
rrc=rc[k];
}
else {
rra=ra[ir];
rrb=rb[ir];
rrc=rc[ir];
ra[ir] = ra[0];
rb[ir] = rb[0];
rc[ir] = rc[0];
if(--ir ==0) {
ra[0]=rra;
rb[0]=rrb;
rc[0]=rrc;
return;
}
}
i=k;
j=((k+1)<<1)-1;
while(j<=ir) {
if(j<ir && ra[j] > ra[j+1]) ++j;
if(rra>ra[j]) {
ra[i]=ra[j];
rb[i]=rb[j];
rc[i]=rc[j];
j +=(i=j)+1;
}
else j=ir+1;
}
ra[i]=rra;
rb[i]=rrb;
rc[i]=rrc;
}
}
//Function to convert a long to a null terminated string.
void long_str(char *cnam,long n);
//Function to convert a string with null termination
//to a long.
void str_long(char *cnam,long &n);
//Function to convert first two char of string to an
//integer. Should be an ASCII null terminated string
int trac(const char *str);
template<typename Y,typename Z>
void xshuffle(Y n,Z *idx){ //Randomly shuffles an array of longs.
Y i,k;
Z u;
for(i=n-1;i>0;i--){
k=(Y)zrand((long)i+1);
u=idx[i];
idx[i]=idx[k];
idx[k]=u;
}
}
template<class Z>
void dxhuffle(long n,Z *idx){ //Randomly shuffles an array type Z*.
long i,k;
Z xx;
for(i=n-1;i>0;i--){
k=zrand(i+1);
xx=idx[i];
idx[i]=idx[k];
idx[k]=xx;
}
}
}
#endif
|