Branch data Line data Source code
1 : : /** @file rset.cc
2 : : * @brief Set of documents judged as relevant
3 : : */
4 : : /* Copyright (C) 2017 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, write to the Free Software
16 : : * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 : : */
18 : :
19 : : #include <config.h>
20 : :
21 : : #include <xapian/rset.h>
22 : :
23 : : #include "rsetinternal.h"
24 : : #include "str.h"
25 : :
26 : : #include <string>
27 : :
28 : : using namespace std;
29 : :
30 : : namespace Xapian {
31 : :
32 : : RSet::RSet(const RSet&) = default;
33 : :
34 : : RSet&
35 : : RSet::operator=(const RSet&) = default;
36 : :
37 : : RSet::RSet(RSet &&) = default;
38 : :
39 : : RSet&
40 : : RSet::operator=(RSet &&) = default;
41 : :
42 : 397878 : RSet::RSet() {}
43 : :
44 : 104 : RSet::RSet(Internal* internal_) : internal(internal_) {}
45 : :
46 : 398182 : RSet::~RSet() {}
47 : :
48 : : Xapian::doccount
49 : 178515 : RSet::size() const
50 : : {
51 [ + + ]: 178515 : return internal.get() ? internal->docs.size() : 0;
52 : : }
53 : :
54 : : void
55 : 335 : RSet::add_document(Xapian::docid did)
56 : : {
57 [ + + ]: 335 : if (rare(did == 0))
58 [ + - ][ + - ]: 2 : throw Xapian::InvalidArgumentError("Docid 0 not valid in an RSet");
[ + - ]
59 [ + + ]: 333 : if (!internal.get())
60 [ + - ]: 226 : internal = new RSet::Internal;
61 : 333 : internal->docs.insert(did);
62 : 333 : }
63 : :
64 : : void
65 : 0 : RSet::remove_document(Xapian::docid did)
66 : : {
67 [ # # ]: 0 : if (rare(did == 0))
68 [ # # ][ # # ]: 0 : throw Xapian::InvalidArgumentError("Docid 0 not valid in an RSet");
[ # # ]
69 [ # # ]: 0 : if (internal.get())
70 : 0 : internal->docs.erase(did); }
71 : :
72 : : bool
73 : 0 : RSet::contains(Xapian::docid did) const
74 : : {
75 [ # # ][ # # ]: 0 : return internal.get() && internal->docs.find(did) != internal->docs.end();
[ # # ][ # # ]
[ # # ]
[ # # # # ]
76 : : }
77 : :
78 : : string
79 : 8 : RSet::get_description() const
80 : : {
81 [ + - ]: 8 : string desc = "RSet(";
82 [ + + ][ - + ]: 8 : if (!internal.get() || internal->docs.empty()) {
[ + + ]
83 [ + - ]: 6 : desc += ')';
84 : : } else {
85 [ + + ]: 5 : for (auto&& did : internal->docs) {
86 [ + - ][ + - ]: 3 : desc += str(did);
87 [ + - ]: 3 : desc += ',';
88 : : }
89 [ + - ]: 2 : desc.back() = ')';
90 : : }
91 : 8 : return desc;
92 : : }
93 : :
94 : : }
|