xapian-core  2.0.0
inmemory_alltermslist.cc
Go to the documentation of this file.
1 
4 /* Copyright 1999,2000,2001 BrightStation PLC
5  * Copyright 2003,2004,2007,2008,2009,2017,2024 Olly Betts
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, see
19  * <https://www.gnu.org/licenses/>.
20  */
21 
22 #include <config.h>
23 #include "inmemory_alltermslist.h"
24 
25 #include "stringutils.h"
26 
27 using namespace std;
28 
31 {
32  // This may be an over-estimate due to deleted entries, and we may be
33  // restricted to a prefix, but we only use this value to build a balanced
34  // or-tree, and it'll do a decent job for that.
35  return tmap->size();
36 }
37 
40 {
41  if (database->is_closed()) InMemoryDatabase::throw_database_closed();
42  Assert(it != tmap->end());
43  Assert(!it->first.empty());
44  /* FIXME: this isn't quite right. */
45  return it->second.docs.size();
46 }
47 
48 TermList*
49 InMemoryAllTermsList::skip_to(string_view tname_)
50 {
51  if (database->is_closed()) InMemoryDatabase::throw_database_closed();
52  string tname(tname_);
53  Assert(it != tmap->end());
54  if (!it->first.empty()) {
55  // Don't skip backwards.
56  if (tname <= it->first) return NULL;
57  } else {
58  // Don't skip to before where we're supposed to start.
59  if (tname < prefix) {
60  tname = prefix;
61  } else if (tname.empty()) {
62  ++it;
63  while (it != tmap->end() && it->second.term_freq == 0) ++it;
64  if (it == tmap->end())
65  return this;
66  current_term = it->first;
67  return NULL;
68  }
69  }
70  it = tmap->lower_bound(tname);
71  while (it != tmap->end() && it->second.term_freq == 0) ++it;
72  if (it == tmap->end() || !startswith(it->first, prefix)) {
73  return this;
74  }
75  current_term = it->first;
76  return NULL;
77 }
78 
79 TermList *
81 {
82  if (database->is_closed()) InMemoryDatabase::throw_database_closed();
83  Assert(it != tmap->end());
84  if (it->first.empty() && !prefix.empty()) {
85  it = tmap->lower_bound(prefix);
86  } else {
87  ++it;
88  }
89  while (it != tmap->end() && it->second.term_freq == 0) ++it;
90  if (it == tmap->end() || !startswith(it->first, prefix)) {
91  return this;
92  }
93  current_term = it->first;
94  return NULL;
95 }
96 
97 #ifdef DISABLE_GPL_LIBXAPIAN
98 # error GPL source we cannot relicense included in libxapian
99 #endif
Xapian::termcount get_approx_size() const
Return approximate size of this termlist.
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
TermList * skip_to(std::string_view tname)
Skip forward to the specified term.
TermList * next()
next() causes the AllTermsList to move to the next term in the list.
static void throw_database_closed()
Abstract base class for termlists.
Definition: termlist.h:42
Iterate all terms in an inmemory db.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:37
#define Assert(COND)
Definition: omassert.h:122
Various handy string-related helpers.
bool startswith(std::string_view s, char pfx)
Definition: stringutils.h:56