2 * @brief Class for merging ValueList objects from subdatabases.
4 /* Copyright (C) 2007,2008,2009,2017 Olly Betts
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.
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.
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
21 #ifndef XAPIAN_INCLUDED_MULTI_VALUELIST_H
22 #define XAPIAN_INCLUDED_MULTI_VALUELIST_H
24 #include "backends/valuelist.h"
26 #include "backends/databaseinternal.h"
27 #include "backends/multi.h"
32 ValueList
* valuelist
;
35 SubValueList(ValueList
* vl
, unsigned shard_
)
36 : valuelist(vl
), shard(shard_
) { }
42 void skip_to(Xapian::docid did
, Xapian::doccount n_shards
) {
43 // Calculate the docid in this shard which is the same or later than
44 // did (which may be in a different shard).
45 Xapian::docid shard_did
= shard_docid(did
, n_shards
);
46 if (shard_number(did
, n_shards
) > shard
)
48 valuelist
->skip_to(shard_did
);
51 Xapian::docid
get_docid() const {
52 return valuelist
->get_docid();
55 Xapian::docid
get_merged_docid(unsigned n_shards
) const {
56 return unshard(valuelist
->get_docid(), shard
, n_shards
);
59 std::string
get_value() const { return valuelist
->get_value(); }
65 bool at_end() const { return valuelist
->at_end(); }
68 /// Class for merging ValueList objects from subdatabases.
69 class MultiValueList
: public ValueList
{
70 /// Don't allow assignment.
71 void operator=(const MultiValueList
&);
73 /// Don't allow copying.
74 MultiValueList(const MultiValueList
&);
76 /// Current docid (or 0 if we haven't started yet).
77 Xapian::docid current_docid
= 0;
79 /// Number of SubValueList* entries in valuelists.
80 Xapian::doccount count
;
82 /// Array of sub-valuelists which we use as a heap.
83 SubValueList
** valuelists
;
85 /// The value slot we're iterating over.
88 Xapian::doccount n_shards
;
92 MultiValueList(Xapian::doccount n_shards_
,
93 SubValueList
** valuelists_
,
94 Xapian::valueno slot_
)
96 valuelists(valuelists_
),
105 /// Return the docid at the current position.
106 Xapian::docid
get_docid() const;
108 /// Return the value at the current position.
109 std::string
get_value() const;
111 /// Return the value slot for the current position/this iterator.
112 Xapian::valueno
get_valueno() const;
114 /// Return true if the current position is past the last entry in this list.
117 /** Advance the current position to the next document in the value stream.
119 * The list starts before the first entry in the list, so next(),
120 * skip_to() or check() must be called before any methods which need the
121 * context of the current position.
125 /** Skip forward to the specified docid.
127 * If the specified docid isn't in the list, position ourselves on the
128 * first document after it (or at_end() if no greater docids are present).
130 void skip_to(Xapian::docid
);
132 /** Check if the specified docid occurs in this valuestream.
134 * The caller is required to ensure that the specified @a docid actually
135 * exists in the database.
137 * This method acts like skip_to() if that can be done at little extra
138 * cost, in which case it then sets @a valid to true.
140 * Otherwise it simply checks if a particular docid is present. If it
141 * is, it returns true. If it isn't, it returns false, and leaves the
142 * position unspecified (and hence the result of calling methods which
143 * depend on the current position, such as get_docid(), are also
144 * unspecified). In this state, next() will advance to the first matching
145 * position after @a docid, and skip_to() will act as it would if the
146 * position was the first matching position after @a docid.
148 * The default implementation calls skip_to().
150 bool check(Xapian::docid did
);
152 /// Return a string description of this object.
153 std::string
get_description() const;
156 #endif // XAPIAN_INCLUDED_MULTIVALUELIST_H