xapian-core  1.4.26
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 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, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20  * USA
21  */
22 
23 #include <config.h>
24 #include "inmemory_alltermslist.h"
25 
26 #include "stringutils.h"
27 
28 string
30 {
32  Assert(!at_end());
33  Assert(!it->first.empty());
34  return it->first;
35 }
36 
39 {
41  Assert(!at_end());
42  Assert(!it->first.empty());
43  /* FIXME: this isn't quite right. */
44  return it->second.docs.size();
45 }
46 
47 TermList *
48 InMemoryAllTermsList::skip_to(const string &tname_)
49 {
51  string tname(tname_);
52  Assert(it != tmap->end());
53  if (!it->first.empty()) {
54  // Don't skip backwards.
55  if (tname <= it->first) return NULL;
56  } else {
57  // Don't skip to before where we're supposed to start.
58  if (tname < prefix) {
59  tname = prefix;
60  } else if (tname.empty()) {
61  ++it;
62  return NULL;
63  }
64  }
65  it = tmap->lower_bound(tname);
66  while (it != tmap->end() && it->second.term_freq == 0) ++it;
67  if (it != tmap->end() && !startswith(it->first, prefix))
68  it = tmap->end();
69  return NULL;
70 }
71 
72 TermList *
74 {
76  Assert(it != tmap->end());
77  if (it->first.empty() && !prefix.empty()) {
78  it = tmap->lower_bound(prefix);
79  } else {
80  ++it;
81  }
82  while (it != tmap->end() && it->second.term_freq == 0) ++it;
83  if (it != tmap->end() && !startswith(it->first, prefix))
84  it = tmap->end();
85  return NULL;
86 }
87 
88 bool
90 {
92  Assert(it == tmap->end() || !it->first.empty());
93  return (it == tmap->end());
94 }
#define Assert(COND)
Definition: omassert.h:122
std::map< string, InMemoryTerm >::const_iterator it
Iterate all terms in an inmemory db.
bool is_closed() const
Abstract base class for termlists.
Definition: termlist.h:39
Xapian::Internal::intrusive_ptr< const InMemoryDatabase > database
string get_termname() const
Return the termname at the current position.
bool at_end() const
Return true if the current position is past the last term in this list.
const std::map< string, InMemoryTerm > * tmap
bool startswith(const std::string &s, char pfx)
Definition: stringutils.h:51
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
TermList * next()
next() causes the AllTermsList to move to the next term in the list.
static void throw_database_closed()
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
Various handy helpers which std::string really should provide.
TermList * skip_to(const string &tname)
Skip forward to the specified term.