Changeset 443


Ignore:
Timestamp:
May 22, 2006 7:28:33 PM (18 years ago)
Author:
mmc
Message:

Changed "Dictionary" to "Lookup" and added simpler version
with string keys, and more general version with arbitrary
keys.

Location:
trunk/src2/core
Files:
2 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/src2/core/Lookup.cpp

    r441 r443  
    11/*
    22 * ======================================================================
    3  *  Rappture::Dictionary<keyType,valType>
     3 *  Rappture::Lookup<valType>
     4 *  Rappture::Lookup2<keyType,valType>
    45 *
    56 *  AUTHOR:  Michael McLennan, Purdue University
     
    6061 */
    6162#include <sstream>
    62 #include "Dictionary.h"
     63#include "Lookup.h"
    6364
    6465using namespace Rappture;
     
    7172
    7273
    73 DictionaryCore::DictionaryCore(size_t keySize)
     74LookupCore::LookupCore(size_t keySize)
    7475{
    7576    // convert key size in bytes to size in words
     
    8788}
    8889
    89 DictionaryCore::~DictionaryCore()
    90 {
    91     // free up all entries in the dictionary
     90LookupCore::~LookupCore()
     91{
     92    // free up all entries in the lookup table
    9293    for (int i = 0; i < _numBuckets; i++) {
    93         DictEntryCore *entryPtr = _buckets[i];
     94        LookupEntryCore *entryPtr = _buckets[i];
    9495        while (entryPtr != NULL) {
    95             DictEntryCore *nextPtr = entryPtr->nextPtr;
     96            LookupEntryCore *nextPtr = entryPtr->nextPtr;
    9697            delete entryPtr;
    9798            entryPtr = nextPtr;
     
    106107
    107108/**
    108  * Finds a dictionary entry with the specified key.  Returns
     109 * Finds a lookup entry with the specified key.  Returns
    109110 * the entry, or NULL if there was no matching entry.
    110111 */
    111 DictEntryCore*
    112 DictionaryCore::find(void* key)
     112LookupEntryCore*
     113LookupCore::find(void* key)
    113114{
    114115    unsigned int index = _hashIndex(key);
     
    117118    // Search all of the entries in the appropriate bucket.
    118119    //
    119     DictEntryCore *hPtr;
     120    LookupEntryCore *hPtr;
    120121    if (_keySize == 0) {
    121122        for (hPtr=_buckets[index]; hPtr != NULL; hPtr=hPtr->nextPtr) {
     
    150151
    151152/**
    152  * Finds a dictionary entry with the specified key.  Returns
     153 * Finds a lookup entry with the specified key.  Returns
    153154 * the entry, or NULL if there was no matching entry.
    154155 */
    155 DictEntryCore*
    156 DictionaryCore::get(void* key, int* newEntryPtr)
     156LookupEntryCore*
     157LookupCore::get(void* key, int* newEntryPtr)
    157158{
    158159    if (newEntryPtr) {
     
    165166    // Search all of the entries in the appropriate bucket.
    166167    //
    167     DictEntryCore *hPtr;
     168    LookupEntryCore *hPtr;
    168169    if (_keySize == 0) {
    169170        for (hPtr=_buckets[index]; hPtr != NULL; hPtr=hPtr->nextPtr) {
     
    202203    }
    203204    if (_keySize == 0) {
    204         char* mem = new char[sizeof(DictEntryCore)
     205        char* mem = new char[sizeof(LookupEntryCore)
    205206            + 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;
    210211    }
    211212    hPtr->dictPtr = this;
     
    233234
    234235/**
    235  * Removes an entry from the dictionary.  The data associated
    236  * with the entry is freed at the Dictionary level before calling
     236 * Removes an entry from the lookup table.  The data associated
     237 * with the entry is freed at the Lookup level before calling
    237238 * this core method to clean up the slot.
    238239 */
    239 DictEntryCore*
    240 DictionaryCore::erase(DictEntryCore* entryPtr)
    241 {
    242     DictEntryCore *prevPtr;
     240LookupEntryCore*
     241LookupCore::erase(LookupEntryCore* entryPtr)
     242{
     243    LookupEntryCore *prevPtr;
    243244
    244245    if (*entryPtr->bucketPtr == entryPtr) {
     
    254255    }
    255256    entryPtr->dictPtr->_numEntries--;
    256     DictEntryCore *nextPtr = entryPtr->nextPtr;
     257    LookupEntryCore *nextPtr = entryPtr->nextPtr;
    257258    delete entryPtr;
    258259
     
    266267 * helps keep track of the next bucket in the table.
    267268 */
    268 DictEntryCore*
    269 DictionaryCore::next(DictEntryCore *entryPtr, int& bucketNum)
     269LookupEntryCore*
     270LookupCore::next(LookupEntryCore *entryPtr, int& bucketNum)
    270271{
    271272    if (entryPtr) {
     
    285286
    286287/**
    287  * Returns a description of all entries in the dictionary.
     288 * Returns a description of all entries in the lookup table.
    288289 * Useful for debugging.
    289290 */
    290291std::string
    291 DictionaryCore::stats()
     292LookupCore::stats()
    292293{
    293294#define NUM_COUNTERS 10
     
    305306    for (i=0; i < _numBuckets; i++) {
    306307        int j=0;
    307         for (DictEntryCore *entryPtr=_buckets[i];
     308        for (LookupEntryCore *entryPtr=_buckets[i];
    308309             entryPtr != NULL;
    309310             entryPtr = entryPtr->nextPtr) {
     
    323324    //
    324325    std::ostringstream result;
    325     result << _numEntries << " entries in dictionary, ";
     326    result << _numEntries << " entries in lookup table, ";
    326327    result << _numBuckets << " buckets" << std::endl;
    327328
     
    342343 */
    343344void
    344 DictionaryCore::_rebuildBuckets()
     345LookupCore::_rebuildBuckets()
    345346{
    346347    int oldSize = _numBuckets;
    347     DictEntryCore** oldBuckets = _buckets;
     348    LookupEntryCore** oldBuckets = _buckets;
    348349
    349350    //
     
    352353    //
    353354    _numBuckets *= 4;
    354     _buckets = new (DictEntryCore*)[_numBuckets];
    355     DictEntryCore **newChainPtr = _buckets;
     355    _buckets = new (LookupEntryCore*)[_numBuckets];
     356    LookupEntryCore **newChainPtr = _buckets;
    356357    for (int count=_numBuckets; count > 0; count--, newChainPtr++) {
    357358        *newChainPtr = NULL;
     
    364365    // Rehash all of the existing entries into the new bucket array.
    365366    //
    366     for (DictEntryCore** oldChainPtr=oldBuckets;
     367    for (LookupEntryCore** oldChainPtr=oldBuckets;
    367368          oldSize > 0; oldSize--, oldChainPtr++) {
    368369
    369         for (DictEntryCore* hPtr=*oldChainPtr;
     370        for (LookupEntryCore* hPtr=*oldChainPtr;
    370371              hPtr != NULL; hPtr=*oldChainPtr) {
    371372
     
    390391 */
    391392unsigned int
    392 DictionaryCore::_hashIndex(void* key)
     393LookupCore::_hashIndex(void* key)
    393394{
    394395    unsigned int result = 0;
  • trunk/src2/core/Lookup.h

    r441 r443  
    11/*
    22 * ======================================================================
    3  *  Rappture::Dictionary<keyType,valType>
     3 *  Rappture::Lookup<valType>
     4 *  Rappture::Lookup2<keyType,valType>
    45 *
    56 *  AUTHOR:  Michael McLennan, Purdue University
     
    6970namespace Rappture {
    7071
    71 class DictionaryCore;  // foward declaration
     72class LookupCore;  // foward declaration
    7273
    7374/**
    74  * Represents one entry within a dictionary object, cast in terms
     75 * Represents one entry within a lookup object, cast in terms
    7576 * of void pointers and data sizes, so that the official, templated
    7677 * version of the class can be lean and mean.
    7778 */
    78 struct DictEntryCore {
    79     DictEntryCore *nextPtr;    // pointer to next entry in this bucket
    80     DictionaryCore *dictPtr;   // pointer to dictionary containing entry
    81     DictEntryCore **bucketPtr; // pointer to bucket containing this entry
    82 
    83     void *valuePtr;            // value within this hash entry
     79struct 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
    8485
    8586    union {
    86         void *ptrValue;        // size of a pointer
    87         int words[1];          // multiple integer words for the key
    88         char string[4];        // first part of string value for key
    89     } key;                     // memory can be oversized if more
    90                                // space is needed for words/string
    91                                // 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!
    9293};
    9394
    9495/**
    95  * This is the functional core of a dictionary object, cast in terms
     96 * This is the functional core of a lookup object, cast in terms
    9697 * of void pointers and data sizes, so that the official, templated
    9798 * version of the class can be lean and mean.
    9899 */
    99 class DictionaryCore {
     100class LookupCore {
    100101public:
    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);
    108109    std::string stats();
    109110
    110111private:
    111     /// Not allowed -- copy Dictionary at higher level
    112     DictionaryCore(const DictionaryCore& dcore) { assert(0); }
    113 
    114     /// Not allowed -- copy Dictionary at higher level
    115     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); }
    116117
    117118    // utility functions
     
    123124
    124125    /// Pointer to array of hash buckets.
    125     DictEntryCore **_buckets;
     126    LookupEntryCore **_buckets;
    126127
    127128    /// 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.
    131132    int _numEntries;
    132133
     
    145146
    146147/**
    147  * This represents a single entry within a dictionary object.  It is
    148  * used to access values within the dictionary, or as an iterator
    149  * 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.
    150151 */
    151152template <class KeyType, class ValType>
    152 class DictEntry {
     153class LookupEntry2 {
    153154public:
    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();
    158159
    159160    int isNull() const;
    160161    KeyType& key();
    161162    ValType& value();
    162     DictEntry& next();
    163     DictEntry& erase();
     163    LookupEntry2& next();
     164    LookupEntry2& erase();
    164165
    165166private:
    166     Ptr<DictionaryCore> _corePtr;
    167     DictEntryCore *_entryPtr;
     167    LookupCore* _corePtr;
     168    LookupEntryCore* _entryPtr;
    168169    int _bucketNum;
    169170};
    170171
    171172template <class KeyType, class ValType>
    172 DictEntry<KeyType,ValType>::DictEntry(Ptr<DictionaryCore> corePtr,
    173     DictEntryCore *entryPtr)
     173LookupEntry2<KeyType,ValType>::LookupEntry2(LookupCore* corePtr,
     174    LookupEntryCore* entryPtr)
    174175    : _corePtr(corePtr),
    175176      _entryPtr(entryPtr),
     
    179180
    180181template <class KeyType, class ValType>
    181 DictEntry<KeyType,ValType>::DictEntry(const DictEntry &entry)
     182LookupEntry2<KeyType,ValType>::LookupEntry2(const LookupEntry2 &entry)
    182183    : _corePtr(entry._corePtr),
    183184      _entryPtr(entry._entryPtr),
     
    187188
    188189template <class KeyType, class ValType>
    189 DictEntry<KeyType,ValType>&
    190 DictEntry<KeyType,ValType>::operator=(const DictEntry &entry)
     190LookupEntry2<KeyType,ValType>&
     191LookupEntry2<KeyType,ValType>::operator=(const LookupEntry2 &entry)
    191192{
    192193    _corePtr = entry._corePtr;
     
    197198
    198199template <class KeyType, class ValType>
    199 DictEntry<KeyType,ValType>::~DictEntry()
     200LookupEntry2<KeyType,ValType>::~LookupEntry2()
    200201{
    201202}
     
    203204template <class KeyType, class ValType>
    204205int
    205 DictEntry<KeyType,ValType>::isNull() const
     206LookupEntry2<KeyType,ValType>::isNull() const
    206207{
    207208    return (_entryPtr == NULL);
     
    210211template <class KeyType, class ValType>
    211212KeyType&
    212 DictEntry<KeyType,ValType>::key()
     213LookupEntry2<KeyType,ValType>::key()
    213214{
    214215    return *(KeyType*)(_entryPtr->key.string);
     
    217218template <class KeyType, class ValType>
    218219ValType&
    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()
     220LookupEntry2<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
     228template <class KeyType, class ValType>
     229LookupEntry2<KeyType,ValType>&
     230LookupEntry2<KeyType,ValType>::next()
    227231{
    228232    _entryPtr = _corePtr->next(_entryPtr, _bucketNum);
     
    231235
    232236template <class KeyType, class ValType>
    233 DictEntry<KeyType,ValType>&
    234 DictEntry<KeyType,ValType>::erase()
    235 {
    236     _entryPtr = _corePtr->erase(_entryPtr);
     237LookupEntry2<KeyType,ValType>&
     238LookupEntry2<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    }
    237249
    238250    if (_entryPtr == NULL) {
     251        // at the end of this bucket? then move on to next one
    239252        _corePtr->next(_entryPtr, _bucketNum);
    240253    }
     
    243256
    244257/**
    245  * This is a dictionary object or associative array.  It is a hash
     258 * This is a lookup object or associative array.  It is a hash
    246259 * table that uniquely maps a key to a value.  The memory for values
    247  * added to dictionary is managed by the dictionary.  When a dictionary
     260 * added to lookup is managed by the lookup.  When a lookup
    248261 * is deleted, its internal values are cleaned up automatically.
    249262 */
    250263template <class KeyType, class ValType>
    251 class Dictionary {
     264class Lookup2 {
    252265public:
    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);
    261275    void clear();
    262276
    263     DictEntry<KeyType,ValType> first();
     277    LookupEntry2<KeyType,ValType> first();
    264278
    265279    std::string stats();
    266280
    267281private:
    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
     285template <class KeyType, class ValType>
     286Lookup2<KeyType,ValType>::Lookup2(int size)
     287{
     288    _corePtr = new LookupCore( (size >= 0) ? size : sizeof(KeyType) );
     289}
     290
     291template <class KeyType, class ValType>
     292Lookup2<KeyType,ValType>::Lookup2(const Lookup2<KeyType,ValType>& dict)
     293{
     294    _corePtr = new LookupCore(sizeof(KeyType));
     295
     296    LookupEntry2<KeyType,ValType> entry;
    283297    for (entry=dict.first(); !entry.isNull(); entry.next()) {
    284298        get(entry.key(), NULL).value() = entry.value();
     
    287301
    288302template <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;
     303Lookup2<KeyType,ValType>&
     304Lookup2<KeyType,ValType>::operator=(const Lookup2<KeyType,ValType>& dict)
     305{
     306    _corePtr->clear();
     307
     308    LookupEntry2<KeyType,ValType> entry;
    295309    for (entry=dict.first(); !entry.isNull(); entry.next()) {
    296310        get(entry.key(), NULL).value() = entry.value();
     
    299313
    300314template <class KeyType, class ValType>
    301 Dictionary<KeyType,ValType>::~Dictionary()
     315Lookup2<KeyType,ValType>::~Lookup2()
    302316{
    303317    clear();
     318    delete _corePtr;
    304319}
    305320
    306321template <class KeyType, class ValType>
    307322void
    308 Dictionary<KeyType,ValType>::clear()
    309 {
    310     DictEntry<KeyType,ValType> entry = first();
     323Lookup2<KeyType,ValType>::clear()
     324{
     325    LookupEntry2<KeyType,ValType> entry = first();
    311326    while (!entry.isNull()) {
    312327        entry.erase();
     
    315330
    316331template <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) {
     332LookupEntry2<KeyType,ValType>
     333Lookup2<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)) {
    322338        entryPtr->valuePtr = new ValType;
    323339    }
    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
     343template <class KeyType, class ValType>
     344ValType&
     345Lookup2<KeyType,ValType>::operator[](const KeyType& key)
     346{
     347    LookupEntry2<KeyType,ValType> entry = get(key, NULL);
     348    return entry.value();
     349}
     350
     351template <class KeyType, class ValType>
     352LookupEntry2<KeyType,ValType>
     353Lookup2<KeyType,ValType>::first()
     354{
     355    LookupEntry2<KeyType,ValType> entry(_corePtr);
    332356    return entry.next();
    333357}
     
    335359template <class KeyType, class ValType>
    336360std::string
    337 Dictionary<KeyType,ValType>::stats()
     361Lookup2<KeyType,ValType>::stats()
    338362{
    339363    return _corePtr->stats();
    340364}
    341365
     366template <class ValType>
     367class LookupEntry : public LookupEntry2<const char*,ValType> {
     368public:
     369    LookupEntry(LookupCore* corePtr, LookupEntryCore* entryPtr=NULL);
     370    LookupEntry(const LookupEntry2<const char*,ValType>& entry);
     371};
     372
     373template <class ValType>
     374LookupEntry<ValType>::LookupEntry(LookupCore* corePtr,
     375    LookupEntryCore* entryPtr)
     376    : LookupEntry2<const char*,ValType>(corePtr, entryPtr)
     377{
     378}
     379
     380template <class ValType>
     381LookupEntry<ValType>::LookupEntry(
     382    const LookupEntry2<const char*,ValType>& entry)
     383    : LookupEntry2<const char*,ValType>(entry)
     384{
     385}
     386
     387template <class ValType>
     388class Lookup : public Lookup2<const char*,ValType> {
     389public:
     390    Lookup();
     391};
     392
     393template <class ValType>
     394Lookup<ValType>::Lookup()
     395    : Lookup2<const char*,ValType>(0)
     396{
     397}
    342398
    343399} // namespace Rappture
  • trunk/src2/core/Makefile

    r441 r443  
    88        g++ $(CFLAGS) -c -o viz.o viz.cc
    99
    10 test: test.o Ptr.o Outcome.o Dictionary.o
    11         g++ $(CFLAGS) -o test test.o Ptr.o Outcome.o Dictionary.o
     10test: test.o Ptr.o Outcome.o Lookup.o
     11        g++ $(CFLAGS) -o test test.o Ptr.o Outcome.o Lookup.o
    1212
    1313docs:
     
    2727        g++ $(CFLAGS) -c -o Outcome.o Outcome.cpp
    2828
    29 Dictionary.o: Dictionary.cpp Ptr.h
    30         g++ $(CFLAGS) -c -o Dictionary.o Dictionary.cpp
     29Lookup.o: Lookup.cpp Ptr.h
     30        g++ $(CFLAGS) -c -o Lookup.o Lookup.cpp
    3131
    3232RpMesh1D.o: RpMesh1D.cc RpMesh1D.h RpNode.h
  • trunk/src2/core/test.cc

    r441 r443  
    33#include <sstream>
    44#include "rappture.h"
    5 #include "Dictionary.h"
     5#include "Lookup.h"
    66
    77class Foo {
     
    4040    ptr.clear();
    4141
    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;
    4747
    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    }
    4954
    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();
    5466    }
    5567
Note: See TracChangeset for help on using the changeset viewer.