xapian-core  1.4.26
vectortermlist.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2011,2012,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, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef XAPIAN_INCLUDED_VECTORTERMLIST_H
22 #define XAPIAN_INCLUDED_VECTORTERMLIST_H
23 
24 #include "xapian/types.h"
25 
26 #include "net/length.h"
27 #include "termlist.h"
28 
38 class VectorTermList : public TermList {
40  std::string data;
41 
43  const char * p;
44 
47 
49  std::string current_term;
50 
51  public:
52  template<typename I>
53  VectorTermList(I begin, I end) : num_terms(0)
54  {
55  // First calculate how much space we'll need so we can reserve it.
56  size_t total_size = 0;
57  for (I i = begin; i != end; ++i) {
58  ++num_terms;
59  const std::string & s = *i;
60  total_size += s.size() + 1;
61  if (s.size() >= 255) {
62  // Not a common case, so just assume the worst case rather than
63  // trying to carefully calculate the exact size.
64  total_size += 5;
65  }
66  }
67  data.reserve(total_size);
68 
69  // Now encode all the terms into data.
70  for (I i = begin; i != end; ++i) {
71  const std::string & s = *i;
72  data += encode_length(s.size());
73  data += s;
74  }
75 
76  p = data.data();
77  }
78 
80 
81  std::string get_termname() const;
82 
83  Xapian::termcount get_wdf() const;
84 
86 
87  TermList * next();
88 
89  TermList * skip_to(const std::string &);
90 
91  bool at_end() const;
92 
94 
96 };
97 
98 #endif // XAPIAN_INCLUDED_VECTORTERMLIST_H
TermList * next()
Advance the current position to the next term in the termlist.
typedefs for Xapian
length encoded as a string
Abstract base class for termlists.
Definition: termlist.h:39
Xapian::termcount get_approx_size() const
Return approximate size of this termlist.
std::string encode_length(T len)
Encode a length as a variable-length string.
Definition: length.h:36
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
VectorTermList(I begin, I end)
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
Xapian::termcount get_wdf() const
Return the wdf for the term at the current position.
Xapian::termcount num_terms
The number of terms in the list.
Xapian::PositionIterator positionlist_begin() const
Return a PositionIterator for the current position.
Class for iterating over term positions.
bool at_end() const
Return true if the current position is past the last term in this list.
This class stores a list of terms.
Xapian::termcount positionlist_count() const
Return the length of the position list for the current position.
std::string data
The encoded terms.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
Abstract base class for termlists.
const char * p
Pointer to the next term&#39;s data, or NULL if we are at end.
std::string current_term
The current term.
TermList * skip_to(const std::string &)
Skip forward to the specified term.
std::string get_termname() const
Return the termname at the current position.