Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

DocListFileIterator.hpp

Go to the documentation of this file.
00001 /*==========================================================================
00002  * Copyright (c) 2004 University of Massachusetts.  All Rights Reserved.
00003  *
00004  * Use of the Lemur Toolkit for Language Modeling and Information Retrieval
00005  * is subject to the terms of the software license set forth in the LICENSE
00006  * file included with this software, and also available at
00007  * http://www.lemurproject.org/license.html
00008  *
00009  *==========================================================================
00010 */
00011 
00012 
00013 //
00014 // DocListFileIterator
00015 //
00016 // 9 January 2004 - tds
00017 //
00018 
00019 #ifndef INDRI_DOCLISTFILEITERATOR_HPP
00020 #define INDRI_DOCLISTFILEITERATOR_HPP
00021 
00022 #include "indri/DocListIterator.hpp"
00023 #include "indri/TermData.hpp"
00024 
00025 namespace indri {
00026   namespace index {
00027     class DocListFileIterator {
00028     public:
00029       struct DocListData {
00030         DocListIterator* iterator;
00031         TermData* termData;
00032       };
00033 
00034       struct iterator_greater {
00035         bool operator() ( const DocListFileIterator*const& one, const DocListFileIterator*const& two ) const {
00036           assert( !one->finished() && !two->finished() );
00037           
00038           const DocListData* oneData = one->currentEntry();
00039           const DocListData* twoData = two->currentEntry();
00040 
00041           const char* oneTerm = oneData->termData->term;
00042           const char* twoTerm = twoData->termData->term;
00043 
00044           int result = strcmp( oneTerm, twoTerm );
00045 
00046           // if terms don't match, we're done
00047           if( result < 0 )
00048             return false;
00049           if( result > 0 )
00050             return true;
00051 
00052           // terms match, so go by document
00053           lemur::api::DOCID_T oneDocument = oneData->iterator->currentEntry() ? oneData->iterator->currentEntry()->document : 0;
00054           lemur::api::DOCID_T twoDocument = twoData->iterator->currentEntry() ? twoData->iterator->currentEntry()->document : 0;
00055 
00056           return oneDocument > twoDocument;
00057         }
00058       };
00059 
00060       virtual ~DocListFileIterator() {};
00061       
00062       virtual bool finished() const = 0;
00063       virtual void startIteration() = 0;
00064 
00065       virtual bool nextEntry() = 0;
00066       virtual DocListData* currentEntry() = 0;
00067       virtual const DocListData* currentEntry() const = 0;
00068     };
00069   }
00070 }
00071 
00072 #endif // INDRI_DOCLISTITERATOR_HPP
00073 

Generated on Tue Jun 15 11:02:53 2010 for Lemur by doxygen 1.3.4