xapian-core  2.1.0
rset.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2017,2026 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  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, see
16  * <https://www.gnu.org/licenses/>.
17  */
18 
19 #include <config.h>
20 
21 #include <xapian/rset.h>
22 
23 #include "clamp_cast.h"
24 #include "rsetinternal.h"
25 #include "str.h"
26 
27 #include <string>
28 
29 using namespace std;
30 
31 namespace Xapian {
32 
33 RSet::RSet(const RSet&) = default;
34 
35 RSet&
36 RSet::operator=(const RSet&) = default;
37 
38 RSet::RSet(RSet &&) = default;
39 
40 RSet&
41 RSet::operator=(RSet &&) = default;
42 
43 RSet::RSet() {}
44 
45 RSet::RSet(Internal* internal_) : internal(internal_) {}
46 
48 
50 RSet::size() const
51 {
52  return internal ? clamp_cast<Xapian::doccount>(internal->docs.size()) : 0;
53 }
54 
55 void
57 {
58  if (rare(did == 0))
59  throw Xapian::InvalidArgumentError("Docid 0 not valid in an RSet");
60  if (!internal)
61  internal = new RSet::Internal;
62  internal->docs.insert(did);
63 }
64 
65 void
67 {
68  if (rare(did == 0))
69  throw Xapian::InvalidArgumentError("Docid 0 not valid in an RSet");
70  if (internal)
71  internal->docs.erase(did);
72 }
73 
74 bool
76 {
77  return internal && internal->docs.find(did) != internal->docs.end();
78 }
79 
80 string
82 {
83  string desc = "RSet(";
84  if (!internal || internal->docs.empty()) {
85  desc += ')';
86  } else {
87  for (auto&& did : internal->docs) {
88  desc += str(did);
89  desc += ',';
90  }
91  desc.back() = ')';
92  }
93  return desc;
94 }
95 
96 }
Cast a value to a type, clamping out of range values.
InvalidArgumentError indicates an invalid parameter value was passed to the API.
Definition: error.h:229
std::set< Xapian::docid > docs
Definition: rsetinternal.h:36
Xapian::Internal::intrusive_ptr< Internal > internal
Definition: rset.h:42
void add_document(Xapian::docid did)
Mark a document as relevant.
Definition: rset.cc:56
~RSet()
Destructor.
Definition: rset.cc:47
void remove_document(Xapian::docid did)
Unmark a document as relevant.
Definition: rset.cc:66
Xapian::doccount size() const
Return number of documents in this RSet object.
Definition: rset.cc:50
bool contains(Xapian::docid did) const
Check if a document is marked as relevant.
Definition: rset.cc:75
std::string get_description() const
Return a string describing this object.
Definition: rset.cc:81
#define rare(COND)
Definition: config.h:616
string str(int value)
Convert int to std::string.
Definition: str.cc:91
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
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
Set of documents judged as relevant.
Set of documents judged as relevant.
Convert types to std::string.