LCOV - code coverage report
Current view: top level - api - rsetinternal.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core fcfb185a9dd5 Lines: 11 11 100.0 %
Date: 2019-04-18 16:33:14 Functions: 3 3 100.0 %
Branches: 12 16 75.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file rsetinternal.h
       2                 :            :  * @brief Set of documents judged as relevant
       3                 :            :  */
       4                 :            : /* Copyright (C) 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                 :            :  *
      14                 :            :  * You should have received a copy of the GNU General Public License
      15                 :            :  * along with this program; if not, write to the Free Software
      16                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
      17                 :            :  */
      18                 :            : 
      19                 :            : #ifndef XAPIAN_INCLUDED_RSETINTERNAL_H
      20                 :            : #define XAPIAN_INCLUDED_RSETINTERNAL_H
      21                 :            : 
      22                 :            : #include <xapian/rset.h>
      23                 :            : 
      24                 :            : #include "backends/multi.h"
      25                 :            : 
      26                 :            : #include <set>
      27                 :            : #include <vector>
      28                 :            : 
      29                 :            : namespace Xapian {
      30                 :            : 
      31                 :        904 : class RSet::Internal : public Xapian::Internal::intrusive_base {
      32                 :            :   public:
      33                 :            :     // We want to be able to iterate the contents in docid order, and we don't
      34                 :            :     // expect people to mark vast numbers of documents as relevant, so use
      35                 :            :     // std::set rather than std::unordered_set.
      36                 :            :     std::set<Xapian::docid> docs;
      37                 :            : 
      38                 :         75 :     void shard(size_t n_shards, std::vector<Xapian::RSet>& rsets) {
      39 [ +  + ][ -  + ]:         75 :         if (n_shards == 1 || docs.empty()) {
                 [ +  + ]
      40                 :            :             // Either there's a single database (in which case we just need
      41                 :            :             // to return ourself as the sharded RSet), or there are no relevance
      42                 :            :             // judgements (in which case we can use ourself as the internals for
      43                 :            :             // all the empty sharded RSets).
      44         [ +  - ]:         52 :             rsets.resize(n_shards, RSet(this));
      45                 :         75 :             return;
      46                 :            :         }
      47                 :            : 
      48                 :            :         // Using resize() here would result in all the entries having the same
      49                 :            :         // internals.
      50                 :         23 :         rsets.reserve(n_shards);
      51         [ +  + ]:         69 :         for (size_t i = 0; i < n_shards; ++i) {
      52         [ +  - ]:         46 :             rsets.emplace_back(RSet());
      53                 :            :         }
      54                 :            : 
      55         [ +  + ]:         54 :         for (auto&& did : docs) {
      56                 :         31 :             Xapian::docid shard_did = shard_docid(did, n_shards);
      57         [ +  - ]:         31 :             rsets[shard_number(did, n_shards)].add_document(shard_did);
      58                 :            :         }
      59                 :            :     }
      60                 :            : };
      61                 :            : 
      62                 :            : }
      63                 :            : 
      64                 :            : #endif // XAPIAN_INCLUDED_RSETINTERNAL_H

Generated by: LCOV version 1.11