Changeset 5850 for branches/uq/src/core/RpDict.h
- Timestamp:
- Aug 28, 2015, 10:12:22 AM (9 years ago)
- Location:
- branches/uq
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/uq
-
branches/uq/src/core/RpDict.h
r5679 r5850 22 22 /**************************************************************************/ 23 23 24 template < 25 26 24 template <typename KeyType, 25 typename ValType, 26 class _Compare=std::equal_to<KeyType> > 27 27 class RpDict; 28 28 29 template < 30 31 29 template <typename KeyType, 30 typename ValType, 31 class _Compare=std::equal_to<KeyType> > 32 32 class RpDictEntry; 33 33 34 template < 35 36 34 template <typename KeyType, 35 typename ValType, 36 class _Compare=std::equal_to<KeyType> > 37 37 class RpDictIterator; 38 39 38 40 39 /* … … 48 47 * because RpBindingsDict uses it. 49 48 */ 50 51 49 52 50 /**************************************************************************/ … … 93 91 private: 94 92 95 RpDict<KeyType,ValType,_Compare>& 96 tablePtr; /* pointer to the table we want to 93 RpDict<KeyType,ValType,_Compare>& 94 tablePtr; /* pointer to the table we want to 97 95 * iterate */ 98 96 int srchNextIndex; /* Index of next bucket to be 99 97 * enumerated after present one. */ 100 RpDictEntry<KeyType,ValType,_Compare>* 98 RpDictEntry<KeyType,ValType,_Compare>* 101 99 srchNextEntryPtr; /* Next entry to be enumerated in the 102 100 * the current bucket. */ 103 101 104 102 }; 105 106 103 107 104 template <typename KeyType, typename ValType, class _Compare> … … 113 110 // operator==(const RpDictEntry& entry) const; 114 111 // 115 //operator!=(const RpDictEntry& lhs, const RpDictEntry& rhs) const 112 //operator!=(const RpDictEntry& lhs, const RpDictEntry& rhs) const 116 113 //{ 117 114 // if (lhs.key != rhs.key) … … 189 186 }; 190 187 191 192 188 template <typename KeyType, typename ValType, class _Compare> 193 189 class RpDict … … 207 203 // 208 204 /*virtual*/ RpDict<KeyType,ValType,_Compare>& 209 set( 210 211 212 213 205 set(KeyType& key, 206 ValType& value, 207 RpDictHint hint=NULL, 208 int *newPtr=NULL, 209 bool ci=false); 214 210 215 211 // find an RpUnits object that should exist in RpUnitsTable 216 // 212 // 217 213 /*virtual*/ RpDictEntry<KeyType,ValType,_Compare>& 218 find( 219 220 bool ci=false);221 222 /*virtual*/ RpDictEntry<KeyType,ValType,_Compare>& operator[]( 214 find(KeyType& key, 215 RpDictHint hint = NULL, 216 bool ci=false); 217 218 /*virtual*/ RpDictEntry<KeyType,ValType,_Compare>& operator[](KeyType& key) 223 219 { 224 220 return find(key,NULL); 225 221 } 226 222 227 RpDict<KeyType,ValType,_Compare>& setCI( bool val);223 RpDict<KeyType,ValType,_Compare>& setCI(bool val); 228 224 bool getCI(); 229 225 RpDict<KeyType,ValType,_Compare>& toggleCI(); … … 263 259 } 264 260 265 // copy constructor 261 // copy constructor 266 262 // RpDict (const RpDict& dict); 267 263 … … 283 279 const int REBUILD_MULTIPLIER; 284 280 285 RpDictEntry<KeyType,ValType,_Compare> 281 RpDictEntry<KeyType,ValType,_Compare> 286 282 **buckets; /* Pointer to bucket array. Each 287 283 * element points to first entry in … … 314 310 315 311 RpDictEntry<KeyType,ValType,_Compare>* 316 search( KeyType& key, RpDictHint hint = NULL, bool ci = false);312 search(KeyType& key, RpDictHint hint = NULL, bool ci = false); 317 313 318 314 // static void RpDict::RebuildTable (); … … 326 322 }; 327 323 328 329 324 /*--------------------------------------------------------------------------*/ 330 325 /*--------------------------------------------------------------------------*/ … … 340 335 * Side Effects: 341 336 * none. 342 * 337 * 343 338 * 344 339 *************************************************************************/ 345 346 340 template <typename KeyType, typename ValType, class _Compare> 347 341 int … … 350 344 return numEntries; 351 345 } 352 353 346 354 347 /************************************************************************** … … 359 352 * 360 353 * Results: 361 * Returns a reference to the RpDict object allowing the user to chain 354 * Returns a reference to the RpDict object allowing the user to chain 362 355 * together different commands such as 363 356 * rpdict_obj.set(key).find(a).erase(a); … … 370 363 template <typename KeyType, typename ValType, class _Compare> 371 364 RpDict<KeyType,ValType,_Compare>& 372 RpDict<KeyType,ValType,_Compare>::set( 373 374 375 376 bool ci)365 RpDict<KeyType,ValType,_Compare>::set(KeyType& key, 366 ValType& value, 367 RpDictHint hint, 368 int* newPtr, 369 bool ci) 377 370 { 378 371 RpDictEntry<KeyType,ValType,_Compare> *hPtr = NULL; … … 466 459 *---------------------------------------------------------------------- 467 460 */ 468 469 461 template <typename KeyType, typename ValType, class _Compare> 470 462 RpDictEntry<KeyType,ValType,_Compare>& 471 RpDict<KeyType,ValType,_Compare>::find( 472 473 bool ci)463 RpDict<KeyType,ValType,_Compare>::find(KeyType& key, 464 RpDictHint hint, 465 bool ci) 474 466 { 475 467 RpDictEntry<KeyType,ValType,_Compare> *hPtr = NULL; … … 503 495 *---------------------------------------------------------------------- 504 496 */ 505 506 497 template <typename KeyType, typename ValType, class _Compare> 507 498 RpDictEntry<KeyType,ValType,_Compare>* 508 RpDict<KeyType,ValType,_Compare>::search( 509 510 bool ci)511 512 499 RpDict<KeyType,ValType,_Compare>::search(KeyType& key, 500 RpDictHint hint, 501 bool ci) 502 // bool ci, 503 // RpDictEntryList* entryList) 513 504 { 514 505 RpDictEntry<KeyType,ValType,_Compare> *hPtr = NULL; … … 572 563 } 573 564 574 575 576 565 /************************************************************************** 577 566 * … … 589 578 /* 590 579 template <typename KeyType,typename ValType,class _Compare> 591 RpDict<KeyType,ValType,_Compare>& 592 RpDictIterator<KeyType,ValType,_Compare>::getTable() 580 RpDict<KeyType,ValType,_Compare>& 581 RpDictIterator<KeyType,ValType,_Compare>::getTable() 593 582 { 594 583 return tablePtr; … … 606 595 * Side Effects: 607 596 * moves iterator to the beginning of the hash table. 608 * 597 * 609 598 * 610 599 *************************************************************************/ … … 630 619 * Side Effects: 631 620 * moves iterator to the next entry of the hash table if it exists. 632 * 621 * 633 622 * 634 623 *************************************************************************/ 635 636 624 template <typename KeyType,typename ValType,class _Compare> 637 625 RpDictEntry<KeyType,ValType,_Compare>* … … 669 657 template <typename KeyType, typename ValType, class _Compare> 670 658 RpDict<KeyType,ValType,_Compare>& 671 RpDict<KeyType,ValType,_Compare>::setCI( bool val)659 RpDict<KeyType,ValType,_Compare>::setCI(bool val) 672 660 { 673 661 caseInsensitive = val; … … 764 752 return *nullEntry; 765 753 } 766 767 754 768 755 /* … … 784 771 *---------------------------------------------------------------------- 785 772 */ 786 787 773 template <typename KeyType, typename ValType, class _Compare> 788 774 void … … 794 780 795 781 // check to see if the object is associated with a table 796 // if object is not associated with a table, there is no 782 // if object is not associated with a table, there is no 797 783 // need to try to remove it from the table. 798 784 if (tablePtr) { … … 804 790 805 791 // remove the entry from the buckets 806 // 792 // 807 793 // if entry is the first entry in the bucket 808 794 // move the bucket to point to the next entry … … 812 798 else { 813 799 // if the entry is not the first entry in the bucket 814 // search for the entry 800 // search for the entry 815 801 for (prevPtr = *bucketPtr; ; prevPtr = prevPtr->nextPtr) { 816 802 … … 821 807 prevPtr->nextPtr = nextPtr; 822 808 break; 823 } 809 } 824 810 } // end for loop 825 811 } // end else … … 843 829 } 844 830 845 846 831 /* 847 832 *---------------------------------------------------------------------- … … 859 844 *---------------------------------------------------------------------- 860 845 */ 861 862 846 template <typename KeyType, typename ValType, class _Compare> 863 847 const KeyType* … … 884 868 *---------------------------------------------------------------------- 885 869 */ 886 887 870 template <typename KeyType, typename ValType, class _Compare> 888 871 const ValType* … … 907 890 *---------------------------------------------------------------------- 908 891 */ 909 910 892 template <typename KeyType, typename ValType, class _Compare> 911 893 const ValType* … … 944 926 *---------------------------------------------------------------------- 945 927 */ 946 947 928 template <typename KeyType, typename ValType, class _Compare> 948 929 bool … … 954 935 return false; 955 936 } 956 957 937 958 938 /*************************************************************************/ … … 978 958 *---------------------------------------------------------------------- 979 959 */ 980 981 960 template <typename KeyType, typename ValType, class _Compare> 982 961 void 983 962 RpDict<KeyType,ValType,_Compare>::RebuildTable() 984 963 { 985 int oldSize=0, count=0, index=0; 964 int oldSize=0, count=0, index=0; 986 965 RpDictEntry<KeyType,ValType,_Compare> **oldBuckets = NULL; 987 966 RpDictEntry<KeyType,ValType,_Compare> **oldChainPtr = NULL, **newChainPtr = NULL; … … 996 975 */ 997 976 998 999 977 numBuckets *= 4; 1000 978 … … 1054 1032 *---------------------------------------------------------------------- 1055 1033 */ 1056 1057 1034 template <typename KeyType, typename ValType, class _Compare> 1058 1035 unsigned int … … 1082 1059 * I chose the one below (multiply by 9 and add new character) 1083 1060 * because of the following reasons: 1084 * 1061 * 1085 1062 * 1. Multiplying by 10 is perfect for keys that are decimal strings, 1086 1063 * and multiplying by 9 is just about as good. … … 1091 1068 * works well both for decimal and non-decimal strings. 1092 1069 */ 1093 1094 1095 1070 template <typename KeyType, typename ValType, class _Compare> 1096 1071 unsigned int … … 1158 1133 * --------------------------------------------------------------------- 1159 1134 */ 1160 1161 1135 template <typename KeyType, typename ValType, class _Compare> 1162 1136 int … … 1166 1140 } 1167 1141 1168 1169 1170 1142 #endif
Note: See TracChangeset
for help on using the changeset viewer.