xapian-core  2.0.0
honey_alldocspostlist.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2006,2007,2008,2009,2017,2018 Olly Betts
5  * Copyright (C) 2008 Lemur Consulting Ltd
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (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 #ifndef XAPIAN_INCLUDED_HONEY_ALLDOCSPOSTLIST_H
23 #define XAPIAN_INCLUDED_HONEY_ALLDOCSPOSTLIST_H
24 
25 #ifndef PACKAGE
26 # error config.h must be included first in each C++ source file
27 #endif
28 
29 #include "backends/leafpostlist.h"
30 #include "honey_defs.h"
31 #include "pack.h"
32 #include "wordaccess.h"
33 
34 #include <string>
35 
36 class HoneyCursor;
37 class HoneyDatabase;
38 
39 namespace Honey {
40 
42 inline std::string
44 {
45  std::string key(1, '\0');
46  Assert(last_did != 0);
47 #ifdef DO_CLZ
48  int width = (do_clz(last_did) >> 3) + 1;
49 #else
50  int width = 0;
51  for (auto v = last_did; v; v >>= 8) {
52  ++width;
53  }
54 #endif
55  key += char(Honey::KEY_DOCLEN_CHUNK + width - 1);
56  Xapian::docid v = last_did;
57 #ifndef WORDS_BIGENDIAN
58  v = do_bswap(v);
59 #endif
60  key.append(reinterpret_cast<const char*>(&v) + (sizeof(v) - width), width);
61  return key;
62 }
63 
64 inline Xapian::docid
65 docid_from_key(const std::string& key)
66 {
67  const char* p = key.data();
68  const char* end = p + key.length();
69  if (end - p < 3 || *p++ != '\0') {
70  // Not a doclen chunk key.
71  return 0;
72  }
73  unsigned char code = *p++;
74  if (code < Honey::KEY_DOCLEN_CHUNK || code > Honey::KEY_DOCLEN_CHUNK_HI) {
75  // Also not a doclen chunk key.
76  return 0;
77  }
78 
79  size_t width = (code - Honey::KEY_DOCLEN_CHUNK) + 1;
80  AssertEq(width, size_t(end - p));
81  Xapian::docid v = 0;
82  memcpy(reinterpret_cast<char*>(&v) + (sizeof(v) - width), p, width);
83 #ifndef WORDS_BIGENDIAN
84  v = do_bswap(v);
85 #endif
86  Assert(v != 0);
87  return v;
88 }
89 
91  unsigned const char* p = nullptr;
92  unsigned const char* end;
93 
95 
97 
98  unsigned width;
99 
100  bool read_doclen(const unsigned char* q);
101 
102  public:
105 
107  bool update(HoneyCursor* cursor);
108 
109  bool at_end() const { return p == NULL; }
110 
111  Xapian::docid get_docid() const { return did; }
112 
114 
115  bool next();
116 
117  bool skip_to(Xapian::docid target);
118 
126  bool find_doclength(Xapian::docid target);
127 
130  (void)read_doclen(end - width);
131  return doclen;
132  }
133 };
134 
135 }
136 
140 
143 
146 
148 
149  public:
151 
153 
154  Xapian::docid get_docid() const;
155 
156  Xapian::termcount get_wdf() const;
157 
158  bool at_end() const;
159 
160  PostList* next(double w_min);
161 
162  PostList* skip_to(Xapian::docid did, double w_min);
163 
164  PostList* check(Xapian::docid did, double w_min, bool& valid);
165 
167 
168  std::string get_description() const;
169 };
170 
171 #endif // XAPIAN_INCLUDED_HONEY_ALLDOCSPOSTLIST_H
HoneyAllDocsPostList(const HoneyAllDocsPostList &)=delete
Don't allow copying.
Xapian::docid get_docid() const
Return the current docid.
Honey::DocLenChunkReader reader
Xapian::termcount get_wdf_upper_bound() const
bool at_end() const
Return true if the current position is past the last entry in this list.
std::string get_description() const
Return a string description of this object.
Xapian::termcount get_wdf() const
Return the wdf for the document at the current position.
PostList * skip_to(Xapian::docid did, double w_min)
Skip forward to the specified docid.
PostList * check(Xapian::docid did, double w_min, bool &valid)
Check if the specified docid occurs in this postlist.
HoneyCursor * cursor
Cursor on the postlist table.
HoneyAllDocsPostList & operator=(const HoneyAllDocsPostList &)=delete
Don't allow assignment.
Database using honey backend.
Xapian::termcount back()
Return the last document length in this chunk.
bool find_doclength(Xapian::docid target)
Searches the whole chunk (skip_to() only advances).
bool update(HoneyCursor *cursor)
Update to use the chunk currently pointed to by cursor.
Xapian::termcount get_doclength() const
unsigned const char * end
Xapian::docid get_docid() const
bool read_doclen(const unsigned char *q)
DocLenChunkReader()
Create a DocLenChunkReader which is already at_end().
bool skip_to(Xapian::docid target)
Abstract base class for leaf postlists.
Definition: leafpostlist.h:40
Abstract base class for postlists.
Definition: postlist.h:40
PostList * next()
Advance the current position to the next document in the postlist.
Definition: postlist.h:168
PositionList * p
Definitions, types, etc for use inside honey.
Abstract base class for leaf postlists.
std::string make_doclenchunk_key(Xapian::docid last_did)
Generate a key for a doclen chunk.
Xapian::docid docid_from_key(const std::string &key)
@ KEY_DOCLEN_CHUNK
Definition: honey_defs.h:88
@ KEY_DOCLEN_CHUNK_HI
Definition: honey_defs.h:89
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
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:51
#define AssertEq(A, B)
Definition: omassert.h:124
#define Assert(COND)
Definition: omassert.h:122
Pack types into strings and unpack them again.
functions for reading and writing different width words
uint16_t do_bswap(uint16_t value)
Definition: wordaccess.h:43