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

FieldListDiskBlockReader.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 // FieldListDiskBlockReader.hpp
00015 //
00016 // 10 February 2004 -- tds
00017 //
00018 
00019 #ifndef INDRI_KEYFILEFIELDLISTDISKBLOCKREADER_HPP
00020 #define INDRI_KEYFILEFIELDLISTDISKBLOCKREADER_HPP
00021 
00022 #include "indri/Extent.hpp"
00023 #include "indri/FieldListDiskBlockWriter.hpp"
00024 
00025 class FieldListDiskBlockReader {
00026 private:
00027   Extent _extent;
00028   const char* _current;
00029   const char* _block;
00030   int _extentCount;
00031   int _document;
00032   int _endByte;
00033   bool _numeric;
00034   INT64 _number;
00035 
00036 public:
00037   void setBlock( const char* block ) {
00038     _block = block;
00039     _current = block;
00040     _document = 0;
00041     _extentCount = 0;
00042     _extent.begin = 0;
00043     _extent.end = 0;
00044     _number = 0;
00045 
00046     int endAndNumeric = * (int*) ( _block + INDRI_FIELDLIST_BLOCKSIZE - 2*sizeof(int) );
00047     _numeric = (endAndNumeric & 0x80000000) ? true : false;
00048     _endByte = endAndNumeric & 0x7fffffff;
00049   }
00050 
00051   int lastDocument() {
00052     return * (int*) ( _block + INDRI_FIELDLIST_BLOCKSIZE - sizeof(int) );
00053   }
00054 
00055   bool next() {
00056     if( ! _extentCount ) {
00057       if( !hasMore() )
00058         return false;
00059 
00060       int documentDelta;
00061 
00062       _current = RVLCompress::decompress_int( _current, documentDelta );
00063       _current = RVLCompress::decompress_int( _current, _extentCount );
00064       _document += documentDelta;
00065     
00066       _extent.begin = 0;
00067       _extent.end = 0;
00068     }
00069 
00070     int beginDelta;
00071     int endDelta;
00072 
00073     _current = RVLCompress::decompress_int( _current, beginDelta );
00074     _current = RVLCompress::decompress_int( _current, endDelta );
00075 
00076     if( _numeric ) {
00077       _current = RVLCompress::decompress_longlong( _current, _number );
00078     }
00079 
00080     assert( _current < _block + INDRI_FIELDLIST_BLOCKSIZE );
00081 
00082     _extentCount--;
00083     _extent.begin = _extent.end + beginDelta;
00084     _extent.end = _extent.begin + endDelta;
00085     return true;
00086   }
00087 
00088   int document() const {
00089     return _document;
00090   }
00091 
00092   INT64 number() const {
00093     return _number;
00094   }
00095 
00096   const Extent& extent() const {
00097     return _extent;
00098   }
00099 
00100   bool hasMore() {
00101     return _endByte > _current - _block;
00102   }
00103 };
00104 
00105 #endif // INDRI_FIELDLISTDISKBLOCKREADER_HPP

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