Changeset 443
- Timestamp:
- May 22, 2006 7:28:33 PM (18 years ago)
- Location:
- trunk/src2/core
- Files:
-
- 2 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src2/core/Lookup.cpp
r441 r443 1 1 /* 2 2 * ====================================================================== 3 * Rappture::Dictionary<keyType,valType> 3 * Rappture::Lookup<valType> 4 * Rappture::Lookup2<keyType,valType> 4 5 * 5 6 * AUTHOR: Michael McLennan, Purdue University … … 60 61 */ 61 62 #include <sstream> 62 #include " Dictionary.h"63 #include "Lookup.h" 63 64 64 65 using namespace Rappture; … … 71 72 72 73 73 DictionaryCore::DictionaryCore(size_t keySize)74 LookupCore::LookupCore(size_t keySize) 74 75 { 75 76 // convert key size in bytes to size in words … … 87 88 } 88 89 89 DictionaryCore::~DictionaryCore()90 { 91 // free up all entries in the dictionary90 LookupCore::~LookupCore() 91 { 92 // free up all entries in the lookup table 92 93 for (int i = 0; i < _numBuckets; i++) { 93 DictEntryCore *entryPtr = _buckets[i];94 LookupEntryCore *entryPtr = _buckets[i]; 94 95 while (entryPtr != NULL) { 95 DictEntryCore *nextPtr = entryPtr->nextPtr;96 LookupEntryCore *nextPtr = entryPtr->nextPtr; 96 97 delete entryPtr; 97 98 entryPtr = nextPtr; … … 106 107 107 108 /** 108 * Finds a dictionaryentry with the specified key. Returns109 * Finds a lookup entry with the specified key. Returns 109 110 * the entry, or NULL if there was no matching entry. 110 111 */ 111 DictEntryCore*112 DictionaryCore::find(void* key)112 LookupEntryCore* 113 LookupCore::find(void* key) 113 114 { 114 115 unsigned int index = _hashIndex(key); … … 117 118 // Search all of the entries in the appropriate bucket. 118 119 // 119 DictEntryCore *hPtr;120 LookupEntryCore *hPtr; 120 121 if (_keySize == 0) { 121 122 for (hPtr=_buckets[index]; hPtr != NULL; hPtr=hPtr->nextPtr) { … … 150 151 151 152 /** 152 * Finds a dictionaryentry with the specified key. Returns153 * Finds a lookup entry with the specified key. Returns 153 154 * the entry, or NULL if there was no matching entry. 154 155 */ 155 DictEntryCore*156 DictionaryCore::get(void* key, int* newEntryPtr)156 LookupEntryCore* 157 LookupCore::get(void* key, int* newEntryPtr) 157 158 { 158 159 if (newEntryPtr) { … … 165 166 // Search all of the entries in the appropriate bucket. 166 167 // 167 DictEntryCore *hPtr;168 LookupEntryCore *hPtr; 168 169 if (_keySize == 0) { 169 170 for (hPtr=_buckets[index]; hPtr != NULL; hPtr=hPtr->nextPtr) { … … 202 203 } 203 204 if (_keySize == 0) { 204 char* mem = new char[sizeof( DictEntryCore)205 char* mem = new char[sizeof(LookupEntryCore) 205 206 + strlen((char*)key) - sizeof(hPtr->key) + 1]; 206 hPtr = new (mem) DictEntryCore;207 } else { 208 char* mem = new char[sizeof( DictEntryCore) + _keySize-1];209 hPtr = new (mem) DictEntryCore;207 hPtr = new (mem) LookupEntryCore; 208 } else { 209 char* mem = new char[sizeof(LookupEntryCore) + _keySize-1]; 210 hPtr = new (mem) LookupEntryCore; 210 211 } 211 212 hPtr->dictPtr = this; … … 233 234 234 235 /** 235 * Removes an entry from the dictionary. The data associated236 * with the entry is freed at the Dictionarylevel before calling236 * Removes an entry from the lookup table. The data associated 237 * with the entry is freed at the Lookup level before calling 237 238 * this core method to clean up the slot. 238 239 */ 239 DictEntryCore*240 DictionaryCore::erase(DictEntryCore* entryPtr)241 { 242 DictEntryCore *prevPtr;240 LookupEntryCore* 241 LookupCore::erase(LookupEntryCore* entryPtr) 242 { 243 LookupEntryCore *prevPtr; 243 244 244 245 if (*entryPtr->bucketPtr == entryPtr) { … … 254 255 } 255 256 entryPtr->dictPtr->_numEntries--; 256 DictEntryCore *nextPtr = entryPtr->nextPtr;257 LookupEntryCore *nextPtr = entryPtr->nextPtr; 257 258 delete entryPtr; 258 259 … … 266 267 * helps keep track of the next bucket in the table. 267 268 */ 268 DictEntryCore*269 DictionaryCore::next(DictEntryCore *entryPtr, int& bucketNum)269 LookupEntryCore* 270 LookupCore::next(LookupEntryCore *entryPtr, int& bucketNum) 270 271 { 271 272 if (entryPtr) { … … 285 286 286 287 /** 287 * Returns a description of all entries in the dictionary.288 * Returns a description of all entries in the lookup table. 288 289 * Useful for debugging. 289 290 */ 290 291 std::string 291 DictionaryCore::stats()292 LookupCore::stats() 292 293 { 293 294 #define NUM_COUNTERS 10 … … 305 306 for (i=0; i < _numBuckets; i++) { 306 307 int j=0; 307 for ( DictEntryCore *entryPtr=_buckets[i];308 for (LookupEntryCore *entryPtr=_buckets[i]; 308 309 entryPtr != NULL; 309 310 entryPtr = entryPtr->nextPtr) { … … 323 324 // 324 325 std::ostringstream result; 325 result << _numEntries << " entries in dictionary, ";326 result << _numEntries << " entries in lookup table, "; 326 327 result << _numBuckets << " buckets" << std::endl; 327 328 … … 342 343 */ 343 344 void 344 DictionaryCore::_rebuildBuckets()345 LookupCore::_rebuildBuckets() 345 346 { 346 347 int oldSize = _numBuckets; 347 DictEntryCore** oldBuckets = _buckets;348 LookupEntryCore** oldBuckets = _buckets; 348 349 349 350 // … … 352 353 // 353 354 _numBuckets *= 4; 354 _buckets = new ( DictEntryCore*)[_numBuckets];355 DictEntryCore **newChainPtr = _buckets;355 _buckets = new (LookupEntryCore*)[_numBuckets]; 356 LookupEntryCore **newChainPtr = _buckets; 356 357 for (int count=_numBuckets; count > 0; count--, newChainPtr++) { 357 358 *newChainPtr = NULL; … … 364 365 // Rehash all of the existing entries into the new bucket array. 365 366 // 366 for ( DictEntryCore** oldChainPtr=oldBuckets;367 for (LookupEntryCore** oldChainPtr=oldBuckets; 367 368 oldSize > 0; oldSize--, oldChainPtr++) { 368 369 369 for ( DictEntryCore* hPtr=*oldChainPtr;370 for (LookupEntryCore* hPtr=*oldChainPtr; 370 371 hPtr != NULL; hPtr=*oldChainPtr) { 371 372 … … 390 391 */ 391 392 unsigned int 392 DictionaryCore::_hashIndex(void* key)393 LookupCore::_hashIndex(void* key) 393 394 { 394 395 unsigned int result = 0; -
trunk/src2/core/Lookup.h
r441 r443 1 1 /* 2 2 * ====================================================================== 3 * Rappture::Dictionary<keyType,valType> 3 * Rappture::Lookup<valType> 4 * Rappture::Lookup2<keyType,valType> 4 5 * 5 6 * AUTHOR: Michael McLennan, Purdue University … … 69 70 namespace Rappture { 70 71 71 class DictionaryCore; // foward declaration72 class LookupCore; // foward declaration 72 73 73 74 /** 74 * Represents one entry within a dictionaryobject, cast in terms75 * Represents one entry within a lookup object, cast in terms 75 76 * of void pointers and data sizes, so that the official, templated 76 77 * version of the class can be lean and mean. 77 78 */ 78 struct DictEntryCore {79 DictEntryCore *nextPtr; // pointer to next entry in this bucket80 DictionaryCore *dictPtr; // pointer to dictionarycontaining entry81 DictEntryCore **bucketPtr; // pointer to bucket containing this entry82 83 void *valuePtr; // value within this hash entry79 struct LookupEntryCore { 80 LookupEntryCore *nextPtr; // pointer to next entry in this bucket 81 LookupCore *dictPtr; // pointer to lookup containing entry 82 LookupEntryCore **bucketPtr; // pointer to bucket containing this entry 83 84 void *valuePtr; // value within this hash entry 84 85 85 86 union { 86 void *ptrValue; // size of a pointer87 int words[1]; // multiple integer words for the key88 char string[4]; // first part of string value for key89 } key; // memory can be oversized if more90 // space is needed for words/string91 // MUST BE THE LAST FIELD IN THIS RECORD!87 void *ptrValue; // size of a pointer 88 int words[1]; // multiple integer words for the key 89 char string[4]; // first part of string value for key 90 } key; // memory can be oversized if more 91 // space is needed for words/string 92 // MUST BE THE LAST FIELD IN THIS RECORD! 92 93 }; 93 94 94 95 /** 95 * This is the functional core of a dictionaryobject, cast in terms96 * This is the functional core of a lookup object, cast in terms 96 97 * of void pointers and data sizes, so that the official, templated 97 98 * version of the class can be lean and mean. 98 99 */ 99 class DictionaryCore {100 class LookupCore { 100 101 public: 101 DictionaryCore(size_t keySize);102 ~ DictionaryCore();103 104 DictEntryCore* get(void* key, int* newEntryPtr);105 DictEntryCore* find(void* key);106 DictEntryCore* erase(DictEntryCore* entryPtr);107 DictEntryCore* next(DictEntryCore* entryPtr, int& bucketNum);102 LookupCore(size_t keySize); 103 ~LookupCore(); 104 105 LookupEntryCore* get(void* key, int* newEntryPtr); 106 LookupEntryCore* find(void* key); 107 LookupEntryCore* erase(LookupEntryCore* entryPtr); 108 LookupEntryCore* next(LookupEntryCore* entryPtr, int& bucketNum); 108 109 std::string stats(); 109 110 110 111 private: 111 /// Not allowed -- copy Dictionaryat higher level112 DictionaryCore(const DictionaryCore& dcore) { assert(0); }113 114 /// Not allowed -- copy Dictionaryat higher level115 DictionaryCore& operator=(const DictionaryCore& dcore) { assert(0); }112 /// Not allowed -- copy Lookup at higher level 113 LookupCore(const LookupCore& dcore) { assert(0); } 114 115 /// Not allowed -- copy Lookup at higher level 116 LookupCore& operator=(const LookupCore& dcore) { assert(0); } 116 117 117 118 // utility functions … … 123 124 124 125 /// Pointer to array of hash buckets. 125 DictEntryCore **_buckets;126 LookupEntryCore **_buckets; 126 127 127 128 /// Built-in storage for small hash tables. 128 DictEntryCore *_staticBuckets[RP_DICT_MIN_SIZE];129 130 /// Total number of entries in the dictionary.129 LookupEntryCore *_staticBuckets[RP_DICT_MIN_SIZE]; 130 131 /// Total number of entries in the lookup. 131 132 int _numEntries; 132 133 … … 145 146 146 147 /** 147 * This represents a single entry within a dictionaryobject. It is148 * used to access values within the dictionary, or as an iterator149 * that traverses the dictionary.148 * This represents a single entry within a lookup object. It is 149 * used to access values within the lookup, or as an iterator 150 * that traverses the lookup. 150 151 */ 151 152 template <class KeyType, class ValType> 152 class DictEntry{153 class LookupEntry2 { 153 154 public: 154 DictEntry(Ptr<DictionaryCore> corePtr, DictEntryCore *entryPtr=NULL);155 DictEntry(const DictEntry& entry);156 DictEntry& operator=(const DictEntry& entry);157 ~ DictEntry();155 LookupEntry2(LookupCore* corePtr, LookupEntryCore* entryPtr=NULL); 156 LookupEntry2(const LookupEntry2& entry); 157 LookupEntry2& operator=(const LookupEntry2& entry); 158 ~LookupEntry2(); 158 159 159 160 int isNull() const; 160 161 KeyType& key(); 161 162 ValType& value(); 162 DictEntry& next();163 DictEntry& erase();163 LookupEntry2& next(); 164 LookupEntry2& erase(); 164 165 165 166 private: 166 Ptr<DictionaryCore>_corePtr;167 DictEntryCore *_entryPtr;167 LookupCore* _corePtr; 168 LookupEntryCore* _entryPtr; 168 169 int _bucketNum; 169 170 }; 170 171 171 172 template <class KeyType, class ValType> 172 DictEntry<KeyType,ValType>::DictEntry(Ptr<DictionaryCore>corePtr,173 DictEntryCore *entryPtr)173 LookupEntry2<KeyType,ValType>::LookupEntry2(LookupCore* corePtr, 174 LookupEntryCore* entryPtr) 174 175 : _corePtr(corePtr), 175 176 _entryPtr(entryPtr), … … 179 180 180 181 template <class KeyType, class ValType> 181 DictEntry<KeyType,ValType>::DictEntry(const DictEntry&entry)182 LookupEntry2<KeyType,ValType>::LookupEntry2(const LookupEntry2 &entry) 182 183 : _corePtr(entry._corePtr), 183 184 _entryPtr(entry._entryPtr), … … 187 188 188 189 template <class KeyType, class ValType> 189 DictEntry<KeyType,ValType>&190 DictEntry<KeyType,ValType>::operator=(const DictEntry&entry)190 LookupEntry2<KeyType,ValType>& 191 LookupEntry2<KeyType,ValType>::operator=(const LookupEntry2 &entry) 191 192 { 192 193 _corePtr = entry._corePtr; … … 197 198 198 199 template <class KeyType, class ValType> 199 DictEntry<KeyType,ValType>::~DictEntry()200 LookupEntry2<KeyType,ValType>::~LookupEntry2() 200 201 { 201 202 } … … 203 204 template <class KeyType, class ValType> 204 205 int 205 DictEntry<KeyType,ValType>::isNull() const206 LookupEntry2<KeyType,ValType>::isNull() const 206 207 { 207 208 return (_entryPtr == NULL); … … 210 211 template <class KeyType, class ValType> 211 212 KeyType& 212 DictEntry<KeyType,ValType>::key()213 LookupEntry2<KeyType,ValType>::key() 213 214 { 214 215 return *(KeyType*)(_entryPtr->key.string); … … 217 218 template <class KeyType, class ValType> 218 219 ValType& 219 DictEntry<KeyType,ValType>::value() 220 { 221 return *static_cast<ValType*>(_entryPtr->valuePtr); 222 } 223 224 template <class KeyType, class ValType> 225 DictEntry<KeyType,ValType>& 226 DictEntry<KeyType,ValType>::next() 220 LookupEntry2<KeyType,ValType>::value() 221 { 222 if (sizeof(ValType) > sizeof(_entryPtr->valuePtr)) { 223 return *static_cast<ValType*>(_entryPtr->valuePtr); 224 } 225 return *(ValType*)(&_entryPtr->valuePtr); 226 } 227 228 template <class KeyType, class ValType> 229 LookupEntry2<KeyType,ValType>& 230 LookupEntry2<KeyType,ValType>::next() 227 231 { 228 232 _entryPtr = _corePtr->next(_entryPtr, _bucketNum); … … 231 235 232 236 template <class KeyType, class ValType> 233 DictEntry<KeyType,ValType>& 234 DictEntry<KeyType,ValType>::erase() 235 { 236 _entryPtr = _corePtr->erase(_entryPtr); 237 LookupEntry2<KeyType,ValType>& 238 LookupEntry2<KeyType,ValType>::erase() 239 { 240 if (_entryPtr != NULL) { 241 // delete the value 242 if (_entryPtr->valuePtr 243 && sizeof(ValType) > sizeof(_entryPtr->valuePtr)) { 244 delete static_cast<ValType*>(_entryPtr->valuePtr); 245 } 246 // delete the slot 247 _entryPtr = _corePtr->erase(_entryPtr); 248 } 237 249 238 250 if (_entryPtr == NULL) { 251 // at the end of this bucket? then move on to next one 239 252 _corePtr->next(_entryPtr, _bucketNum); 240 253 } … … 243 256 244 257 /** 245 * This is a dictionaryobject or associative array. It is a hash258 * This is a lookup object or associative array. It is a hash 246 259 * table that uniquely maps a key to a value. The memory for values 247 * added to dictionary is managed by the dictionary. When a dictionary260 * added to lookup is managed by the lookup. When a lookup 248 261 * is deleted, its internal values are cleaned up automatically. 249 262 */ 250 263 template <class KeyType, class ValType> 251 class Dictionary{264 class Lookup2 { 252 265 public: 253 Dictionary(); 254 Dictionary(const Dictionary& dict); 255 Dictionary& operator=(const Dictionary& dict); 256 ~Dictionary(); 257 258 DictEntry<KeyType,ValType> get(const KeyType& key, int* newEntryPtr); 259 DictEntry<KeyType,ValType> find(const KeyType& key) const; 260 DictEntry<KeyType,ValType> erase(const KeyType& key); 266 Lookup2(int size=-1); 267 Lookup2(const Lookup2& dict); 268 Lookup2& operator=(const Lookup2& dict); 269 ~Lookup2(); 270 271 LookupEntry2<KeyType,ValType> get(const KeyType& key, int* newEntryPtr); 272 LookupEntry2<KeyType,ValType> find(const KeyType& key) const; 273 ValType& operator[](const KeyType& key); 274 LookupEntry2<KeyType,ValType> erase(const KeyType& key); 261 275 void clear(); 262 276 263 DictEntry<KeyType,ValType> first();277 LookupEntry2<KeyType,ValType> first(); 264 278 265 279 std::string stats(); 266 280 267 281 private: 268 Ptr<DictionaryCore>_corePtr;269 }; 270 271 template <class KeyType, class ValType> 272 Dictionary<KeyType,ValType>::Dictionary()273 { 274 _corePtr = Ptr<DictionaryCore>( new DictionaryCore(sizeof(KeyType)) );275 } 276 277 template <class KeyType, class ValType> 278 Dictionary<KeyType,ValType>::Dictionary(const Dictionary<KeyType,ValType>& dict)279 { 280 _corePtr = Ptr<DictionaryCore>( new DictionaryCore(sizeof(KeyType)));281 282 DictEntry<KeyType,ValType> entry;282 LookupCore* _corePtr; 283 }; 284 285 template <class KeyType, class ValType> 286 Lookup2<KeyType,ValType>::Lookup2(int size) 287 { 288 _corePtr = new LookupCore( (size >= 0) ? size : sizeof(KeyType) ); 289 } 290 291 template <class KeyType, class ValType> 292 Lookup2<KeyType,ValType>::Lookup2(const Lookup2<KeyType,ValType>& dict) 293 { 294 _corePtr = new LookupCore(sizeof(KeyType)); 295 296 LookupEntry2<KeyType,ValType> entry; 283 297 for (entry=dict.first(); !entry.isNull(); entry.next()) { 284 298 get(entry.key(), NULL).value() = entry.value(); … … 287 301 288 302 template <class KeyType, class ValType> 289 Dictionary<KeyType,ValType>&290 Dictionary<KeyType,ValType>::operator=(const Dictionary<KeyType,ValType>& dict)291 { 292 *_corePtr = *dict._corePtr;293 294 DictEntry<KeyType,ValType> entry;303 Lookup2<KeyType,ValType>& 304 Lookup2<KeyType,ValType>::operator=(const Lookup2<KeyType,ValType>& dict) 305 { 306 _corePtr->clear(); 307 308 LookupEntry2<KeyType,ValType> entry; 295 309 for (entry=dict.first(); !entry.isNull(); entry.next()) { 296 310 get(entry.key(), NULL).value() = entry.value(); … … 299 313 300 314 template <class KeyType, class ValType> 301 Dictionary<KeyType,ValType>::~Dictionary()315 Lookup2<KeyType,ValType>::~Lookup2() 302 316 { 303 317 clear(); 318 delete _corePtr; 304 319 } 305 320 306 321 template <class KeyType, class ValType> 307 322 void 308 Dictionary<KeyType,ValType>::clear()309 { 310 DictEntry<KeyType,ValType> entry = first();323 Lookup2<KeyType,ValType>::clear() 324 { 325 LookupEntry2<KeyType,ValType> entry = first(); 311 326 while (!entry.isNull()) { 312 327 entry.erase(); … … 315 330 316 331 template <class KeyType, class ValType> 317 DictEntry<KeyType,ValType> 318 Dictionary<KeyType,ValType>::get(const KeyType& key, int* newEntryPtr) 319 { 320 DictEntryCore* entryPtr = _corePtr->get((void*)&key, newEntryPtr); 321 if (entryPtr->valuePtr == NULL) { 332 LookupEntry2<KeyType,ValType> 333 Lookup2<KeyType,ValType>::get(const KeyType& key, int* newEntryPtr) 334 { 335 LookupEntryCore* entryPtr = _corePtr->get((void*)&key, newEntryPtr); 336 if (entryPtr->valuePtr == NULL 337 && sizeof(ValType) > sizeof(entryPtr->valuePtr)) { 322 338 entryPtr->valuePtr = new ValType; 323 339 } 324 return DictEntry<KeyType,ValType>(_corePtr, entryPtr); 325 } 326 327 template <class KeyType, class ValType> 328 DictEntry<KeyType,ValType> 329 Dictionary<KeyType,ValType>::first() 330 { 331 DictEntry<KeyType,ValType> entry(_corePtr); 340 return LookupEntry2<KeyType,ValType>(_corePtr, entryPtr); 341 } 342 343 template <class KeyType, class ValType> 344 ValType& 345 Lookup2<KeyType,ValType>::operator[](const KeyType& key) 346 { 347 LookupEntry2<KeyType,ValType> entry = get(key, NULL); 348 return entry.value(); 349 } 350 351 template <class KeyType, class ValType> 352 LookupEntry2<KeyType,ValType> 353 Lookup2<KeyType,ValType>::first() 354 { 355 LookupEntry2<KeyType,ValType> entry(_corePtr); 332 356 return entry.next(); 333 357 } … … 335 359 template <class KeyType, class ValType> 336 360 std::string 337 Dictionary<KeyType,ValType>::stats()361 Lookup2<KeyType,ValType>::stats() 338 362 { 339 363 return _corePtr->stats(); 340 364 } 341 365 366 template <class ValType> 367 class LookupEntry : public LookupEntry2<const char*,ValType> { 368 public: 369 LookupEntry(LookupCore* corePtr, LookupEntryCore* entryPtr=NULL); 370 LookupEntry(const LookupEntry2<const char*,ValType>& entry); 371 }; 372 373 template <class ValType> 374 LookupEntry<ValType>::LookupEntry(LookupCore* corePtr, 375 LookupEntryCore* entryPtr) 376 : LookupEntry2<const char*,ValType>(corePtr, entryPtr) 377 { 378 } 379 380 template <class ValType> 381 LookupEntry<ValType>::LookupEntry( 382 const LookupEntry2<const char*,ValType>& entry) 383 : LookupEntry2<const char*,ValType>(entry) 384 { 385 } 386 387 template <class ValType> 388 class Lookup : public Lookup2<const char*,ValType> { 389 public: 390 Lookup(); 391 }; 392 393 template <class ValType> 394 Lookup<ValType>::Lookup() 395 : Lookup2<const char*,ValType>(0) 396 { 397 } 342 398 343 399 } // namespace Rappture -
trunk/src2/core/Makefile
r441 r443 8 8 g++ $(CFLAGS) -c -o viz.o viz.cc 9 9 10 test: test.o Ptr.o Outcome.o Dictionary.o11 g++ $(CFLAGS) -o test test.o Ptr.o Outcome.o Dictionary.o10 test: test.o Ptr.o Outcome.o Lookup.o 11 g++ $(CFLAGS) -o test test.o Ptr.o Outcome.o Lookup.o 12 12 13 13 docs: … … 27 27 g++ $(CFLAGS) -c -o Outcome.o Outcome.cpp 28 28 29 Dictionary.o: Dictionary.cpp Ptr.h30 g++ $(CFLAGS) -c -o Dictionary.o Dictionary.cpp29 Lookup.o: Lookup.cpp Ptr.h 30 g++ $(CFLAGS) -c -o Lookup.o Lookup.cpp 31 31 32 32 RpMesh1D.o: RpMesh1D.cc RpMesh1D.h RpNode.h -
trunk/src2/core/test.cc
r441 r443 3 3 #include <sstream> 4 4 #include "rappture.h" 5 #include " Dictionary.h"5 #include "Lookup.h" 6 6 7 7 class Foo { … … 40 40 ptr.clear(); 41 41 42 Rappture:: Dictionary<int,int> str2id;43 str2id.get(4,NULL).value() = 1;44 str2id.get(105,NULL).value() = 2;45 str2id.get(69,NULL).value() = 3;46 str2id.get(95,NULL).value() = 4;42 Rappture::Lookup2<int,int> num2id; 43 num2id.get(4,NULL).value() = 1; 44 num2id.get(105,NULL).value() = 2; 45 num2id.get(69,NULL).value() = 3; 46 num2id.get(95,NULL).value() = 4; 47 47 48 std::cout << str2id.stats(); 48 std::cout << num2id.stats(); 49 Rappture::LookupEntry2<int,int> entry = num2id.first(); 50 while (!entry.isNull()) { 51 std::cout << " " << entry.key() << " = " << entry.value() << std::endl; 52 entry.next(); 53 } 49 54 50 Rappture::DictEntry<int,int> entry = str2id.first(); 51 while (!entry.isNull()) { 52 std::cout << " " << entry.key() << " = =" << entry.value() << std::endl; 53 entry.next(); 55 Rappture::Lookup<double> str2dbl; 56 const char *one = "testing"; 57 const char *two = "another"; 58 str2dbl[one] = 2.0; 59 str2dbl[two] = 5.75; 60 61 std::cout << str2dbl.stats(); 62 Rappture::LookupEntry<double> entry2 = str2dbl.first(); 63 while (!entry2.isNull()) { 64 std::cout << " " << entry2.key() << " = " << entry2.value() << std::endl; 65 entry2.next(); 54 66 } 55 67
Note: See TracChangeset
for help on using the changeset viewer.