xapian-core  2.0.0
inmemory_positionlist.cc
Go to the documentation of this file.
1 
4 /* Copyright 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 #include <config.h>
22 
23 #include "inmemory_positionlist.h"
24 
25 #include "omassert.h"
26 
27 #include <algorithm>
28 
29 using namespace std;
30 
33 {
34  return positions.size();
35 }
36 
39 {
40  return positions.back();
41 }
42 
45 {
46  AssertRel(index, <, positions.size());
47  return positions[index];
48 }
49 
50 bool
52 {
53  // We start index at size_t(-1) so the first increment gives 0.
54  UNSIGNED_OVERFLOW_OK(++index);
55  AssertRel(index, <=, positions.size());
56  return index != positions.size();
57 }
58 
59 bool
61 {
62  if (index == size_t(-1))
63  index = 0;
64  auto begin = positions.begin();
65  auto end = positions.end();
66  auto it = lower_bound(begin + index, end, termpos);
67  index = it - begin;
68  return it != end;
69 }
Xapian::termpos back() const
Return the final entry in this positionlist.
bool skip_to(Xapian::termpos termpos)
Skip forward to the specified position.
Xapian::termpos get_position() const
Return the current position.
Xapian::termcount get_approx_size() const
Return approximate size of this positionlist.
bool next()
Advance to the next entry in the positionlist.
#define UNSIGNED_OVERFLOW_OK(X)
Definition: config.h:626
PositionList from an InMemory DB or a Document object.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
Definition: types.h:75
Various assertion macros.
#define AssertRel(A, REL, B)
Definition: omassert.h:123