LCOV - code coverage report
Current view: top level - backends/multi - multi_valuelist.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 7028d852e609 Lines: 20 20 100.0 %
Date: 2019-02-17 14:59:59 Functions: 8 8 100.0 %
Branches: 3 4 75.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file multi_valuelist.h
       2                 :            :  * @brief Class for merging ValueList objects from subdatabases.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2007,2008,2009,2017 Olly Betts
       5                 :            :  *
       6                 :            :  * This program is free software; you can redistribute it and/or modify
       7                 :            :  * it under the terms of the GNU General Public License as published by
       8                 :            :  * the Free Software Foundation; either version 2 of the License, or
       9                 :            :  * (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 USA
      19                 :            :  */
      20                 :            : 
      21                 :            : #ifndef XAPIAN_INCLUDED_MULTI_VALUELIST_H
      22                 :            : #define XAPIAN_INCLUDED_MULTI_VALUELIST_H
      23                 :            : 
      24                 :            : #include "backends/valuelist.h"
      25                 :            : 
      26                 :            : #include "backends/databaseinternal.h"
      27                 :            : #include "backends/multi.h"
      28                 :            : 
      29                 :            : #include <string>
      30                 :            : 
      31                 :            : struct SubValueList {
      32                 :            :     ValueList * valuelist;
      33                 :            :     unsigned shard;
      34                 :            : 
      35                 :        500 :     SubValueList(ValueList * vl, unsigned shard_)
      36                 :        500 :         : valuelist(vl), shard(shard_) { }
      37                 :            : 
      38                 :        500 :     ~SubValueList() {
      39         [ +  - ]:        500 :         delete valuelist;
      40                 :        500 :     }
      41                 :            : 
      42                 :      53492 :     void skip_to(Xapian::docid did, size_t n_shards) {
      43                 :            :         // Calculate the docid in this shard which is the same or later than
      44                 :            :         // did (which may be in a different shard).
      45                 :      53492 :         Xapian::docid shard_did = shard_docid(did, n_shards);
      46         [ +  + ]:      53492 :         if (shard_number(did, n_shards) > shard)
      47                 :      11649 :             ++shard_did;
      48                 :      53492 :         valuelist->skip_to(shard_did);
      49                 :      53492 :     }
      50                 :            : 
      51                 :      53490 :     Xapian::docid get_docid() const {
      52                 :      53490 :         return valuelist->get_docid();
      53                 :            :     }
      54                 :            : 
      55                 :      26845 :     Xapian::docid get_merged_docid(unsigned n_shards) const {
      56                 :      26845 :         return unshard(valuelist->get_docid(), shard, n_shards);
      57                 :            :     }
      58                 :            : 
      59                 :      53230 :     std::string get_value() const { return valuelist->get_value(); }
      60                 :            : 
      61                 :        556 :     void next() {
      62                 :        556 :         valuelist->next();
      63                 :        555 :     }
      64                 :            : 
      65                 :     108094 :     bool at_end() const { return valuelist->at_end(); }
      66                 :            : };
      67                 :            : 
      68                 :            : /// Class for merging ValueList objects from subdatabases.
      69                 :            : class MultiValueList : public ValueList {
      70                 :            :     /// Don't allow assignment.
      71                 :            :     void operator=(const MultiValueList &);
      72                 :            : 
      73                 :            :     /// Don't allow copying.
      74                 :            :     MultiValueList(const MultiValueList &);
      75                 :            : 
      76                 :            :     /// Current docid (or 0 if we haven't started yet).
      77                 :            :     Xapian::docid current_docid = 0;
      78                 :            : 
      79                 :            :     /// Number of SubValueList* entries in valuelists.
      80                 :            :     size_t count;
      81                 :            : 
      82                 :            :     /// Array of sub-valuelists which we use as a heap.
      83                 :            :     SubValueList** valuelists;
      84                 :            : 
      85                 :            :     /// The value slot we're iterating over.
      86                 :            :     Xapian::valueno slot;
      87                 :            : 
      88                 :            :     size_t n_shards;
      89                 :            : 
      90                 :            :   public:
      91                 :            :     /// Constructor.
      92                 :            :     MultiValueList(size_t n_shards_,
      93                 :            :                    SubValueList** valuelists_,
      94                 :            :                    Xapian::valueno slot_);
      95                 :            : 
      96                 :            :     /// Destructor.
      97                 :            :     ~MultiValueList();
      98                 :            : 
      99                 :            :     /// Return the docid at the current position.
     100                 :            :     Xapian::docid get_docid() const;
     101                 :            : 
     102                 :            :     /// Return the value at the current position.
     103                 :            :     std::string get_value() const;
     104                 :            : 
     105                 :            :     /// Return the value slot for the current position/this iterator.
     106                 :            :     Xapian::valueno get_valueno() const;
     107                 :            : 
     108                 :            :     /// Return true if the current position is past the last entry in this list.
     109                 :            :     bool at_end() const;
     110                 :            : 
     111                 :            :     /** Advance the current position to the next document in the value stream.
     112                 :            :      *
     113                 :            :      *  The list starts before the first entry in the list, so next(),
     114                 :            :      *  skip_to() or check() must be called before any methods which need the
     115                 :            :      *  context of the current position.
     116                 :            :      */
     117                 :            :     void next();
     118                 :            : 
     119                 :            :     /** Skip forward to the specified docid.
     120                 :            :      *
     121                 :            :      *  If the specified docid isn't in the list, position ourselves on the
     122                 :            :      *  first document after it (or at_end() if no greater docids are present).
     123                 :            :      */
     124                 :            :     void skip_to(Xapian::docid);
     125                 :            : 
     126                 :            :     /** Check if the specified docid occurs in this valuestream.
     127                 :            :      *
     128                 :            :      *  The caller is required to ensure that the specified @a docid actually
     129                 :            :      *  exists in the database.
     130                 :            :      *
     131                 :            :      *  This method acts like skip_to() if that can be done at little extra
     132                 :            :      *  cost, in which case it then sets @a valid to true.
     133                 :            :      *
     134                 :            :      *  Otherwise it simply checks if a particular docid is present.  If it
     135                 :            :      *  is, it returns true.  If it isn't, it returns false, and leaves the
     136                 :            :      *  position unspecified (and hence the result of calling methods which
     137                 :            :      *  depend on the current position, such as get_docid(), are also
     138                 :            :      *  unspecified).  In this state, next() will advance to the first matching
     139                 :            :      *  position after @a docid, and skip_to() will act as it would if the
     140                 :            :      *  position was the first matching position after @a docid.
     141                 :            :      *
     142                 :            :      *  The default implementation calls skip_to().
     143                 :            :      */
     144                 :            :     bool check(Xapian::docid did);
     145                 :            : 
     146                 :            :     /// Return a string description of this object.
     147                 :            :     std::string get_description() const;
     148                 :            : };
     149                 :            : 
     150                 :            : #endif // XAPIAN_INCLUDED_MULTIVALUELIST_H

Generated by: LCOV version 1.11