root / tags / 1.0.8 / xapian-core / backends / flint / flint_alldocspostlist.cc

Revision 9463, 3.7 kB (checked in by olly, 15 months ago)

common/omassert.h: Rewritten from scratch. The new version only
includes headers if assertions are enabled, which should help
to speed up non-assertion builds by reducing unnecessary header
inclusion. Also, float.h and math.h are never now pulled in -
instead we use the new within_DBL_EPSILON() function. AssertNe?()
and AssertNeParanoid?() are never actually used, so replace them with
AssertRel?() and AssertRelParanoid? which allow the user to assert any
binary relation, not just inequality. Also, we now use rare() to
give branch prediction hints for assertion tests (since the failure
branch should never be taken).
common/omdebug.h,common/stringutils.h,tests/harness/testsuite.h:
Replace several definitions of the STRINGIZE macro with a single
version in common/stringutils.h.
backends/flint/,backends/inmemory/inmemory_database.cc,
backends/multi/multi_postlist.cc,backends/quartz/,
backends/remote/remote-database.cc,bin/quartzcheck.cc,
bin/xapian-compact.cc,common/stringutils.h,expand/expandweight.cc,
expand/ortermlist.cc,matcher/phrasepostlist.cc,
matcher/scaleweightpostlist.cc,net/remoteconnection.cc,
net/tcpserver.cc: Explicitly include headers which were previously
being pulled in implicitly by omassert.h.
HACKING: Update the documentation for assertion calls, and document
CompileTimeAssert?() (which previously wasn't documented here).

  • Property svn:eol-style set to native
Line 
1/** @file flint_alldocspostlist.cc
2 * @brief A PostList which iterates over all documents in a FlintDatabase.
3 */
4/* Copyright (C) 2006,2007 Olly Betts
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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#include <config.h>
22
23#include <string>
24
25#include "flint_database.h"
26#include "flint_alldocspostlist.h"
27
28#include "utils.h"
29
30using namespace std;
31
32FlintAllDocsPostList::~FlintAllDocsPostList()
33{
34}
35
36Xapian::doccount
37FlintAllDocsPostList::get_termfreq() const
38{
39    return doccount;
40}
41
42Xapian::docid
43FlintAllDocsPostList::get_docid() const
44{
45    return current_did;
46}
47
48Xapian::doclength
49FlintAllDocsPostList::get_doclength() const
50{
51    DEBUGCALL(DB, Xapian::doclength, "FlintAllDocsPostList::get_doclength", "");
52    Assert(current_did);
53
54    cursor->read_tag();
55
56    if (cursor->current_tag.empty()) RETURN(0);
57
58    const char * pos = cursor->current_tag.data();
59    const char * end = pos + cursor->current_tag.size();
60
61    flint_doclen_t doclen;
62    if (!unpack_uint(&pos, end, &doclen)) {
63        const char *msg;
64        if (pos == 0) {
65            msg = "Too little data for doclen in termlist";
66        } else {
67            msg = "Overflowed value for doclen in termlist";
68        }
69        throw Xapian::DatabaseCorruptError(msg);
70    }
71
72    RETURN(doclen);
73}
74
75Xapian::termcount
76FlintAllDocsPostList::get_wdf() const
77{
78    DEBUGCALL(DB, Xapian::termcount, "FlintAllDocsPostList::get_wdf", "");
79    Assert(current_did);
80    RETURN(1);
81}
82
83PostList *
84FlintAllDocsPostList::read_did_from_current_key()
85{
86    DEBUGCALL(DB, PostList *, "FlintAllDocsPostList::read_did_from_current_key",
87              "");
88    const string & key = cursor->current_key;
89    const char * pos = key.data();
90    const char * end = pos + key.size();
91    if (!unpack_uint_preserving_sort(&pos, end, &current_did)) {
92        const char *msg;
93        if (pos == 0) {
94            msg = "Too little data in termlist key";
95        } else {
96            msg = "Overflowed value in termlist key";
97        }
98        throw Xapian::DatabaseCorruptError(msg);
99    }
100
101    // Return NULL to help the compiler tail-call optimise our callers.
102    RETURN(NULL);
103}
104
105PostList *
106FlintAllDocsPostList::next(Xapian::weight /*w_min*/)
107{
108    DEBUGCALL(DB, PostList *, "FlintAllDocsPostList::next", "/*w_min*/");
109    Assert(!at_end());
110    if (!cursor->next()) RETURN(NULL);
111    RETURN(read_did_from_current_key());
112}
113
114PostList *
115FlintAllDocsPostList::skip_to(Xapian::docid did, Xapian::weight /*w_min*/)
116{
117    DEBUGCALL(DB, PostList *, "FlintAllDocsPostList::skip_to",
118              did << ", /*w_min*/");
119
120    if (did <= current_did || at_end()) RETURN(NULL);
121
122    if (cursor->find_entry_ge(pack_uint_preserving_sort(did))) {
123        // The exact docid that was asked for exists.
124        current_did = did;
125        RETURN(NULL);
126    }
127    if (cursor->after_end()) RETURN(NULL);
128
129    RETURN(read_did_from_current_key());
130}
131
132bool
133FlintAllDocsPostList::at_end() const {
134    DEBUGCALL(DB, bool, "FlintAllDocsPostList::at_end", "");
135    RETURN(cursor->after_end());
136}
137
138string
139FlintAllDocsPostList::get_description() const
140{
141    string desc = "FlintAllDocsPostList(did=";
142    desc += om_tostring(current_did);
143    desc += ",doccount=";
144    desc += om_tostring(doccount);
145    desc += ')';
146    return desc;
147}
Note: See TracBrowser for help on using the browser.