1 /* IV.h */ 2 3 #include "../cfiles.h" 4 5 /*--------------------------------------------------------------------*/ 6 /* 7 --------------------------------------------------------- 8 IV -- integer vector object 9 10 size -- size of the vector 11 maxsize -- maximum size of the vector 12 owned -- owner flag 13 when == 1, storage pointed to by entries 14 has been allocated here and can be free'd. 15 when == 0, storage pointed to by entries 16 has not been allocated here and cannot be free'd. 17 vec -- pointer to base address 18 --------------------------------------------------------- 19 */ 20 typedef struct _IV IV ; 21 struct _IV { 22 int size ; 23 int maxsize ; 24 int owned ; 25 int *vec ; 26 } ; 27 /*--------------------------------------------------------------------*/ 28 /* 29 ------------------------------------------------------------------------ 30 ----- methods found in basics.c ---------------------------------------- 31 ------------------------------------------------------------------------ 32 */ 33 /* 34 ----------------------- 35 constructor method 36 37 created -- 95oct06, cca 38 ----------------------- 39 */ 40 IV * 41 IV_new ( 42 void 43 ) ; 44 /* 45 ----------------------- 46 set the default fields 47 48 created -- 95oct06, cca 49 ----------------------- 50 */ 51 void 52 IV_setDefaultFields ( 53 IV *iv 54 ) ; 55 /* 56 ----------------------- 57 clear the data fields 58 59 created -- 95oct06, cca 60 ----------------------- 61 */ 62 void 63 IV_clearData ( 64 IV *iv 65 ) ; 66 /* 67 ----------------------- 68 destructor 69 70 created -- 95oct06, cca 71 ----------------------- 72 */ 73 void 74 IV_free ( 75 IV *iv 76 ) ; 77 /*--------------------------------------------------------------------*/ 78 /* 79 ------------------------------------------------------------------------ 80 ----- methods found in init.c ---------------------------------------- 81 ------------------------------------------------------------------------ 82 */ 83 /* 84 --------------------------------------------- 85 simplest initialization method 86 87 if entries != NULL 88 the object does not own the entries, 89 it just points to the entries base address 90 else if size > 0 91 the object will own the entries, 92 it allocates a vector of size int's. 93 else 94 nothing happens 95 endif 96 97 created -- 96aug28, cca 98 --------------------------------------------- 99 */ 100 void 101 IV_init ( 102 IV *iv, 103 int size, 104 int *entries 105 ) ; 106 /* 107 ------------------------- 108 basic initializion method 109 110 created -- 95oct06, cca 111 ------------------------- 112 */ 113 void 114 IV_init1 ( 115 IV *iv, 116 int Maxsize 117 ) ; 118 /* 119 ------------------------- 120 total initializion method 121 122 created -- 95oct06, cca 123 ------------------------- 124 */ 125 void 126 IV_init2 ( 127 IV *iv, 128 int size, 129 int maxsize, 130 int owned, 131 int *vec 132 ) ; 133 /* 134 ---------------------------------- 135 set the maximum size of the vector 136 137 created -- 96dec08, cca 138 ---------------------------------- 139 */ 140 void 141 IV_setMaxsize ( 142 IV *iv, 143 int newmaxsize 144 ) ; 145 /* 146 -------------------------- 147 set the size of the vector 148 149 created -- 96dec08, cca 150 -------------------------- 151 */ 152 void 153 IV_setSize ( 154 IV *iv, 155 int newsize 156 ) ; 157 /*--------------------------------------------------------------------*/ 158 /* 159 ------------------------------------------------------------------------ 160 ----- methods found in instance.c -------------------------------------- 161 ------------------------------------------------------------------------ 162 */ 163 /* 164 --------------------------------------------------------------- 165 return value is 0 if the entries are not owned by the object 166 otherwise the return value is the number of entries at the base 167 storage of the vector 168 169 created -- 96jun22, cca 170 modified -- 96aug28, cca 171 --------------------------------------------------------------- 172 */ 173 int 174 IV_owned ( 175 IV *iv 176 ) ; 177 /* 178 ---------------------------------- 179 return the vector size and entries 180 181 created -- 95oct06, cca 182 ---------------------------------- 183 */ 184 int 185 IV_size ( 186 IV *iv 187 ) ; 188 /* 189 ------------------------------------- 190 return the maximum size of the vector 191 192 created -- 95dec08, cca 193 ------------------------------------- 194 */ 195 int 196 IV_maxsize ( 197 IV *iv 198 ) ; 199 /* 200 ------------------------------------------------ 201 return the loc'th entry of a vector. 202 note: if loc is out of range then -1 is returned 203 204 created -- 96jun29, cca 205 ------------------------------------------------ 206 */ 207 int 208 IV_entry ( 209 IV *iv, 210 int loc 211 ) ; 212 /* 213 ---------------------------------------------- 214 return a pointer to the object's entries array 215 216 created -- 95oct06, cca 217 ---------------------------------------------- 218 */ 219 int * 220 IV_entries ( 221 IV *iv 222 ) ; 223 /* 224 -------------------------------------------- 225 fill *psize with the vector's size 226 and *pentries with the address of the vector 227 228 created -- 95oct06, cca 229 -------------------------------------------- 230 */ 231 void 232 IV_sizeAndEntries ( 233 IV *iv, 234 int *psize, 235 int **pentries 236 ) ; 237 /* 238 -------------------------- 239 set the size of the vector 240 241 created -- 96jun22, cca 242 -------------------------- 243 */ 244 void 245 IV_setSize ( 246 IV *iv, 247 int Size 248 ) ; 249 /* 250 --------------------------- 251 set and entry in the vector 252 253 created -- 96jul14, cca 254 --------------------------- 255 */ 256 void 257 IV_setEntry ( 258 IV *iv, 259 int location, 260 int value 261 ) ; 262 /*--------------------------------------------------------------------*/ 263 /* 264 ------------------------------------------------------------------------ 265 ----- methods found in util.c ---------------------------------------- 266 ------------------------------------------------------------------------ 267 */ 268 /* 269 ----------------------------------------------------------- 270 shift the base of the entries and adjust the dimensions 271 note: this is a dangerous operation because the iv->vec 272 does not point to the base of the entries any longer, 273 and thus if the object owns its entries and it is called 274 to resize them or to free them, malloc and free will choke. 275 276 USE WITH CAUTION! 277 278 created -- 96aug25, cca 279 modified -- 96aug28, cca 280 structure changed 281 ----------------------------------------------------------- 282 */ 283 void 284 IV_shiftBase ( 285 IV *iv, 286 int offset 287 ) ; 288 /* 289 --------------------------- 290 push an entry onto the list 291 292 created -- 95oct06, cca 293 modified -- 95aug28, cca 294 structure has changed 295 --------------------------- 296 */ 297 void 298 IV_push ( 299 IV *iv, 300 int val 301 ) ; 302 /* 303 --------------------------- 304 minimum and maximum entries 305 306 created -- 95oct06, cca 307 --------------------------- 308 */ 309 int 310 IV_min ( 311 IV *iv 312 ) ; 313 int 314 IV_max ( 315 IV *iv 316 ) ; 317 int 318 IV_sum ( 319 IV *iv 320 ) ; 321 /* 322 ------------------------------------------------------- 323 sort each index list into ascending or descending order 324 325 created -- 95oct06, cca 326 ------------------------------------------------------- 327 */ 328 void 329 IV_sortUp ( 330 IV *iv 331 ) ; 332 void 333 IV_sortDown ( 334 IV *iv 335 ) ; 336 /* 337 ----------------------- 338 ramp the entries 339 340 created -- 95oct06, cca 341 ----------------------- 342 */ 343 void 344 IV_ramp ( 345 IV *iv, 346 int base, 347 int incr 348 ) ; 349 /* 350 ----------------------- 351 shuffle the list 352 353 created -- 95oct06, cca 354 ----------------------- 355 */ 356 void 357 IV_shuffle ( 358 IV *iv, 359 int seed 360 ) ; 361 /* 362 ---------------------------------------------- 363 return the number of bytes taken by the object 364 365 created -- 95oct06, cca 366 ---------------------------------------------- 367 */ 368 int 369 IV_sizeOf ( 370 IV *iv 371 ) ; 372 /* 373 ---------------------------------------------------------------- 374 keep entries that are tagged, move others to end and adjust size 375 376 created -- 95oct06, cca 377 ---------------------------------------------------------------- 378 */ 379 void 380 IV_filterKeep ( 381 IV *iv, 382 int tags[], 383 int keepTag 384 ) ; 385 /* 386 --------------------------------------------------------- 387 move purge entries that are tagged to end and adjust size 388 389 created -- 95oct06, cca 390 --------------------------------------------------------- 391 */ 392 void 393 IV_filterPurge ( 394 IV *iv, 395 int tags[], 396 int purgeTag 397 ) ; 398 /* 399 -------------------------------------------- 400 iterator : 401 return the pointer to the head of the vector 402 403 created -- 95oct06, cca 404 -------------------------------------------- 405 */ 406 int * 407 IV_first ( 408 IV *iv 409 ) ; 410 /* 411 ----------------------------------------------------- 412 iterator : 413 return the pointer to the next location in the vector 414 415 created -- 95oct06, cca 416 ----------------------------------------------------- 417 */ 418 int * 419 IV_next ( 420 IV *iv, 421 int *pi 422 ) ; 423 /* 424 -------------------------- 425 fill a vector with a value 426 427 created -- 96jun22, cca 428 -------------------------- 429 */ 430 void 431 IV_fill ( 432 IV *iv, 433 int value 434 ) ; 435 /* 436 -------------------------------------- 437 copy entries from iv2 into iv1. 438 note: this is a "mapped" copy, 439 iv1 and iv2 need not be the same size. 440 441 created -- 96aug31, cca 442 -------------------------------------- 443 */ 444 void 445 IV_copy ( 446 IV *iv1, 447 IV *iv2 448 ) ; 449 /* 450 -------------------------------------------------- 451 increment the loc'th location of the vector by one 452 and return the new value 453 454 created -- 96dec18, cca 455 -------------------------------------------------- 456 */ 457 int 458 IV_increment ( 459 IV *iv, 460 int loc 461 ) ; 462 /* 463 -------------------------------------------------- 464 decrement the loc'th location of the vector by one 465 and return the new value 466 467 created -- 96dec18, cca 468 -------------------------------------------------- 469 */ 470 int 471 IV_decrement ( 472 IV *iv, 473 int loc 474 ) ; 475 /* 476 ------------------------------------------------------------ 477 return the first location in the vector that contains value. 478 if value is not present, -1 is returned. cost is linear in 479 the size of the vector 480 481 created -- 96jan15, cca 482 ------------------------------------------------------------ 483 */ 484 int 485 IV_findValue ( 486 IV *iv, 487 int value 488 ) ; 489 /* 490 --------------------------------------------------------------- 491 return a location in the vector that contains value. 492 the entries in the vector are assumed to be in ascending order. 493 if value is not present, -1 is returned. cost is logarithmic in 494 the size of the vector 495 496 created -- 96jan15, cca 497 --------------------------------------------------------------- 498 */ 499 int 500 IV_findValueAscending ( 501 IV *iv, 502 int value 503 ) ; 504 /* 505 ---------------------------------------------------------------- 506 return a location in the vector that contains value. 507 the entries in the vector are assumed to be in descending order. 508 if value is not present, -1 is returned. cost is logarithmic in 509 the size of the vector 510 511 created -- 96jan15, cca 512 ---------------------------------------------------------------- 513 */ 514 int 515 IV_findValueDescending ( 516 IV *iv, 517 int value 518 ) ; 519 /* 520 --------------------------------------------------- 521 purpose -- return invlistIV, an IV object 522 that contains the inverse map, 523 i.e., invlist[list[ii]] = ii. 524 other entries of invlist[] are -1. 525 all entris in listIV must be nonnegative 526 527 created -- 98aug12, cca 528 --------------------------------------------------- 529 */ 530 IV * 531 IV_inverseMap ( 532 IV *listIV 533 ) ; 534 /* 535 ----------------------------------------------------------- 536 purpose -- return an IV object that contains the locations 537 of all instances of target in listIV. this is 538 used when listIV is a map from [0,n) to a finite 539 set (like processors) and we want to find all 540 entries that are mapped to a specific processor. 541 542 created -- 98aug12, cca 543 ----------------------------------------------------------- 544 */ 545 IV * 546 IV_targetEntries ( 547 IV *listIV, 548 int target 549 ) ; 550 /*--------------------------------------------------------------------*/ 551 /* 552 ------------------------------------------------------------------------ 553 ----- methods found in IO.c -------------------------------------------- 554 ------------------------------------------------------------------------ 555 */ 556 /* 557 ---------------------------------------------- 558 purpose -- to read in an IV object from a file 559 560 input -- 561 562 fn -- filename, must be *.ivb or *.ivf 563 564 return value -- 1 if success, 0 if failure 565 566 created -- 95oct06, cca 567 ---------------------------------------------- 568 */ 569 int 570 IV_readFromFile ( 571 IV *iv, 572 char *fn 573 ) ; 574 /* 575 ----------------------------------------------------- 576 purpose -- to read an IV object from a formatted file 577 578 return value -- 1 if success, 0 if failure 579 580 created -- 95oct06, cca 581 ----------------------------------------------------- 582 */ 583 int 584 IV_readFromFormattedFile ( 585 IV *iv, 586 FILE *fp 587 ) ; 588 /* 589 --------------------------------------------------- 590 purpose -- to read an IV object from a binary file 591 592 return value -- 1 if success, 0 if failure 593 594 created -- 95oct06, cca 595 --------------------------------------------------- 596 */ 597 int 598 IV_readFromBinaryFile ( 599 IV *iv, 600 FILE *fp 601 ) ; 602 /* 603 ------------------------------------------- 604 purpose -- to write an IV object to a file 605 606 input -- 607 608 fn -- filename 609 *.ivb -- binary 610 *.ivf -- formatted 611 anything else -- for human eye 612 613 return value -- 1 if success, 0 otherwise 614 615 created -- 95oct06, cca 616 ------------------------------------------- 617 */ 618 int 619 IV_writeToFile ( 620 IV *iv, 621 char *fn 622 ) ; 623 /* 624 ----------------------------------------------------- 625 purpose -- to write an IV object to a formatted file 626 627 return value -- 1 if success, 0 otherwise 628 629 created -- 95oct06, cca 630 ----------------------------------------------------- 631 */ 632 int 633 IV_writeToFormattedFile ( 634 IV *iv, 635 FILE *fp 636 ) ; 637 /* 638 -------------------------------------------------- 639 purpose -- to write an IV object to a binary file 640 641 return value -- 1 if success, 0 otherwise 642 643 created -- 95oct06, cca 644 -------------------------------------------------- 645 */ 646 int 647 IV_writeToBinaryFile ( 648 IV *iv, 649 FILE *fp 650 ) ; 651 /* 652 ------------------------------------------------- 653 purpose -- to write an IV object for a human eye 654 655 return value -- 1 if success, 0 otherwise 656 657 created -- 95oct06, cca 658 ------------------------------------------------- 659 */ 660 int 661 IV_writeForHumanEye ( 662 IV *iv, 663 FILE *fp 664 ) ; 665 /* 666 --------------------------------------------------------- 667 purpose -- to write out the statistics for the IV object 668 669 return value -- 1 if success, 0 otherwise 670 671 created -- 95oct06, cca 672 --------------------------------------------------------- 673 */ 674 int 675 IV_writeStats ( 676 IV *iv, 677 FILE *fp 678 ) ; 679 /* 680 ------------------------------------------------------------------- 681 purpose -- to write out an integer vector with eighty column lines 682 683 input -- 684 685 fp -- file pointer, must be formatted and write access 686 column -- present column 687 pierr -- pointer to int to hold return value, 688 should be 1 if any print was successful, 689 if fprintf() failed, then ierr = -1 690 691 return value -- present column 692 693 created -- 96jun22, cca 694 ------------------------------------------------------------------- 695 */ 696 int 697 IV_fp80 ( 698 IV *iv, 699 FILE *fp, 700 int column, 701 int *pierr 702 ) ; 703 /* 704 --------------------------------------------------- 705 purpose -- to write the IV object for a matlab file 706 707 return value -- 1 if success, 0 otherwise 708 709 created -- 98oct22, cca 710 --------------------------------------------------- 711 */ 712 int 713 IV_writeForMatlab ( 714 IV *iv, 715 char *name, 716 FILE *fp 717 ) ; 718 /*--------------------------------------------------------------------*/ 719