xapian-core  2.0.0
multi.h
Go to the documentation of this file.
1 
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, see
18  * <https://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef XAPIAN_INCLUDED_MULTI_H
22 #define XAPIAN_INCLUDED_MULTI_H
23 
24 #include <xapian/types.h>
25 #include "omassert.h"
26 
34 inline Xapian::docid
36  Assert(did != 0);
37  Assert(n_shards != 0);
38  return (did - 1) / n_shards + 1;
39 }
40 
48 inline Xapian::doccount
50  Assert(did != 0);
51  Assert(n_shards != 0);
52  return Xapian::doccount((did - 1) % n_shards);
53 }
54 
63 inline Xapian::docid
65  Xapian::doccount shard,
66  Xapian::doccount n_shards) {
67  Assert(shard_did != 0);
68  AssertRel(shard,<,n_shards);
69  return (shard_did - 1) * n_shards + shard + 1;
70 }
71 
72 #endif // XAPIAN_INCLUDED_MULTI_H
Xapian::doccount shard_number(Xapian::docid did, Xapian::doccount n_shards)
Convert docid in the multi-db to shard number.
Definition: multi.h:49
Xapian::docid shard_docid(Xapian::docid did, Xapian::doccount n_shards)
Convert docid in the multi-db to the docid in the shard.
Definition: multi.h:35
Xapian::docid unshard(Xapian::docid shard_did, Xapian::doccount shard, Xapian::doccount n_shards)
Convert shard number and shard docid to docid in multi-db.
Definition: multi.h:64
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:37
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:51
Various assertion macros.
#define AssertRel(A, REL, B)
Definition: omassert.h:123
#define Assert(COND)
Definition: omassert.h:122
typedefs for Xapian