Use C++11 member initialisation more
[xapian.git] / xapian-core / matcher / postlisttree.h
blobdc6f9c78595f798eed2c817226afcd4850876bc3
1 /** @file postlisttree.h
2 * @brief Class for managing a tree of PostList objects
3 */
4 /* Copyright 2017 Olly Betts
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (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_POSTLISTTREE_H
22 #define XAPIAN_INCLUDED_POSTLISTTREE_H
24 #include "api/postlist.h"
26 class PostListTree {
27 PostList* pl = NULL;
29 bool use_cached_max_weight = false;
31 double max_weight;
33 public:
34 PostListTree() {}
36 ~PostListTree() {
37 delete pl;
40 void set_postlist(PostList* pl_) {
41 pl = pl_;
44 double recalc_maxweight() {
45 if (!use_cached_max_weight) {
46 use_cached_max_weight = true;
47 max_weight = pl->recalc_maxweight();
49 return max_weight;
52 void force_recalc() {
53 use_cached_max_weight = false;
56 Xapian::doccount get_termfreq_min() const {
57 return pl->get_termfreq_min();
60 Xapian::doccount get_termfreq_max() const {
61 return pl->get_termfreq_max();
64 Xapian::doccount get_termfreq_est() const {
65 return pl->get_termfreq_est();
68 Xapian::docid get_docid() const {
69 return pl->get_docid();
72 double get_weight() const {
73 return pl->get_weight();
76 const std::string* get_sort_key() const {
77 return pl->get_sort_key();
80 const std::string* get_collapse_key() const {
81 return pl->get_collapse_key();
84 /// Return false if we're done.
85 bool next(double w_min) {
86 if (rare(!use_cached_max_weight) && w_min > 0.0) {
87 if (recalc_maxweight() < w_min) {
88 // We can't now achieve w_min so we're done.
89 return false;
93 PostList* result = pl->next(w_min);
94 if (rare(result)) {
95 delete pl;
96 pl = result;
98 if (rare(pl->at_end()))
99 return false;
101 if (rare(result) && w_min > 0.0) {
102 use_cached_max_weight = false;
103 if (recalc_maxweight() < w_min) {
104 // We can't now achieve w_min so we're done.
105 return false;
109 return true;
112 Xapian::termcount count_matching_subqs() const {
113 return pl->count_matching_subqs();
116 std::string get_description() const {
117 return pl->get_description();
121 #endif // XAPIAN_INCLUDED_POSTLISTTREE_H