Changeset 9730 for trunk/psLib/src/types
- Timestamp:
- Oct 24, 2006, 12:55:05 PM (20 years ago)
- Location:
- trunk/psLib/src/types
- Files:
-
- 7 edited
-
psArray.c (modified) (3 diffs)
-
psArray.h (modified) (3 diffs)
-
psHash.c (modified) (2 diffs)
-
psList.c (modified) (4 diffs)
-
psLookupTable.c (modified) (5 diffs)
-
psMetadataConfig.c (modified) (8 diffs)
-
psMetadataConfig.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psArray.c
r9543 r9730 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1.5 6$ $Name: not supported by cvs2svn $12 * @date $Date: 2006-10- 13 22:24:29$11 * @version $Revision: 1.57 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2006-10-24 22:52:56 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 49 49 } 50 50 51 // Allocate an array, deliberately leave size unset. 52 static psArray *arrayAlloc(long nalloc) 53 { 54 if (nalloc < 0) { 55 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 56 "Can't allocate a psArray of negative size."); 57 return NULL; 58 } 59 60 // Create vector struct 61 psArray *array = (psArray*)psAlloc(sizeof(psArray)); 62 psMemSetDeallocator(array, (psFreeFunc)arrayFree); 63 64 P_PSARRAY_SET_NALLOC(array, nalloc); 65 // Create vector data array 66 array->data = psAlloc(nalloc * sizeof(psPtr)); 67 memset(array->data, 0, sizeof(void*) * nalloc); //set the initial values of data to NULL 68 69 return array; 70 } 51 71 52 72 /***************************************************************************** … … 55 75 psArray* psArrayAlloc(long nalloc) 56 76 { 57 if (nalloc < 0) { 58 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 59 "Can't allocate a psArray of negative size."); 60 return NULL; 61 } 62 psArray* psArr = NULL; 63 64 // Create vector struct 65 psArr = (psArray* ) psAlloc(sizeof(psArray)); 66 psMemSetDeallocator(psArr, (psFreeFunc) arrayFree); 67 68 P_PSARRAY_SET_NALLOC(psArr,nalloc); 69 psArr->n = 0; //set the initial number of elements in use to 0 70 // Create vector data array 71 psArr->data = psAlloc(nalloc * sizeof(psPtr)); 72 memset(psArr->data, 0, sizeof(void*) * nalloc); //set the initial values of data to NULL 73 74 return psArr; 77 psArray *array = arrayAlloc(nalloc); 78 if (!array) { 79 return NULL; 80 } 81 array->n = nalloc; 82 return array; 83 } 84 85 psArray* psArrayAllocEmpty(long nalloc) 86 { 87 psArray *array = arrayAlloc(nalloc); 88 if (!array) { 89 return NULL; 90 } 91 array->n = 0; 92 return array; 75 93 } 76 94 -
trunk/psLib/src/types/psArray.h
r9543 r9730 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.4 2$ $Name: not supported by cvs2svn $14 * @date $Date: 2006-10- 13 22:24:29$13 * @version $Revision: 1.43 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2006-10-24 22:52:56 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 60 60 61 61 62 /** Allocate an array .62 /** Allocate an array, set the length to the number of allocated elements 63 63 * 64 64 * Uses psLib memory allocation functions to create an array collection of … … 69 69 */ 70 70 psArray* psArrayAlloc( 71 long nalloc ///< Total number of elements to make available. 72 ); 73 74 /** Allocate an array, set the length to zero. 75 * 76 * Uses psLib memory allocation functions to create an array collection of 77 * data 78 * 79 * @return psArray* : Pointer to psArray. 80 * 81 */ 82 psArray* psArrayAllocEmpty( 71 83 long nalloc ///< Total number of elements to make available. 72 84 ); -
trunk/psLib/src/types/psHash.c
r9538 r9730 12 12 * @author GLG, MHPCC 13 13 * 14 * @version $Revision: 1.3 4$ $Name: not supported by cvs2svn $15 * @date $Date: 2006-10- 13 21:13:48$14 * @version $Revision: 1.35 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2006-10-24 22:52:56 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 433 433 434 434 psArray* result = psArrayAlloc(nElements); 435 result->n = nElements;436 435 437 436 // now fill in the array with the hash hash's data -
trunk/psLib/src/types/psList.c
r9538 r9730 6 6 * @author Robert Daniel DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1.5 5$ $Name: not supported by cvs2svn $9 * @date $Date: 2006-10- 13 21:13:48$8 * @version $Revision: 1.56 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-10-24 22:52:56 $ 10 10 * 11 11 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 25 25 #define ITER_INIT_HEAD ((psPtr )1) // next iteration should return head 26 26 #define ITER_INIT_TAIL ((psPtr )2) // next iteration should return tail 27 28 #define INITIAL_NUM_ITERATORS 16 // Initial number of iterators to create 27 29 28 30 // private functions. … … 125 127 list->n = 0; 126 128 list->head = list->tail = NULL; 127 list->iterators = psArrayAlloc(16); 128 list->iterators->n = 0; 129 list->iterators = psArrayAllocEmpty(INITIAL_NUM_ITERATORS); 129 130 130 131 // create a default iterator … … 564 565 psArray* psListToArray(const psList* list) 565 566 { 566 psListElem* ptr; 567 psU32 n; 568 psArray* arr; 569 570 if (list == NULL) { 571 return NULL; 572 } 573 574 //XXX: Following is unnecessary as a list->n = 0 should do ArrayAlloc(0) I believe. 575 /* if (list->n > 0) { 576 arr = psArrayAlloc(list->n); 577 } else { 578 arr = psArrayAlloc(1); 579 } 580 */ 581 arr = psArrayAlloc(list->n); 582 arr->n = list->n; 583 584 ptr = list->head; 585 n = list->n; 567 PS_ASSERT_PTR_NON_NULL(list, NULL); 568 569 long n = list->n; 570 psArray *arr = psArrayAlloc(n); 571 572 psListElem *ptr = list->head; 586 573 for (psS32 i = 0; i < n; i++) { 587 574 arr->data[i] = psMemIncrRefCounter(ptr->data); -
trunk/psLib/src/types/psLookupTable.c
r9715 r9730 7 7 * @author Ross Harman, MHPCC 8 8 * 9 * @version $Revision: 1.4 2$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-10-2 2 00:51:05$9 * @version $Revision: 1.43 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-10-24 22:52:56 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii … … 36 36 #define MAX_STRING_LENGTH 256 37 37 #define ARRAY_STRIDE 16 38 38 #define INITIAL_NUM 10 // Initial number of elements 39 39 /******************************************************************************/ 40 40 /* TYPE DEFINITIONS */ … … 449 449 450 450 // Create output array and set array elements to zero 451 outputArray = psArrayAlloc(10); 452 outputArray->n = 0; 451 outputArray = psArrayAllocEmpty(INITIAL_NUM); 453 452 454 453 // Parse the format string to determine how many vectors … … 629 628 // Check if array is sorted on the index column 630 629 psVector* sortedIndex = psVectorAlloc(numRows,PS_TYPE_U32); 631 sortedIndex->n = numRows;632 630 sortedIndex = psVectorSortIndex(sortedIndex,indexColumnVector); 633 631 for(psS32 i = 0; i < numRows; i++ ) { … … 645 643 psS32 type = ((psVector*)(vectors->data[j]))->type.type; 646 644 newValueArray->data[j] = psVectorAlloc(numRows,type); 647 ((psVector*)(newValueArray->data[j]))->n = numRows;648 newValueArray->n++;649 645 } 650 646 -
trunk/psLib/src/types/psMetadataConfig.c
r9720 r9730 10 10 * @author Eric Van Alst, MHPCC 11 11 * 12 * @version $Revision: 1.9 5$ $Name: not supported by cvs2svn $13 * @date $Date: 2006-10-24 01:15:47$12 * @version $Revision: 1.96 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-10-24 22:52:56 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 47 47 /** Maximum size of a string */ 48 48 #define MAX_STRING_LENGTH 1024 49 #define INITIAL_LENGTH 10 // Initial length for arrays 49 50 50 51 /******************************************************************************/ … … 73 74 static psMetadata* setMetadataItem(psMetadata* template, char* linePtr) 74 75 ; 75 static void parseLevelInfoFree(p_psParseLevelInfo* info); 76 static psBool parseLine(psS32* level, psArray* levelArray, char* linePtr, psS32 lineCount, psBool overwrite); 77 static psBool parseMetadataItem(char* keyName, psS32* level, psArray* levelArray, char* linePtr, psS32 lineCount, psMetadataFlags flags); 76 static psBool parseLine(psS32* level, psArray* levelArray, char* linePtr, 77 psS32 lineCount, psBool overwrite); 78 static psBool parseMetadataItem(char* keyName, psS32* level, psArray* levelArray, 79 char* linePtr, psS32 lineCount, psMetadataFlags flags); 78 80 static psString formatMetadataItem(psMetadataItem *item); 79 81 static psArray *p_psMetadataKeyArray(psMetadata *md); 82 83 84 // A metadata data structure used in parsing arrays. 85 // Contains array information and the metadata storage location. 86 typedef struct 87 { 88 psArray* nonUniqueKeyArray; ///< non-unique key names 89 psArray* typeArray; ///< array of user defined types 90 psArray* templateArray; ///< array of user type templates 91 psMetadata* metadata; ///< metadata container 92 char* name; ///< name of key 93 } 94 p_psParseLevelInfo; 95 80 96 static void parseLevelInfoFree(p_psParseLevelInfo* info) 81 97 { … … 85 101 psFree(info->name); 86 102 psFree(info->metadata); 103 } 104 105 static p_psParseLevelInfo* p_psParseLevelInfoAlloc(void) 106 { 107 // Allocate memory for parse level info 108 p_psParseLevelInfo *info = (p_psParseLevelInfo*)psAlloc(sizeof(p_psParseLevelInfo)); 109 psMemSetDeallocator(info,(psFreeFunc)parseLevelInfoFree); 110 111 info->nonUniqueKeyArray = psArrayAllocEmpty(INITIAL_LENGTH); 112 info->typeArray = psArrayAllocEmpty(INITIAL_LENGTH); 113 info->templateArray = psArrayAllocEmpty(INITIAL_LENGTH); 114 info->metadata = NULL; 115 info->name = NULL; 116 117 return info; 87 118 } 88 119 … … 350 381 inString = saveValue; 351 382 end = NULL; 352 vec = psVectorAlloc (numValues, elemType);383 vec = psVectorAllocEmpty(numValues, elemType); 353 384 354 385 while(*inString!='\0') { … … 406 437 } 407 438 439 408 440 /*****************************************************************************/ 409 441 /* FUNCTION IMPLEMENTATION - PUBLIC */ 410 442 /*****************************************************************************/ 411 412 p_psParseLevelInfo* p_psParseLevelInfoAlloc(void)413 {414 415 p_psParseLevelInfo* info = NULL;416 417 // Allocate memory for parse level info418 info = (p_psParseLevelInfo*)psAlloc(sizeof(p_psParseLevelInfo));419 420 // If allocation successful then initialize members421 if(info != NULL) {422 423 info->nonUniqueKeyArray = psArrayAlloc(10);424 425 info->typeArray = psArrayAlloc(10);426 427 info->templateArray = psArrayAlloc(10);428 429 info->metadata = NULL;430 info->name = NULL;431 432 // Set memory deallocator433 psMemSetDeallocator(info,(psFreeFunc)parseLevelInfoFree);434 }435 return info;436 }437 443 438 444 bool psMetadataItemPrint(FILE * fd, … … 1220 1226 1221 1227 // Allocate array to store parse level information 1222 parseLevelInfoArray = psArrayAlloc (10);1228 parseLevelInfoArray = psArrayAllocEmpty(INITIAL_LENGTH); 1223 1229 1224 1230 // Set parse level info for the top level … … 1522 1528 PS_ASSERT_PTR_NON_NULL(md, NULL); 1523 1529 1524 psArray *keys = psArrayAlloc (psListLength(md->list));1530 psArray *keys = psArrayAllocEmpty(psListLength(md->list)); 1525 1531 1526 1532 // since we want to preserve the order of the keys in the metadata we can't -
trunk/psLib/src/types/psMetadataConfig.h
r9720 r9730 10 10 * @author Robert DeSonia, MHPCC 11 11 * 12 * @version $Revision: 1.2 4$ $Name: not supported by cvs2svn $13 * @date $Date: 2006-10-24 01:15:47$12 * @version $Revision: 1.25 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-10-24 22:52:56 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 22 22 /// @addtogroup Metadata 23 23 /// @{ 24 25 /** A metadata data structure used in parsing arrays.26 *27 * Contains array information and the metadata storage location.28 */29 typedef struct30 {31 psArray* nonUniqueKeyArray; ///< non-unique key names32 psArray* typeArray; ///< array of user defined types33 psArray* templateArray; ///< array of user type templates34 psMetadata* metadata; ///< metadata container35 char* name; ///< name of key36 }37 p_psParseLevelInfo;38 39 /** Allocates a p_psParseLevelInfo structure40 *41 * @return p_psParseLevelInfo* : new p_psParseLevelInfo struct42 */43 p_psParseLevelInfo* p_psParseLevelInfoAlloc(void);44 24 45 25 /** Print metadata item to file.
Note:
See TracChangeset
for help on using the changeset viewer.
