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

Revision 9463, 2.5 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).

Line 
1/** @file contiguousalldocspostlist.cc
2 * @brief Iterate all document ids when they form a contiguous range.
3 */
4/* Copyright (C) 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 "contiguousalldocspostlist.h"
26
27#include "omassert.h"
28#include "utils.h"
29
30using namespace std;
31
32ContiguousAllDocsPostList::~ContiguousAllDocsPostList() { }
33
34Xapian::doccount
35ContiguousAllDocsPostList::get_termfreq() const
36{
37    return doccount;
38}
39
40Xapian::docid
41ContiguousAllDocsPostList::get_docid() const
42{
43    Assert(did != 0);
44    Assert(!at_end());
45    return did;
46}
47
48Xapian::doclength
49ContiguousAllDocsPostList::get_doclength() const
50{
51    Assert(did != 0);
52    Assert(!at_end());
53    return db->get_doclength(did);
54}
55
56Xapian::termcount
57ContiguousAllDocsPostList::get_wdf() const
58{
59    Assert(did != 0);
60    Assert(!at_end());
61    return 1;
62}
63
64PositionList *
65ContiguousAllDocsPostList::read_position_list()
66{
67    // Throws the same exception.
68    return ContiguousAllDocsPostList::open_position_list();
69}
70
71PositionList *
72ContiguousAllDocsPostList::open_position_list() const
73{
74    throw Xapian::InvalidOperationError("Position lists not meaningful for ContiguousAllDocsPostList");
75}
76
77PostList *
78ContiguousAllDocsPostList::next(Xapian::weight)
79{
80    Assert(!at_end());
81    if (did == doccount) {
82        db = NULL;
83    } else {
84        ++did;
85    }
86    return NULL;
87}
88
89PostList *
90ContiguousAllDocsPostList::skip_to(Xapian::docid target, Xapian::weight)
91{
92    Assert(!at_end());
93    if (target > did) {
94        if (target > doccount) {
95            db = NULL;
96        } else {
97            did = target;
98        }
99    }
100    return NULL;
101}
102
103bool
104ContiguousAllDocsPostList::at_end() const
105{
106    return db.get() == NULL;
107}
108
109string
110ContiguousAllDocsPostList::get_description() const
111{
112    string msg("ContiguousAllDocsPostList(1..");
113    msg += om_tostring(doccount);
114    msg += ')';
115    return msg;
116}
Note: See TracBrowser for help on using the browser.