matcher/branchpostlist.h

Go to the documentation of this file.
00001 /* branchpostlist.h: virtual base class for branched types of postlist
00002  *
00003  * Copyright 1999,2000,2001 BrightStation PLC
00004  * Copyright 2002 Ananova Ltd
00005  * Copyright 2003,2004,2007 Olly Betts
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License as
00009  * published by the Free Software Foundation; either version 2 of the
00010  * License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00020  * USA
00021  */
00022 
00023 #ifndef OM_HGUARD_BRANCHPOSTLIST_H
00024 #define OM_HGUARD_BRANCHPOSTLIST_H
00025 
00026 #include "multimatch.h"
00027 #include "postlist.h"
00028 
00036 class BranchPostList : public PostList {
00037     private:
00038         // Prevent copying
00039         BranchPostList(const BranchPostList &);
00040         BranchPostList & operator=(const BranchPostList &);
00041 
00042     protected:
00044         PostList *l;
00045 
00047         PostList *r;
00048 
00054         MultiMatch *matcher;
00055 
00059         void handle_prune(PostList *&kid, PostList *ret) {
00060             if (ret) {
00061                 delete kid;
00062                 kid = ret;
00063 
00064                 // now tell matcher that maximum weights need recalculation.
00065                 matcher->recalc_maxweight();
00066             }
00067         }
00068 
00069     public:
00070         BranchPostList(PostList *l_, PostList *r_, MultiMatch *matcher_)
00071                 : l(l_), r(r_), matcher(matcher_) {}
00072 
00073         virtual ~BranchPostList();
00074 };
00075 
00076 // Helper functions - call next/skip_to on a postlist and handle any
00077 // resulting prune
00078 // 
00079 // Returns true iff a prune was handled, so the caller can recalculate
00080 // weights etc if necessary
00081 inline bool
00082 next_handling_prune(PostList * & pl, Xapian::weight w_min,
00083                     MultiMatch *matcher)
00084 {
00085     PostList *p = pl->next(w_min);
00086     if (!p) return false;
00087     delete pl;
00088     pl = p;
00089     // now tell matcher that maximum weights need recalculation.
00090     if (matcher) matcher->recalc_maxweight();
00091     return true;
00092 }
00093 
00094 inline bool
00095 skip_to_handling_prune(PostList * & pl, Xapian::docid did, Xapian::weight w_min,
00096                        MultiMatch *matcher)
00097 {
00098     PostList *p = pl->skip_to(did, w_min);
00099     if (!p) return false;
00100     delete pl;
00101     pl = p;
00102     // now tell matcher that maximum weights need recalculation.
00103     if (matcher) matcher->recalc_maxweight();
00104     return true;
00105 }
00106 
00107 inline bool
00108 check_handling_prune(PostList * & pl, Xapian::docid did, Xapian::weight w_min,
00109                      MultiMatch *matcher, bool & valid)
00110 {
00111     PostList *p = pl->check(did, w_min, valid);
00112     if (!p) return false;
00113     delete pl;
00114     pl = p;
00115     // now tell matcher that maximum weights need recalculation.
00116     if (matcher) matcher->recalc_maxweight();
00117     return true;
00118 }
00119 
00120 #endif /* OM_HGUARD_BRANCHPOSTLIST_H */

Documentation for Xapian (version 1.0.20).
Generated on 28 Apr 2010 by Doxygen 1.5.2.