Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

ListCache.hpp

Go to the documentation of this file.
00001 
00002 //
00003 // ListCache
00004 //
00005 // 24 September 2004 -- tds
00006 //
00007 // Stores previously used precomputed lists.
00008 //
00009 
00010 #ifndef INDRI_LISTCACHE_HPP
00011 #define INDRI_LISTCACHE_HPP
00012 
00013 #include <vector>
00014 #include "indri/delete_range.hpp"
00015 #include "indri/SimpleCopier.hpp"
00016 #include "indri/DocumentCount.hpp"
00017 #include "indri/QuerySpec.hpp"
00018 #include "indri/TreePrinterWalker.hpp"
00019 #include "indri/Parameters.hpp"
00020 
00021 class ListCache {
00022 public:
00023   struct CachedList {
00024     // query structure
00025     SimpleCopier raw;
00026     SimpleCopier context;
00027 
00028     // postings
00029     greedy_vector<DocumentContextCount> entries;
00030 
00031     // statistics about the entries
00032     INT64 occurrences;
00033     INT64 contextSize;
00034     INT64 minimumContextSize;
00035     INT64 maximumContextSize;
00036     INT64 maximumOccurrences;
00037     float maximumContextFraction;
00038   };
00039 
00040 private:
00041   std::vector<struct CachedList*> _lists;
00042 
00043 public:
00044   ~ListCache() {
00045     delete_vector_contents( _lists );
00046   }
00047 
00048   void add( CachedList* list ) {
00049     if( _lists.size() > 100 ) {
00050       delete _lists[0];
00051       _lists.erase( _lists.begin() );
00052     }
00053 
00054     _lists.push_back( list );
00055   }
00056 
00057   CachedList* find( indri::lang::Node* raw, indri::lang::Node* context ) {
00058     ListCache::CachedList* list = 0;
00059     size_t i = 0;
00060 
00061     // TODO: use a hash function to make this faster
00062     for( i=0; i<_lists.size(); i++ ) {
00063       indri::lang::Node* cachedRaw = _lists[i]->raw.root();
00064       indri::lang::Node* cachedContext = _lists[i]->context.root();
00065 
00066       if( *cachedRaw == *raw ) {
00067         if( ( !cachedContext && !context ) ||
00068             ( cachedContext && context && (*context == *cachedContext)) ) {
00069           list = _lists[i];
00070           break;
00071         } 
00072       }
00073     }
00074 
00075     return list;
00076   }
00077 };
00078 
00079 #endif // INDRI_LISTCACHE_HPP
00080 
00081 

Generated on Wed Nov 3 12:58:59 2004 for Lemur Toolkit by doxygen1.2.18