LCOV - code coverage report
Current view: top level - backends - multi.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 7822d31adece Lines: 6 6 100.0 %
Date: 2019-05-23 11:15:29 Functions: 3 3 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /** @file multi.h
       2                 :            :  * @brief Multi-database support functions
       3                 :            :  */
       4                 :            : /* Copyright (C) 2017 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_MULTI_H
      23                 :            : #define XAPIAN_INCLUDED_MULTI_H
      24                 :            : 
      25                 :            : #include <cstddef> // For std::size_t
      26                 :            : #include <xapian/types.h>
      27                 :            : #include "omassert.h"
      28                 :            : 
      29                 :            : /** Convert docid in the multi-db to the docid in the shard.
      30                 :            :  *
      31                 :            :  *  @param did          docid in the multi-db
      32                 :            :  *  @param n_shards     number of dbs in the multi-db
      33                 :            :  *
      34                 :            :  *  @return docid in the shard
      35                 :            :  */
      36                 :            : inline Xapian::docid
      37                 :   44027180 : shard_docid(Xapian::docid did, std::size_t n_shards) {
      38                 :            :     Assert(did != 0);
      39                 :            :     Assert(n_shards != 0);
      40                 :   44027180 :     return (did - 1) / n_shards + 1;
      41                 :            : }
      42                 :            : 
      43                 :            : /** Convert docid in the multi-db to shard number.
      44                 :            :  *
      45                 :            :  *  @param did          docid in the multi-db
      46                 :            :  *  @param n_shards     number of dbs in the multi-db
      47                 :            :  *
      48                 :            :  *  @return shard number between 0 and (n_shards - 1) inclusive
      49                 :            :  */
      50                 :            : inline size_t
      51                 :    9683810 : shard_number(Xapian::docid did, std::size_t n_shards) {
      52                 :            :     Assert(did != 0);
      53                 :            :     Assert(n_shards != 0);
      54                 :    9683810 :     return (did - 1) % n_shards;
      55                 :            : }
      56                 :            : 
      57                 :            : /** Convert shard number and shard docid to docid in multi-db.
      58                 :            :  *
      59                 :            :  *  @param shard_did    docid in the shard
      60                 :            :  *  @param shard        shard number between 0 and (n_shards - 1) inclusive
      61                 :            :  *  @param n_shards     number of dbs in the multi-db
      62                 :            :  *
      63                 :            :  *  @return docid in the multi-db.
      64                 :            :  */
      65                 :            : inline Xapian::docid
      66                 :   81872821 : unshard(Xapian::docid shard_did, std::size_t shard, std::size_t n_shards) {
      67                 :            :     Assert(shard_did != 0);
      68                 :            :     AssertRel(shard,<,n_shards);
      69                 :   81872821 :     return (shard_did - 1) * n_shards + shard + 1;
      70                 :            : }
      71                 :            : 
      72                 :            : #endif // XAPIAN_INCLUDED_MULTI_H

Generated by: LCOV version 1.11