Ignore:
Timestamp:
01/23/07 00:11:50 (17 years ago)
Author:
bittner
Message:

merge

File:
1 edited

Legend:

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

    r2015 r2019  
    55#include <vector> 
    66#include "common.h" 
     7#include <math.h> 
     8using namespace std; 
    79 
    810namespace GtpVisibilityPreprocessor { 
     
    171173 
    172174public: 
    173  
    174         Pvs(): mSamples(0), mEntries(), mLastSorted(0) {} 
     175   
     176        Pvs(): mSamples(0), mEntries(), mLastSorted(0), mQueriesSinceSort(0) {} 
    175177 
    176178        /** creates pvs and initializes it with the given entries.  
     
    312314          // the last part should not be more than log of the sorted part. this 
    313315          // way we can achieve logarithmic behaviour for insertion and find 
    314           const int dirtySize = (int)mEntries.size() - mLastSorted; 
    315           return dirtySize > 500; 
    316           //              4*(int)(log((double)mEntries.size()) / log(2.0)); 
     316          const int n = mEntries.size(); 
     317          const int dirtySize = n - mLastSorted; 
     318 
     319#define LOG2E 1.442695040f 
     320           
     321          const float logN = log((float)max(1, n))/LOG2E; 
     322          const float logS = log((float)max(1, mLastSorted))/LOG2E; 
     323          const float logD = log((float)max(1, dirtySize))/LOG2E; 
     324           
     325          if (8*(n + 2*dirtySize*logD) < 
     326                  mQueriesSinceSort*((mLastSorted*logS + dirtySize*dirtySize/2)/n - logN)) { 
     327                //              cout<<"Q="<<mQueriesSinceSort<<" N="<<n<<" D="<<dirtySize<<endl; 
     328                return true; 
     329          } 
     330          return false; 
    317331        } 
    318332 
     
    342356   
    343357        /// Last sorted entry in the pvs (important for find and merge) 
    344         int mLastSorted;   
     358        int mLastSorted; 
     359 
     360  int mQueriesSinceSort; 
    345361}; 
    346362 
     
    367383        sort(it, newEnd); 
    368384        //sort(mEntries.begin(), mEntries.end()); 
    369  
     385         
    370386        // now merge sorted ranges 
    371387        ObjectPvs newPvs; 
    372388        Merge(newPvs,  
    373                   mEntries.begin(), it,  
    374                   it, newEnd,  
    375                   mSamples, 0); 
     389                  mEntries.begin(), 
     390                  it,  
     391                  it, 
     392                  newEnd,  
     393                  mSamples, 
     394                  0); 
    376395         
    377396        mEntries = newPvs.mEntries; 
    378397        mLastSorted = (int)mEntries.size(); 
     398        mQueriesSinceSort = 0; 
    379399} 
    380400 
     
    382402void Pvs<T, S>::SimpleSort() 
    383403{ 
    384   sort(mEntries.begin(), mEntries.end()); 
     404  //  sort(mEntries.begin(), mEntries.end()); 
     405  std::vector<PvsEntry<T, S> >::iterator it = mEntries.begin() + mLastSorted; 
     406   
     407  sort(it, mEntries.end()); 
     408  inplace_merge(mEntries.begin(), it, mEntries.end()); 
     409   
    385410  mLastSorted = (int)mEntries.size(); 
     411  mQueriesSinceSort = 0; 
    386412} 
    387413 
     
    610636{ 
    611637  PvsEntry<T, S> dummy(sample, PvsData()); 
     638  mQueriesSinceSort++; 
    612639   
    613640  // only check clean part 
Note: See TracChangeset for help on using the changeset viewer.