xapian-core  2.1.0
inmemory_positionlist.cc
Go to the documentation of this file.
1 
4 /* Copyright 2017,2026 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 "clamp_cast.h"
26 #include "omassert.h"
27 
28 #include <algorithm>
29 
30 using namespace std;
31 
34 {
35  return clamp_cast<Xapian::termcount>(positions.size());
36 }
37 
40 {
41  return positions.back();
42 }
43 
46 {
47  AssertRel(index, <, positions.size());
48  return positions[index];
49 }
50 
51 bool
53 {
54  // We start index at size_t(-1) so the first increment gives 0.
55  UNSIGNED_OVERFLOW_OK(++index);
56  AssertRel(index, <=, positions.size());
57  return index != positions.size();
58 }
59 
60 bool
62 {
63  if (index == size_t(-1))
64  index = 0;
65  auto begin = positions.begin();
66  auto end = positions.end();
67  auto it = lower_bound(begin + index, end, termpos);
68  index = it - begin;
69  return it != end;
70 }
Cast a value to a type, clamping out of range values.
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:635
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