Ignore:
Timestamp:
02/23/07 13:54:56 (17 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/HashPvs.h

    r2146 r2161  
    22#define __HASHPVS_H 
    33 
    4 //#include <hash_map> 
     4 
    55#include <hash_set> 
    66#include "common.h" 
    77#include <math.h> 
    88#include "PvsBase.h" 
     9#include "google/dense_hash_set" 
    910 
    1011 
     
    2526   size_t operator()(T a) const 
    2627   { 
    27       size_t h = (size_t)(a->GetId());// % 2000; 
    28       //for (; *s; ++s) 
    29       //   h = 5 * h + *s; 
    30       return h; 
     28           return (size_t)(a->GetId()); 
    3129   } 
    3230 
     
    3735}; 
    3836 
    39 /* 
    40 template<typename T> 
    41 struct gt 
    42 { 
    43         bool operator() (T s1, T s2) const 
    44         { 
    45                 return s1 > s2; 
    46         } 
    47 }; 
    48 */ 
    49 //#define HASH_SET stdext::hash_set<T, stdext::hash_compare<T, gt<T> > > 
    50 #define HASH_SET stdext::hash_set<T, my_hash_compare<T> > 
     37 
     38#define HASH_SET google::dense_hash_set<T, my_hash_compare<T> > 
     39//#define HASH_SET stdext::hash_set<T, my_hash_compare<T> > 
     40#define HASH_ITERATOR HASH_SET::iterator 
     41#define CONST_HASH_ITERATOR HASH_SET::const_iterator 
    5142 
    5243/** Iterator over a hash pvs. 
     
    5950        HashPvsIterator<T, S>() {} 
    6051 
    61         HashPvsIterator<T, S>(const typename HASH_SET::const_iterator &itCurrent, 
    62                                                   const typename HASH_SET::const_iterator &itEnd): 
     52        HashPvsIterator<T, S>(const typename CONST_HASH_ITERATOR &itCurrent, 
     53                                                  const typename CONST_HASH_ITERATOR &itEnd): 
    6354        mItCurrent(itCurrent), mItEnd(itEnd) 
    6455        { 
     
    7263        T Next(S &pdf) 
    7364        { 
    74                 // hack: create new pvs entry 
    75                 return *(mItCurrent) ++; 
     65                T sample = *mItCurrent; 
     66                ++ mItCurrent; 
     67 
     68                return sample; 
    7669        } 
    7770 
    7871        T Next() 
    7972        { 
    80                 // hack: create new pvs entry 
    81                 return *(mItCurrent) ++; 
     73                T sample = *mItCurrent; 
     74                ++ mItCurrent; 
     75 
     76                return sample; 
    8277        } 
    8378         
    8479private: 
    85         typename HASH_SET::const_iterator mItCurrent; 
    86         typename HASH_SET::const_iterator mItEnd; 
     80        typename CONST_HASH_ITERATOR mItCurrent; 
     81        typename CONST_HASH_ITERATOR mItEnd; 
    8782}; 
    8883 
     
    139134                it would be added in the sorted vector. 
    140135        */ 
    141         bool Find(T sample, typename HASH_SET::iterator &it); 
     136        inline bool Find(T sample, typename HASH_ITERATOR &it); 
    142137 
    143138        typename HashPvsIterator<T, S> GetIterator() const; 
     
    210205 
    211206template <typename T, typename S> 
    212 bool HashPvs<T, S>::Find(T sample, typename HASH_SET::iterator &it) 
     207bool HashPvs<T, S>::Find(T sample, typename HASH_ITERATOR &it) 
    213208{ 
    214209        it = mEntries.find(sample); 
     
    216211        // already in map 
    217212        return (it != mEntries.end()); 
     213        return false; 
    218214} 
    219215 
     
    236232float HashPvs<T, S>::AddSample(T sample, const float pdf) 
    237233{ 
    238         static HASH_SET::iterator it; 
     234        static HASH_ITERATOR it; 
    239235 
    240236        if (Find(sample, it)) 
     
    256252void HashPvs<T, S>::AddSampleDirty(T sample, const float pdf) 
    257253{ 
    258         static HASH_SET::iterator it; 
     254        static HASH_ITERATOR it; 
    259255 
    260256        // not yet in map 
     
    272268                                                                                const float pdf) 
    273269{ 
    274         /*pair<HASH_SET::iterator, bool> p = mEntries.insert(sample); 
     270        /*pair<HASH_ITERATOR, bool> p = mEntries.insert(sample); 
    275271 
    276272        // already in map 
    277273        return p.second; 
    278274*/ 
    279         static HASH_SET::iterator it; 
     275        static HASH_ITERATOR it; 
    280276 
    281277        // already in map 
     
    375371                                                  const HashPvs<T, S> &b) 
    376372{ 
    377         HASH_SET::const_iterator ait, ait_end = a.mEntries.end(); 
     373        CONST_HASH_ITERATOR ait, ait_end = a.mEntries.end(); 
    378374 
    379375        for (ait = a.mEntries.begin(); ait != ait_end; ++ ait) 
     
    382378        } 
    383379 
    384         HASH_SET::const_iterator bit, bit_end = b.mEntries.end(); 
     380        CONST_HASH_ITERATOR bit, bit_end = b.mEntries.end(); 
    385381 
    386382        for (bit = b.mEntries.begin(); bit != bit_end; ++ bit) 
     
    389385        } 
    390386 
    391         //cerr << "not implemented" << endl;  
    392387} 
    393388 
Note: See TracChangeset for help on using the changeset viewer.