LCOV - code coverage report
Current view: top level - backends/honey - honey_positionlist.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core eba1a2e3082b Lines: 16 22 72.7 %
Date: 2019-06-13 13:35:36 Functions: 9 11 81.8 %
Branches: 7 16 43.8 %

           Branch data     Line data    Source code
       1                 :            : /** @file honey_positionlist.h
       2                 :            :  * @brief A position list in a honey database.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2005,2006,2008,2009,2010,2011,2013,2016,2017,2019 Olly Betts
       5                 :            :  *
       6                 :            :  * This program is free software; you can redistribute it and/or
       7                 :            :  * modify it under the terms of the GNU General Public License as
       8                 :            :  * published by the Free Software Foundation; either version 2 of the
       9                 :            :  * License, or (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This program is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this program; if not, write to the Free Software
      18                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
      19                 :            :  * USA
      20                 :            :  */
      21                 :            : 
      22                 :            : #ifndef XAPIAN_INCLUDED_HONEY_POSITIONLIST_H
      23                 :            : #define XAPIAN_INCLUDED_HONEY_POSITIONLIST_H
      24                 :            : 
      25                 :            : #include <xapian/types.h>
      26                 :            : 
      27                 :            : #include "backends/positionlist.h"
      28                 :            : #include "bitstream.h"
      29                 :            : #include "honey_cursor.h"
      30                 :            : #include "honey_lazytable.h"
      31                 :            : #include "pack.h"
      32                 :            : 
      33                 :            : #include <string>
      34                 :            : 
      35                 :            : using namespace std;
      36                 :            : 
      37                 :        610 : class HoneyPositionTable : public HoneyLazyTable {
      38                 :            :   public:
      39                 :       4463 :     static string make_key(Xapian::docid did, const string & term) {
      40                 :       4463 :         string key;
      41         [ +  - ]:       4463 :         pack_string_preserving_sort(key, term);
      42         [ +  - ]:       4463 :         pack_uint_preserving_sort(key, did);
      43                 :       4463 :         return key;
      44                 :            :     }
      45                 :            : 
      46                 :            :     /** Create a new HoneyPositionTable object.
      47                 :            :      *
      48                 :            :      *  This method does not create or open the table on disk - you
      49                 :            :      *  must call the create() or open() methods respectively!
      50                 :            :      *
      51                 :            :      *  @param dbdir            The directory the honey database is stored in.
      52                 :            :      *  @param readonly         true if we're opening read-only, else false.
      53                 :            :      */
      54                 :        304 :     HoneyPositionTable(const string & dbdir, bool readonly)
      55         [ +  - ]:        304 :         : HoneyLazyTable("position", dbdir + "/position.", readonly) { }
      56                 :            : 
      57                 :          1 :     HoneyPositionTable(int fd, off_t offset_, bool readonly_)
      58                 :          1 :         : HoneyLazyTable("position", fd, offset_, readonly_) { }
      59                 :            : 
      60                 :            :     /** Pack a position list into a string.
      61                 :            :      *
      62                 :            :      *  @param s The string to append the position list data to.
      63                 :            :      */
      64                 :            :     void pack(string & s, const Xapian::VecCOW<Xapian::termpos> & vec) const;
      65                 :            : 
      66                 :            :     /** Set the position list for term tname in document did.
      67                 :            :      */
      68                 :          0 :     void set_positionlist(Xapian::docid did, const string & tname,
      69                 :            :                           const string & s) {
      70         [ #  # ]:          0 :         add(make_key(did, tname), s);
      71                 :          0 :     }
      72                 :            : 
      73                 :            :     /// Delete the position list for term tname in document did.
      74                 :          0 :     void delete_positionlist(Xapian::docid did, const string & tname) {
      75                 :          0 :         del(make_key(did, tname));
      76                 :          0 :     }
      77                 :            : 
      78                 :            :     /// Return the number of entries in specified position list.
      79                 :            :     Xapian::termcount positionlist_count(Xapian::docid did,
      80                 :            :                                          const string & term) const;
      81                 :            : };
      82                 :            : 
      83                 :            : /** Base-class for a position list in a honey database. */
      84         [ -  + ]:       5678 : class HoneyBasePositionList : public PositionList {
      85                 :            :     /// Copying is not allowed.
      86                 :            :     HoneyBasePositionList(const HoneyBasePositionList&) = delete;
      87                 :            : 
      88                 :            :     /// Assignment is not allowed.
      89                 :            :     HoneyBasePositionList& operator=(const HoneyBasePositionList&) = delete;
      90                 :            : 
      91                 :            :   protected:
      92                 :            :     /// Interpolative decoder.
      93                 :            :     BitReader rd;
      94                 :            : 
      95                 :            :     /// Current entry.
      96                 :            :     Xapian::termpos current_pos;
      97                 :            : 
      98                 :            :     /// Last entry.
      99                 :            :     Xapian::termpos last;
     100                 :            : 
     101                 :            :     /// Number of entries.
     102                 :            :     Xapian::termcount size;
     103                 :            : 
     104                 :            :     /// Have we started iterating yet?
     105                 :            :     bool have_started;
     106                 :            : 
     107                 :            :     /** Set positional data and start to decode it.
     108                 :            :      *
     109                 :            :      *  @param data     The positional data.  Must stay valid
     110                 :            :      *                  while this object is using it.
     111                 :            :      */
     112                 :            :     void set_data(const string& data);
     113                 :            : 
     114                 :            :   public:
     115                 :            :     /// Default constructor.
     116                 :       5678 :     HoneyBasePositionList() {}
     117                 :            : 
     118                 :            :     /// Returns size of position list.
     119                 :            :     Xapian::termcount get_approx_size() const;
     120                 :            : 
     121                 :            :     Xapian::termpos back() const;
     122                 :            : 
     123                 :            :     /** Returns current position.
     124                 :            :      *
     125                 :            :      *  Either next() or skip_to() must have been called before this
     126                 :            :      *  method can be called.
     127                 :            :      */
     128                 :            :     Xapian::termpos get_position() const;
     129                 :            : 
     130                 :            :     /// Advance to the next term position in the list.
     131                 :            :     bool next();
     132                 :            : 
     133                 :            :     /// Advance to the first term position which is at least termpos.
     134                 :            :     bool skip_to(Xapian::termpos termpos);
     135                 :            : };
     136                 :            : 
     137                 :            : /** A position list in a honey database. */
     138         [ -  + ]:      10560 : class HoneyPositionList : public HoneyBasePositionList {
     139                 :            :     /// The encoded positional data being read by rd.
     140                 :            :     std::string pos_data;
     141                 :            : 
     142                 :            :     /// Copying is not allowed.
     143                 :            :     HoneyPositionList(const HoneyPositionList&) = delete;
     144                 :            : 
     145                 :            :     /// Assignment is not allowed.
     146                 :            :     HoneyPositionList& operator=(const HoneyPositionList&) = delete;
     147                 :            : 
     148                 :            :   public:
     149                 :            :     /// Construct and initialise with data.
     150                 :            :     explicit
     151                 :            :     HoneyPositionList(string&& data);
     152                 :            : 
     153                 :            :     /// Construct and initialise with data.
     154                 :            :     HoneyPositionList(const HoneyTable& table,
     155                 :            :                       Xapian::docid did,
     156                 :            :                       const string& term);
     157                 :            : };
     158                 :            : 
     159                 :            : /** A reusable position list in a honey database. */
     160         [ -  + ]:        396 : class HoneyRePositionList : public HoneyBasePositionList {
     161                 :            :     /// Cursor for locating multiple entries efficiently.
     162                 :            :     HoneyCursor cursor;
     163                 :            : 
     164                 :            :     /// Copying is not allowed.
     165                 :            :     HoneyRePositionList(const HoneyRePositionList&) = delete;
     166                 :            : 
     167                 :            :     /// Assignment is not allowed.
     168                 :            :     HoneyRePositionList& operator=(const HoneyRePositionList&) = delete;
     169                 :            : 
     170                 :            :   public:
     171                 :            :     /// Constructor.
     172                 :            :     explicit
     173                 :        198 :     HoneyRePositionList(const HoneyTable& table)
     174         [ +  - ]:        198 :         : cursor(&table) {}
     175                 :            : 
     176                 :            :     /** Fill list with data, and move the position to the start. */
     177                 :            :     void assign_data(string&& data);
     178                 :            : 
     179                 :            :     /** Fill list with data, and move the position to the start. */
     180                 :            :     void read_data(Xapian::docid did, const string& term);
     181                 :            : };
     182                 :            : 
     183                 :            : #endif /* XAPIAN_INCLUDED_HONEY_POSITIONLIST_H */

Generated by: LCOV version 1.11