Changeset 3407 for trunk/psLib/src/collections
- Timestamp:
- Mar 11, 2005, 10:38:56 AM (21 years ago)
- Location:
- trunk/psLib/src/collections
- Files:
-
- 4 edited
-
psMetadata.c (modified) (5 diffs)
-
psMetadata.h (modified) (3 diffs)
-
psVector.c (modified) (4 diffs)
-
psVector.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psMetadata.c
r3381 r3407 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.5 4$ $Name: not supported by cvs2svn $15 * @date $Date: 2005-03- 07 20:58:50$14 * @version $Revision: 1.55 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2005-03-11 20:38:56 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 67 67 /* FUNCTION IMPLEMENTATION - LOCAL */ 68 68 /*****************************************************************************/ 69 70 static psMetadataItem* makeMetaMulti(psHash* table, const char* key, psMetadataItem* existing) 71 { 72 73 if (existing != NULL && existing->type == PS_META_MULTI) { 74 return existing; 75 } 76 77 // move any existing entry into a psList 78 psList* newList = psListAlloc(existing); 79 80 psMetadataItem* item = psMetadataItemAlloc(key, 81 PS_META_MULTI, 82 "", 83 newList); 84 85 if (existing != NULL) { 86 psHashRemove(table,key); // take out the old entry 87 } 88 89 psHashAdd(table, key, item); // put in the new entry 90 91 // free local references of newly allocated items. 92 psFree(newList); 93 psFree(item); 94 95 return item; 96 } 69 97 70 98 static void metadataItemFree(psMetadataItem* metadataItem) … … 253 281 existingEntry = (psMetadataItem*)psHashLookup(mdTable, key); 254 282 255 // how the item is added to the hash depends on flags & prior existence 256 if(existingEntry != NULL) { 257 if ((flags & PS_META_DUPLICATE_OK) != 0) { 283 if (metadataItem->type == PS_META_MULTI) { 284 // the incoming entry is PS_META_MULTI 285 286 // force the hash entry to be PS_META_MULTI 287 existingEntry = makeMetaMulti(mdTable,key,existingEntry); 288 289 // add all the items in the incoming entry to metadata 290 psList* list = metadataItem->data.list; 291 if (list != NULL) { 292 psListIterator* iter = psListIteratorAlloc(list,PS_LIST_HEAD,true); 293 psMetadataItem* listItem; 294 while ((listItem=(psMetadataItem*)psListGetAndIncrement(iter)) != NULL) { 295 psMetadataAddItem(md,listItem,location,flags); 296 } 297 psFree(iter); 298 } 299 300 return true; // all done. 301 } 302 303 // how the item is added to the hash depends on prior existence, flags, etc. 304 if(existingEntry != NULL) { // prior existence 305 if (existingEntry->type == PS_META_MULTI || (flags & PS_META_DUPLICATE_OK) != 0) { 258 306 // duplicate entries allowed - add another entry. 259 if (existingEntry->type != PS_META_MULTI) { 260 // first duplicate, transfer the hash's old entry into a 261 // list of entries with the type PS_META_MULTI. 262 263 // add entry to a list and dereference the local pointer 264 psList* newList = psListAlloc(existingEntry); 265 266 existingEntry = psMetadataItemAlloc(key, 267 PS_META_MULTI, 268 "", 269 newList); 270 psHashRemove(mdTable,key); // take out the old entry 271 psHashAdd(mdTable, key, existingEntry); // put in the new entry 272 273 // free local references of newly allocated items. 274 psFree(newList); 275 psFree(existingEntry); 276 277 } 307 308 // make sure the existing entry is PS_META_MULTI 309 existingEntry = makeMetaMulti(mdTable,key,existingEntry); 278 310 279 311 // add to the hash's list of duplicate entries … … 282 314 return false; 283 315 } 284 // (added to list below)285 286 316 } else if ((flags & PS_META_REPLACE) != 0) { 287 317 // replace entry instead of creating a duplicate entry. 288 318 289 319 // remove the existing entry from metadata 290 psListRemoveData(mdList, existingEntry); 291 psHashRemove(mdTable, key); 320 psMetadataRemove(md,0,key); 292 321 293 322 // treat as if new (added to list below) … … 423 452 // multiple entries with same key, remove just the specified one 424 453 psListRemoveData(tableItem->data.list, entry); 425 if (psListGet(tableItem->data.list,PS_LIST_HEAD) == NULL) {426 // list is empty, so let's clear the whole entry now.427 if (!psHashRemove(mdTable, key)) {428 psError(PS_ERR_UNKNOWN, false, PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED, key);429 return false;430 }431 }432 454 } else { 433 455 if (!psHashRemove(mdTable, key)) { -
trunk/psLib/src/collections/psMetadata.h
r3381 r3407 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1. 39$ $Name: not supported by cvs2svn $14 * @date $Date: 2005-03- 07 20:58:50$13 * @version $Revision: 1.40 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2005-03-11 20:38:56 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 37 37 */ 38 38 typedef enum { 39 PS_META_S32 ,///< psS32 primitive data.40 PS_META_F32 ,///< psF32 primitive data.41 PS_META_F64 ,///< psF64 primitive data.42 PS_META_BOOL ,///< psBool primitive data.43 PS_META_LIST ,///< List data (Stored as item.data.list).39 PS_META_S32 = PS_TYPE_S32, ///< psS32 primitive data. 40 PS_META_F32 = PS_TYPE_F32, ///< psF32 primitive data. 41 PS_META_F64 = PS_TYPE_F64, ///< psF64 primitive data. 42 PS_META_BOOL = PS_TYPE_BOOL, ///< psBool primitive data. 43 PS_META_LIST = 0x10000, ///< List data (Stored as item.data.list). 44 44 PS_META_STR, ///< String data (Stored as item.data.V). 45 45 PS_META_VEC, ///< Vector data (Stored as item.data.V). … … 51 51 PS_META_ASTROM, ///< Astrometric coefficients (Stored as item.data.V). 52 52 PS_META_UNKNOWN, ///< Other data (Stored as item.data.V). 53 PS_META_MULTI, ///< Used internally, do not create an metadata item of this type. 54 PS_META_NTYPE ///< Number of types. Must be last. 53 PS_META_MULTI ///< Used internally, do not create an metadata item of this type. 55 54 } psMetadataType; 56 55 -
trunk/psLib/src/collections/psVector.c
r3264 r3407 1 2 1 /** @file psVector.c 3 2 * … … 10 9 * @author Robert DeSonia, MHPCC 11 10 * 12 * @version $Revision: 1.3 4$ $Name: not supported by cvs2svn $13 * @date $Date: 2005-0 2-17 19:26:23$11 * @version $Revision: 1.35 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2005-03-11 20:38:56 $ 14 13 * 15 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 18 17 #include <string.h> // for memcpy 19 18 #include <stdlib.h> 19 #include <stdio.h> 20 20 #include <math.h> 21 21 … … 407 407 return outVector; 408 408 } 409 410 char* psVectorToString(psVector* vector, int maxLength) 411 { 412 413 if (maxLength < 5) { 414 return NULL; 415 } 416 417 char* str = psAlloc(sizeof(char)*maxLength+1); 418 419 if (vector == NULL) { 420 snprintf(str,maxLength, "NULL"); 421 return str; 422 } 423 424 int size = vector->n; 425 426 if (size == 0) { 427 snprintf(str,maxLength, "[]"); 428 return str; 429 } 430 431 char* tempStr = psAlloc(sizeof(char)*maxLength+1); 432 *str = '\0'; 433 bool full = false; 434 435 #define APPEND_ELEMENTS_CASE(TYPE, NATIVE_TYPE, FORMAT) \ 436 case PS_TYPE_##TYPE: \ 437 for (lcv=0; lcv < size && ! full; lcv++) { \ 438 snprintf(tempStr, maxLength, "%s" FORMAT, prefix, (NATIVE_TYPE) (vector->data.TYPE[lcv])); \ 439 strncat(str,tempStr,maxLength); \ 440 full = (strlen(str) > maxLength-2); \ 441 prefix = ","; \ 442 } \ 443 break; 444 445 #define APPEND_ELEMENTS_CASE_COMPLEX(TYPE,CREAL,CIMAG) \ 446 case PS_TYPE_##TYPE: \ 447 for (lcv=0; lcv < size && ! full; lcv++) { \ 448 snprintf(tempStr, maxLength, "%s%g%+gi", prefix, \ 449 CREAL(vector->data.TYPE[lcv]), \ 450 CIMAG(vector->data.TYPE[lcv])); \ 451 full = (strlen(str) > maxLength-2); \ 452 prefix = ","; \ 453 } \ 454 break; 455 456 int lcv; 457 char* prefix = "["; 458 switch(vector->type.type) { 459 APPEND_ELEMENTS_CASE(S8,char,"%hd") 460 APPEND_ELEMENTS_CASE(S16,short int,"%hd") 461 APPEND_ELEMENTS_CASE(S32,int,"%d") 462 APPEND_ELEMENTS_CASE(S64,long,"%ld") 463 APPEND_ELEMENTS_CASE(U8,unsigned char,"%hu") 464 APPEND_ELEMENTS_CASE(U16,unsigned short,"%hu") 465 APPEND_ELEMENTS_CASE(U32,unsigned int, "%u") 466 APPEND_ELEMENTS_CASE(U64,unsigned long,"%lu") 467 APPEND_ELEMENTS_CASE(F32,double,"%g") 468 APPEND_ELEMENTS_CASE(F64,double,"%g") 469 APPEND_ELEMENTS_CASE_COMPLEX(C32,crealf,cimagf) 470 APPEND_ELEMENTS_CASE_COMPLEX(C64,creal,cimag) 471 default: 472 snprintf(str,maxLength,"[...]"); 473 break; 474 } 475 476 if (full) { 477 // couldn't all fit in given string length 478 479 // remove elements until there is room for ",...]" 480 while (strlen(str) > maxLength - 5) { 481 char* lastComma = strrchr(str,','); 482 if (lastComma == NULL) { // no comma, must be first number 483 str[1] = '\0'; 484 } else { 485 *lastComma = '\0'; 486 } 487 } 488 strncat(str,",...]",maxLength); 489 } else { 490 strncat(str,"]",maxLength); 491 } 492 493 psFree(tempStr); 494 495 return str; 496 } 497 -
trunk/psLib/src/collections/psVector.h
r3264 r3407 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.2 8$ $Name: not supported by cvs2svn $14 * @date $Date: 2005-0 2-17 19:26:23$13 * @version $Revision: 1.29 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2005-03-11 20:38:56 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 144 144 ); 145 145 146 /** Creates a string from a psVector's values in the form "[x0,x1,x2]". 147 * 148 * @return psPtr a newly allocated string 149 */ 150 char* psVectorToString( 151 psVector* vector, ///< vector to create a string from 152 int maxLength ///< the maximum length of the resulting string 153 ); 154 146 155 /// @} 147 156
Note:
See TracChangeset
for help on using the changeset viewer.
